├── .gitattributes
├── .gitignore
├── README.md
├── ReCapProject.Business
├── Abstract
│ ├── IAuthService.cs
│ ├── IBrandService.cs
│ ├── ICarImageService.cs
│ ├── ICarService.cs
│ ├── IColorService.cs
│ ├── ICustomerService.cs
│ ├── IFakeCardService.cs
│ ├── IRentalService.cs
│ └── IUserService.cs
├── BusinessAspects
│ └── Autofac
│ │ └── SecuredOperation.cs
├── Concrete
│ ├── AuthManager.cs
│ ├── BrandManager.cs
│ ├── CarImageManager.cs
│ ├── CarManager.cs
│ ├── ColorManager.cs
│ ├── CustomerManager.cs
│ ├── FakeCardManager.cs
│ ├── RentalManager.cs
│ └── UserManager.cs
├── Constants
│ └── Messages.cs
├── DependencyResolvers
│ └── Autofac
│ │ └── AutofacBusinessModule.cs
├── ReCapProject.Business.csproj
└── ValidationRules
│ └── FluentValidation
│ ├── BrandValidator.cs
│ ├── CarImageValidator.cs
│ ├── CarValidator.cs
│ ├── ColorValidator.cs
│ ├── CustomerValidator.cs
│ ├── RentalValidator.cs
│ └── UserValidator.cs
├── ReCapProject.Console
├── Program.cs
└── ReCapProject.Console.csproj
├── ReCapProject.Core
├── Aspects
│ ├── Caching
│ │ ├── CacheAspect.cs
│ │ └── CacheRemoveAspect.cs
│ ├── Performance
│ │ └── PerformanceAspect.cs
│ ├── Transaction
│ │ └── TransactionScopeAspect.cs
│ └── Validation
│ │ └── ValidationAspect.cs
├── CrossCuttingConcerns
│ ├── Caching
│ │ ├── ICacheManager.cs
│ │ └── Microsoft
│ │ │ └── MemoryCacheManager.cs
│ └── Validation
│ │ └── ValidationTool.cs
├── DataAccess
│ ├── EntityFramework
│ │ └── EfEntityRepositoryBase.cs
│ └── IEntityRepository.cs
├── DependencyResolvers
│ └── CoreModule.cs
├── Entities
│ ├── Concrete
│ │ ├── OperationClaim.cs
│ │ ├── User.cs
│ │ └── UserOperationClaim.cs
│ ├── IDto.cs
│ └── IEntity.cs
├── Extensions
│ ├── ClaimExtensions.cs
│ ├── ClaimsPrincipalExtensions.cs
│ ├── ErrorDetails.cs
│ ├── ExceptionMiddleware.cs
│ ├── ExceptionMiddlewareExtensions.cs
│ └── ServiceCollectionExtensions.cs
├── ReCapProject.Core.csproj
└── Utilities
│ ├── Business
│ └── BusinessRules.cs
│ ├── FileHelper
│ └── FileHelper.cs
│ ├── IoC
│ ├── ICoreModule.cs
│ └── ServiceTool.cs
│ ├── Results
│ ├── DataResult.cs
│ ├── ErrorDataResult.cs
│ ├── ErrorResult.cs
│ ├── IDataResult.cs
│ ├── IResult.cs
│ ├── Result.cs
│ ├── SuccessDataResult.cs
│ └── SuccessResult.cs
│ ├── Security
│ ├── Encryption
│ │ ├── SecurityKeyHelper.cs
│ │ └── SigningCredentialsHelper.cs
│ ├── Hashing
│ │ └── HashingHelper.cs
│ └── JWT
│ │ ├── AccessToken.cs
│ │ ├── ITokenHelper.cs
│ │ ├── JwtHelper.cs
│ │ └── TokenOptions.cs
│ └── İnterceptors
│ ├── AspectInterceptorSelector.cs
│ ├── MethodInterception.cs
│ └── MethodInterceptionBaseAttribute.cs
├── ReCapProject.DataAccess
├── Abstract
│ ├── IBrandDal.cs
│ ├── ICarDal.cs
│ ├── ICarImageDal.cs
│ ├── IColorDal.cs
│ ├── ICustomerDal.cs
│ ├── IFakeCardDal.cs
│ ├── IRentalDal.cs
│ └── IUserDal.cs
├── Concrete
│ ├── EntityFramework
│ │ ├── EfBrandDal.cs
│ │ ├── EfCarDal.cs
│ │ ├── EfCarImageDal.cs
│ │ ├── EfColorDal.cs
│ │ ├── EfCustomerDal.cs
│ │ ├── EfFakeCardDal.cs
│ │ ├── EfRentalDal.cs
│ │ ├── EfUserDal.cs
│ │ └── NorthwindContext.cs
│ └── InMemory
│ │ └── IMCarDal.cs
└── ReCapProject.DataAccess.csproj
├── ReCapProject.Entities
├── Concrete
│ ├── Brand.cs
│ ├── Car.cs
│ ├── CarImage.cs
│ ├── Color.cs
│ ├── Customer.cs
│ ├── FakeCard.cs
│ └── Rental.cs
├── DTOs
│ ├── CarDetailDto.cs
│ ├── CarImageDto.cs
│ ├── CustomerDetailDto.cs
│ ├── RentalDetailDto.cs
│ ├── UserForLoginDto.cs
│ └── UserForRegisterDto.cs
└── ReCapProject.Entities.csproj
├── ReCapProject.sln
└── WebAPI
├── Controllers
├── AuthController.cs
├── BrandsController.cs
├── CarImagesController.cs
├── CarsController.cs
├── ColorsController.cs
├── CustomersController.cs
├── FakeCardsController.cs
├── RentalsController.cs
├── UsersController.cs
└── WeatherForecastController.cs
├── Program.cs
├── Properties
└── launchSettings.json
├── Startup.cs
├── WeatherForecast.cs
├── WebAPI.csproj
├── appsettings.Development.json
├── appsettings.json
└── wwwroot
└── Images
├── 07f8041a153345ecac7dcb88090f6857.JPG
├── 083bdc5ad5b94464b21bcb7a20323658-3-8-2021.JPG
├── 3dd65d62c8e142fa95eaa4601e4128ad.JPG
├── cc53d921a7e04be6915308bff157acc0.JPG
├── d3e1d3b0a7cc4afaa43401a361316225-2-28-2021.JPG
├── d4f7916a8b444381a531f2f5ecbda9ae.JPG
└── default.PNG
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | [Aa][Rr][Mm]/
24 | [Aa][Rr][Mm]64/
25 | bld/
26 | [Bb]in/
27 | [Oo]bj/
28 | [Ll]og/
29 |
30 | # Visual Studio 2015/2017 cache/options directory
31 | .vs/
32 | # Uncomment if you have tasks that create the project's static files in wwwroot
33 | #wwwroot/
34 |
35 | # Visual Studio 2017 auto generated files
36 | Generated\ Files/
37 |
38 | # MSTest test Results
39 | [Tt]est[Rr]esult*/
40 | [Bb]uild[Ll]og.*
41 |
42 | # NUNIT
43 | *.VisualState.xml
44 | TestResult.xml
45 |
46 | # Build Results of an ATL Project
47 | [Dd]ebugPS/
48 | [Rr]eleasePS/
49 | dlldata.c
50 |
51 | # Benchmark Results
52 | BenchmarkDotNet.Artifacts/
53 |
54 | # .NET Core
55 | project.lock.json
56 | project.fragment.lock.json
57 | artifacts/
58 |
59 | # StyleCop
60 | StyleCopReport.xml
61 |
62 | # Files built by Visual Studio
63 | *_i.c
64 | *_p.c
65 | *_h.h
66 | *.ilk
67 | *.meta
68 | *.obj
69 | *.iobj
70 | *.pch
71 | *.pdb
72 | *.ipdb
73 | *.pgc
74 | *.pgd
75 | *.rsp
76 | *.sbr
77 | *.tlb
78 | *.tli
79 | *.tlh
80 | *.tmp
81 | *.tmp_proj
82 | *_wpftmp.csproj
83 | *.log
84 | *.vspscc
85 | *.vssscc
86 | .builds
87 | *.pidb
88 | *.svclog
89 | *.scc
90 |
91 | # Chutzpah Test files
92 | _Chutzpah*
93 |
94 | # Visual C++ cache files
95 | ipch/
96 | *.aps
97 | *.ncb
98 | *.opendb
99 | *.opensdf
100 | *.sdf
101 | *.cachefile
102 | *.VC.db
103 | *.VC.VC.opendb
104 |
105 | # Visual Studio profiler
106 | *.psess
107 | *.vsp
108 | *.vspx
109 | *.sap
110 |
111 | # Visual Studio Trace Files
112 | *.e2e
113 |
114 | # TFS 2012 Local Workspace
115 | $tf/
116 |
117 | # Guidance Automation Toolkit
118 | *.gpState
119 |
120 | # ReSharper is a .NET coding add-in
121 | _ReSharper*/
122 | *.[Rr]e[Ss]harper
123 | *.DotSettings.user
124 |
125 | # JustCode is a .NET coding add-in
126 | .JustCode
127 |
128 | # TeamCity is a build add-in
129 | _TeamCity*
130 |
131 | # DotCover is a Code Coverage Tool
132 | *.dotCover
133 |
134 | # AxoCover is a Code Coverage Tool
135 | .axoCover/*
136 | !.axoCover/settings.json
137 |
138 | # Visual Studio code coverage results
139 | *.coverage
140 | *.coveragexml
141 |
142 | # NCrunch
143 | _NCrunch_*
144 | .*crunch*.local.xml
145 | nCrunchTemp_*
146 |
147 | # MightyMoose
148 | *.mm.*
149 | AutoTest.Net/
150 |
151 | # Web workbench (sass)
152 | .sass-cache/
153 |
154 | # Installshield output folder
155 | [Ee]xpress/
156 |
157 | # DocProject is a documentation generator add-in
158 | DocProject/buildhelp/
159 | DocProject/Help/*.HxT
160 | DocProject/Help/*.HxC
161 | DocProject/Help/*.hhc
162 | DocProject/Help/*.hhk
163 | DocProject/Help/*.hhp
164 | DocProject/Help/Html2
165 | DocProject/Help/html
166 |
167 | # Click-Once directory
168 | publish/
169 |
170 | # Publish Web Output
171 | *.[Pp]ublish.xml
172 | *.azurePubxml
173 | # Note: Comment the next line if you want to checkin your web deploy settings,
174 | # but database connection strings (with potential passwords) will be unencrypted
175 | *.pubxml
176 | *.publishproj
177 |
178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
179 | # checkin your Azure Web App publish settings, but sensitive information contained
180 | # in these scripts will be unencrypted
181 | PublishScripts/
182 |
183 | # NuGet Packages
184 | *.nupkg
185 | # The packages folder can be ignored because of Package Restore
186 | **/[Pp]ackages/*
187 | # except build/, which is used as an MSBuild target.
188 | !**/[Pp]ackages/build/
189 | # Uncomment if necessary however generally it will be regenerated when needed
190 | #!**/[Pp]ackages/repositories.config
191 | # NuGet v3's project.json files produces more ignorable files
192 | *.nuget.props
193 | *.nuget.targets
194 |
195 | # Microsoft Azure Build Output
196 | csx/
197 | *.build.csdef
198 |
199 | # Microsoft Azure Emulator
200 | ecf/
201 | rcf/
202 |
203 | # Windows Store app package directories and files
204 | AppPackages/
205 | BundleArtifacts/
206 | Package.StoreAssociation.xml
207 | _pkginfo.txt
208 | *.appx
209 |
210 | # Visual Studio cache files
211 | # files ending in .cache can be ignored
212 | *.[Cc]ache
213 | # but keep track of directories ending in .cache
214 | !?*.[Cc]ache/
215 |
216 | # Others
217 | ClientBin/
218 | ~$*
219 | *~
220 | *.dbmdl
221 | *.dbproj.schemaview
222 | *.jfm
223 | *.pfx
224 | *.publishsettings
225 | orleans.codegen.cs
226 |
227 | # Including strong name files can present a security risk
228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
229 | #*.snk
230 |
231 | # Since there are multiple workflows, uncomment next line to ignore bower_components
232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
233 | #bower_components/
234 |
235 | # RIA/Silverlight projects
236 | Generated_Code/
237 |
238 | # Backup & report files from converting an old project file
239 | # to a newer Visual Studio version. Backup files are not needed,
240 | # because we have git ;-)
241 | _UpgradeReport_Files/
242 | Backup*/
243 | UpgradeLog*.XML
244 | UpgradeLog*.htm
245 | ServiceFabricBackup/
246 | *.rptproj.bak
247 |
248 | # SQL Server files
249 | *.mdf
250 | *.ldf
251 | *.ndf
252 |
253 | # Business Intelligence projects
254 | *.rdl.data
255 | *.bim.layout
256 | *.bim_*.settings
257 | *.rptproj.rsuser
258 | *- Backup*.rdl
259 |
260 | # Microsoft Fakes
261 | FakesAssemblies/
262 |
263 | # GhostDoc plugin setting file
264 | *.GhostDoc.xml
265 |
266 | # Node.js Tools for Visual Studio
267 | .ntvs_analysis.dat
268 | node_modules/
269 |
270 | # Visual Studio 6 build log
271 | *.plg
272 |
273 | # Visual Studio 6 workspace options file
274 | *.opt
275 |
276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
277 | *.vbw
278 |
279 | # Visual Studio LightSwitch build output
280 | **/*.HTMLClient/GeneratedArtifacts
281 | **/*.DesktopClient/GeneratedArtifacts
282 | **/*.DesktopClient/ModelManifest.xml
283 | **/*.Server/GeneratedArtifacts
284 | **/*.Server/ModelManifest.xml
285 | _Pvt_Extensions
286 |
287 | # Paket dependency manager
288 | .paket/paket.exe
289 | paket-files/
290 |
291 | # FAKE - F# Make
292 | .fake/
293 |
294 | # JetBrains Rider
295 | .idea/
296 | *.sln.iml
297 |
298 | # CodeRush personal settings
299 | .cr/personal
300 |
301 | # Python Tools for Visual Studio (PTVS)
302 | __pycache__/
303 | *.pyc
304 |
305 | # Cake - Uncomment if you are using it
306 | # tools/**
307 | # !tools/packages.config
308 |
309 | # Tabs Studio
310 | *.tss
311 |
312 | # Telerik's JustMock configuration file
313 | *.jmconfig
314 |
315 | # BizTalk build output
316 | *.btp.cs
317 | *.btm.cs
318 | *.odx.cs
319 | *.xsd.cs
320 |
321 | # OpenCover UI analysis results
322 | OpenCover/
323 |
324 | # Azure Stream Analytics local run output
325 | ASALocalRun/
326 |
327 | # MSBuild Binary and Structured Log
328 | *.binlog
329 |
330 | # NVidia Nsight GPU debugger configuration file
331 | *.nvuser
332 |
333 | # MFractors (Xamarin productivity tool) working folder
334 | .mfractor/
335 |
336 | # Local History for Visual Studio
337 | .localhistory/
338 |
339 | # BeatPulse healthcheck temp database
340 | healthchecksdb
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ReCapProject (Rent A Car Back-end)
2 |
3 |
4 | ## Introduction
5 | While developing this project,
6 | I learned new techniques and patterns and I developed myself very well. If you need detailed information, you can contact me.
7 |
8 | ## Technologies Used
9 | - .NET
10 | - ASP.NET for Restful api
11 | - EntityFramework Core
12 | - Autofac
13 | - FluentValidation
14 | - MsSql
15 |
16 | ## Techniques
17 | - Layered Architecture Design Pattern
18 | - OOP
19 | - AOP
20 | - JWT
21 | - Autofac dependency resolver
22 | - IOC
23 |
24 | ## FluentValidation
25 | If you want to check content of entity when add, update etc. operations you can create validation for related entity.
26 |
27 | ## Aspects
28 | - ValidationAspect
29 | - CacheAspect
30 | - CacheRemoveAspect
31 | - PerformanceAspect
32 | - SecuredOperationAspect
33 | - TransactionAsepct
34 | You can understand better if you examine the classes in the concrete folder in the business layer.
35 |
36 | ## Database objects
37 | - Brand
38 | - Car
39 | - CarImage
40 | - Color
41 | - Customer
42 | - FakeCard
43 | - Rental
44 | - OperationClaim(In the core layer)
45 | - UserOperationClaim(In the core layer)
46 | - User(In the core layer)
47 |
48 | ## Nuget Packages and Their Versions
49 | - Autofac - Version = v6.1.0
50 | - Autofac.Extensions.DependencyInjection - Version = v7.1.0
51 | - Autofac.Extras.DynamicProxy - Version = v6.0.0
52 | - FluentValidation - Version = v9.5.1
53 | - Microsoft.AspNetCore.Authentication.JwtBearer - Version = v3.1.12
54 | - Microsoft.AspNetCore.Http - Version = v2.2.2
55 | - Microsoft.AspNetCore.Http.Abstractions - Version = v2.2.0
56 | - Microsoft.AspNetCore.Http.Features - Version = v5.0.3
57 | - Microsoft.EntityFrameworkCore.SqlServer - Version = v3.1.12
58 | - Microsoft.IdentityModel.Tokens - Version = v6.8.0
59 | - Newtonsoft.Json - Version = v13.0.1
60 | - System.IdentityModel.Tokens.Jwt - Version = v6.8.0
61 |
62 |
63 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Abstract/IAuthService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using ReCapProject.Core.Entities.Concrete;
5 | using ReCapProject.Core.Utilities.Results;
6 | using ReCapProject.Core.Utilities.Security.JWT;
7 | using ReCapProject.Entities.DTOs;
8 |
9 | namespace ReCapProject.Business.Abstract
10 | {
11 | public interface IAuthService
12 | {
13 | IDataResult Register(UserForRegisterDto userForRegisterDto, string password);
14 | IDataResult Update(UserForRegisterDto userForRegisterDto, string password);
15 | IDataResult Login(UserForLoginDto userForLoginDto);
16 | IResult UserExists(string email);
17 | IDataResult CreateAccessToken(User user);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Abstract/IBrandService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using ReCapProject.Core.Utilities.Results;
5 | using ReCapProject.Entities.Concrete;
6 |
7 | namespace ReCapProject.Business.Abstract
8 | {
9 | public interface IBrandService
10 | {
11 | IDataResult> GetAll();
12 | IDataResult> GetBrandsByBrandId(int brandId);
13 | IDataResult> GetBrandsByName(string brandName);
14 | IResult Add(Brand brand);
15 | IResult Update(Brand brand);
16 | IResult Delete(Brand brand);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Abstract/ICarImageService.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Microsoft.AspNetCore.Http;
3 | using ReCapProject.Core.Utilities.Results;
4 | using ReCapProject.Entities.Concrete;
5 |
6 | namespace ReCapProject.Business.Abstract
7 | {
8 | public interface ICarImageService
9 | {
10 | IResult Add(CarImage carImage, IFormFile file);
11 | IResult Delete(CarImage carImage);
12 | IResult Update(CarImage carImage, IFormFile file);
13 | IDataResult> GetAll();
14 | IDataResult> GetAllByCarId(int carId);
15 | IDataResult GetById(int id);
16 |
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Abstract/ICarService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using ReCapProject.Core.Utilities.Results;
5 | using ReCapProject.Entities.Concrete;
6 | using ReCapProject.Entities.DTOs;
7 |
8 | namespace ReCapProject.Business.Abstract
9 | {
10 | public interface ICarService
11 | {
12 | IDataResult> GetAll();
13 | IDataResult> GetCarsByCarId(int carId);
14 | IDataResult> GetCarsByBrandId(int brandId);
15 | IDataResult> GetCarsByColorId(int colorId);
16 | IDataResult> GetCarDetailsByCarsId(int carId);
17 | IDataResult> GetCarsDetailsByBrandId(int brandId);
18 | IDataResult> GetCarsDetailsByColorId(int colorId);
19 | IDataResult> GetCarsDetailsByBrandIdAndColorId(int brandId, int colorId);
20 | IDataResult> GetCarDetails();
21 | IResult Add(Car car);
22 | IResult Update(Car car);
23 | IResult Delete(int carId);
24 | IResult TransactionalOperation(Car car);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Abstract/IColorService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using ReCapProject.Core.Utilities.Results;
5 | using ReCapProject.Entities.Concrete;
6 |
7 | namespace ReCapProject.Business.Abstract
8 | {
9 | public interface IColorService
10 | {
11 | IDataResult> GetAll();
12 | IDataResult> GetColorsByColorId(int colorId);
13 | IResult Add(Color color);
14 | IResult Update(Color color);
15 | IResult Delete(Color color);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Abstract/ICustomerService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using ReCapProject.Core.Utilities.Results;
5 | using ReCapProject.Entities.Concrete;
6 | using ReCapProject.Entities.DTOs;
7 |
8 | namespace ReCapProject.Business.Abstract
9 | {
10 | public interface ICustomerService
11 | {
12 | IDataResult> GetAll();
13 | IDataResult> GetCustomerDetails();
14 | IDataResult> GetCustomersByCustomerId(int customerId);
15 | IResult Add(Customer customer);
16 | IResult Update(Customer customer);
17 | IResult Delete(Customer customer);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Abstract/IFakeCardService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using ReCapProject.Core.Utilities.Results;
5 | using ReCapProject.Entities.Concrete;
6 |
7 | namespace ReCapProject.Business.Abstract
8 | {
9 | public interface IFakeCardService
10 | {
11 | IResult Add(FakeCard fakeCard);
12 | IResult Update(FakeCard fakeCard);
13 | IResult Delete(FakeCard fakeCard);
14 | IDataResult> GetAll();
15 | IDataResult GetById(int id);
16 | IDataResult> GetByCardNumber(string cardNumber);
17 | IResult IsCardExist(FakeCard fakeCard);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Abstract/IRentalService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using ReCapProject.Core.Utilities.Results;
5 | using ReCapProject.Entities.Concrete;
6 | using ReCapProject.Entities.DTOs;
7 |
8 | namespace ReCapProject.Business.Abstract
9 | {
10 | public interface IRentalService
11 | {
12 | IDataResult> GetAll();
13 | IDataResult> GetRentalsByRentalId(int rentalId);
14 | IDataResult> GetRentalDetails();
15 | IDataResult> GetAllByCarId(int carId);
16 | IDataResult> GetAllByCustomerId(int customerId);
17 | IResult Add(Rental rental);
18 | IResult Update(Rental rental);
19 | IResult Delete(Rental rental);
20 | IResult IsDelivered(Rental rental);
21 | IResult IsRentable(Rental rental);
22 | Boolean Rentable(Rental rental);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Abstract/IUserService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using ReCapProject.Core.Entities.Concrete;
5 | using ReCapProject.Core.Utilities.Results;
6 | using ReCapProject.Entities.Concrete;
7 |
8 | namespace ReCapProject.Business.Abstract
9 | {
10 | public interface IUserService
11 | {
12 | IDataResult> GetAll();
13 | IDataResult> GetUsersByUserId(int userId);
14 | IDataResult> GetByEmail(string email);
15 | IDataResult> GetByName(string name);
16 | IResult Add(User user);
17 | IResult Update(User user);
18 | IResult Delete(User user);
19 | List GetClaims(User user);
20 | User GetByMail(string email);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/ReCapProject.Business/BusinessAspects/Autofac/SecuredOperation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Castle.DynamicProxy;
5 | using Microsoft.AspNetCore.Http;
6 | using Microsoft.Extensions.DependencyInjection;
7 | using ReCapProject.Business.Constants;
8 | using ReCapProject.Core.Extensions;
9 | using ReCapProject.Core.Utilities.İnterceptors;
10 | using ReCapProject.Core.Utilities.IoC;
11 |
12 | namespace ReCapProject.Business.BusinessAspects.Autofac
13 | {
14 | public class SecuredOperation : MethodInterception
15 | {
16 | private string[] _roles;
17 | private IHttpContextAccessor _httpContextAccessor;
18 |
19 | public SecuredOperation(string roles)
20 | {
21 | _roles = roles.Split(',');
22 | _httpContextAccessor = ServiceTool.ServiceProvider.GetService();
23 |
24 | }
25 |
26 | protected override void OnBefore(IInvocation invocation)
27 | {
28 | var roleClaims = _httpContextAccessor.HttpContext.User.ClaimRoles();
29 | foreach (var role in _roles)
30 | {
31 | if (roleClaims.Contains(role))
32 | {
33 | return;
34 | }
35 | }
36 | throw new Exception(Messages.AuthorizationDenied);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Concrete/AuthManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using ReCapProject.Business.Abstract;
5 | using ReCapProject.Business.Constants;
6 | using ReCapProject.Core.Entities.Concrete;
7 | using ReCapProject.Core.Utilities.Results;
8 | using ReCapProject.Core.Utilities.Security.Hashing;
9 | using ReCapProject.Core.Utilities.Security.JWT;
10 | using ReCapProject.Entities.DTOs;
11 |
12 | namespace ReCapProject.Business.Concrete
13 | {
14 | public class AuthManager : IAuthService
15 | {
16 | private IUserService _userService;
17 | private ITokenHelper _tokenHelper;
18 |
19 | public AuthManager(IUserService userService, ITokenHelper tokenHelper)
20 | {
21 | _userService = userService;
22 | _tokenHelper = tokenHelper;
23 | }
24 |
25 | public IDataResult Register(UserForRegisterDto userForRegisterDto, string password)
26 | {
27 | byte[] passwordHash, passwordSalt;
28 | HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt);
29 | var user = new User
30 | {
31 | Email = userForRegisterDto.Email,
32 | FirstName = userForRegisterDto.FirstName,
33 | LastName = userForRegisterDto.LastName,
34 | PasswordHash = passwordHash,
35 | PasswordSalt = passwordSalt,
36 | Status = true
37 | };
38 | _userService.Add(user);
39 | return new SuccessDataResult(user, Messages.UserRegistered);
40 | }
41 |
42 | public IDataResult Update(UserForRegisterDto userForRegisterDto, string password)
43 | {
44 | byte[] passwordHash, passwordSalt;
45 | HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt);
46 | var user = new User
47 | {
48 | UserId = userForRegisterDto.Id,
49 | FirstName = userForRegisterDto.FirstName,
50 | LastName = userForRegisterDto.LastName,
51 | Email = userForRegisterDto.Email,
52 | PasswordSalt = passwordSalt,
53 | PasswordHash = passwordHash,
54 | Status = true
55 | };
56 | _userService.Update(user);
57 | return new SuccessDataResult(user, Messages.Updated);
58 | }
59 |
60 | public IDataResult Login(UserForLoginDto userForLoginDto)
61 | {
62 | var userToCheck = _userService.GetByMail(userForLoginDto.Email);
63 | if (userToCheck == null)
64 | {
65 | return new ErrorDataResult(Messages.UserNotFound);
66 | }
67 |
68 | if (!HashingHelper.VerifyPasswordHash(userForLoginDto.Password, userToCheck.PasswordHash, userToCheck.PasswordSalt))
69 | {
70 | return new ErrorDataResult(Messages.PasswordError);
71 | }
72 |
73 | return new SuccessDataResult(userToCheck, Messages.SuccessfulLogin);
74 | }
75 |
76 | public IResult UserExists(string email)
77 | {
78 | if (_userService.GetByMail(email) != null)
79 | {
80 | return new ErrorResult(Messages.UserAlreadyExists);
81 | }
82 | return new SuccessResult();
83 | }
84 |
85 | public IDataResult CreateAccessToken(User user)
86 | {
87 | var claims = _userService.GetClaims(user);
88 | var accessToken = _tokenHelper.CreateToken(user, claims);
89 | return new SuccessDataResult(accessToken, Messages.AccessTokenCreated);
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Concrete/BrandManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using ReCapProject.Business.Abstract;
5 | using ReCapProject.Business.Constants;
6 | using ReCapProject.Business.ValidationRules.FluentValidation;
7 | using ReCapProject.Core.Aspects.Validation;
8 | using ReCapProject.Core.Utilities.Results;
9 | using ReCapProject.DataAccess.Abstract;
10 | using ReCapProject.Entities.Concrete;
11 |
12 | namespace ReCapProject.Business.Concrete
13 | {
14 | public class BrandManager:IBrandService
15 | {
16 | private IBrandDal _brandDal;
17 |
18 | public BrandManager(IBrandDal brandDal)
19 | {
20 | _brandDal = brandDal;
21 | }
22 |
23 | public IDataResult> GetAll()
24 | {
25 | return new SuccessDataResult>(_brandDal.GetAll(),Messages.Listed);
26 | }
27 |
28 | public IDataResult> GetBrandsByBrandId(int brandId)
29 | {
30 | return new SuccessDataResult>(_brandDal.GetAll(b=>b.BrandId==brandId));
31 | }
32 |
33 | public IDataResult> GetBrandsByName(string brandName)
34 | {
35 | return new SuccessDataResult>(_brandDal.GetAll(b=>b.BrandName==brandName),Messages.Successful);
36 | }
37 |
38 | [ValidationAspect(typeof(BrandValidator))]
39 | public IResult Add(Brand brand)
40 | {
41 | _brandDal.Add(brand);
42 | return new SuccessResult(Messages.Added);
43 | }
44 |
45 | public IResult Update(Brand brand)
46 | {
47 | _brandDal.Update(brand);
48 | return new SuccessResult(Messages.Updated);
49 | }
50 |
51 | public IResult Delete(Brand brand)
52 | {
53 | _brandDal.Delete(brand);
54 | return new SuccessResult(Messages.Deleted);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Concrete/CarImageManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using Microsoft.AspNetCore.Http;
6 | using ReCapProject.Business.Abstract;
7 | using ReCapProject.Business.Constants;
8 | using ReCapProject.Business.ValidationRules.FluentValidation;
9 | using ReCapProject.Core.Aspects.Validation;
10 | using ReCapProject.Core.Utilities.Business;
11 | using ReCapProject.Core.Utilities.FileHelper;
12 | using ReCapProject.Core.Utilities.Results;
13 | using ReCapProject.DataAccess.Abstract;
14 | using ReCapProject.Entities.Concrete;
15 |
16 | namespace ReCapProject.Business.Concrete
17 | {
18 | public class CarImageManager : ICarImageService
19 | {
20 | ICarImageDal _carImageDal;
21 |
22 | public CarImageManager(ICarImageDal carImageDal)
23 | {
24 | _carImageDal = carImageDal;
25 | }
26 |
27 | [ValidationAspect(typeof(CarImageValidator))]
28 | public IResult Add(CarImage carImage, IFormFile file)
29 | {
30 | IResult result = BusinessRules.Run(
31 | CheckIfImageLimitExpired(carImage.CarId),
32 | CheckIfImageExtensionValid(file)
33 | );
34 |
35 | if (result != null)
36 | {
37 | return result;
38 | }
39 |
40 | carImage.ImagePath = FileHelper.Add(file);
41 | carImage.Date = DateTime.Now;
42 | _carImageDal.Add(carImage);
43 | return new SuccessResult();
44 | }
45 |
46 | public IResult Delete(CarImage carImage)
47 | {
48 | IResult result = BusinessRules.Run(
49 | CheckIfImageExists(carImage.Id)
50 | );
51 | if (result != null)
52 | {
53 | return result;
54 | }
55 | string path = GetById(carImage.Id).Data.ImagePath;
56 | FileHelper.Delete(path);
57 | _carImageDal.Delete(carImage);
58 | return new SuccessResult();
59 | }
60 |
61 | public IDataResult> GetAll()
62 | {
63 | return new SuccessDataResult>(_carImageDal.GetAll());
64 | }
65 |
66 | public IDataResult> GetAllByCarId(int carId)
67 | {
68 | return new SuccessDataResult>(CheckIfCarHaveNoImage(carId));
69 | }
70 |
71 | public IDataResult GetById(int id)
72 | {
73 | return new SuccessDataResult(_carImageDal.Get(c => c.Id == id));
74 | }
75 |
76 | public IResult Update(CarImage carImage, IFormFile file)
77 | {
78 | IResult result = BusinessRules.Run(
79 | CheckIfImageLimitExpired(carImage.CarId),
80 | CheckIfImageExtensionValid(file),
81 | CheckIfImageExists(carImage.Id)
82 | );
83 |
84 | if (result != null)
85 | {
86 | return result;
87 | }
88 |
89 | carImage.Date = DateTime.Now;
90 | string oldPath = GetById(carImage.Id).Data.ImagePath;
91 | FileHelper.Update(file, oldPath);
92 | _carImageDal.Update(carImage);
93 | return new SuccessResult();
94 | }
95 |
96 | private IResult CheckIfImageLimitExpired(int carId)
97 | {
98 | int result = _carImageDal.GetAll(c => c.CarId == carId).Count;
99 | if (result >= 5)
100 | return new ErrorResult(Messages.ImageLimitExpiredForCar);
101 | return new SuccessResult();
102 | }
103 |
104 | private IResult CheckIfImageExtensionValid(IFormFile file)
105 | {
106 | bool isValidFileExtension = Messages.ValidImageFileTypes.Any(t => t == Path.GetExtension(file.FileName).ToUpper());
107 | if (!isValidFileExtension)
108 | return new ErrorResult(Messages.InvalidImageExtension);
109 | return new SuccessResult();
110 | }
111 |
112 | private List CheckIfCarHaveNoImage(int carId)
113 | {
114 | string path = @"\Images\default.png"; /*Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName + @"\Images\default.png");*/
115 | var result = _carImageDal.GetAll(c => c.CarId == carId);
116 | if (!result.Any())
117 | return new List { new CarImage { CarId = carId, ImagePath = path } };
118 | return result;
119 | }
120 |
121 | private IResult CheckIfImageExists(int id)
122 | {
123 | if (_carImageDal.IsExist(id))
124 | return new SuccessResult();
125 | return new ErrorResult(Messages.CarImageMustBeExists);
126 | }
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Concrete/CarManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using ReCapProject.Business.Abstract;
6 | using ReCapProject.Business.BusinessAspects.Autofac;
7 | using ReCapProject.Business.Constants;
8 | using ReCapProject.Business.ValidationRules.FluentValidation;
9 | using ReCapProject.Core.Aspects.Caching;
10 | using ReCapProject.Core.Aspects.Performance;
11 | using ReCapProject.Core.Aspects.Transaction;
12 | using ReCapProject.Core.Aspects.Validation;
13 | using ReCapProject.Core.CrossCuttingConcerns.Validation;
14 | using ReCapProject.Core.Utilities.Business;
15 | using ReCapProject.Core.Utilities.Results;
16 | using ReCapProject.DataAccess.Abstract;
17 | using ReCapProject.Entities.Concrete;
18 | using ReCapProject.Entities.DTOs;
19 |
20 | namespace ReCapProject.Business.Concrete
21 | {
22 | public class CarManager : ICarService
23 | {
24 | private ICarDal _carDal;
25 |
26 | public CarManager(ICarDal carDal)
27 | {
28 | _carDal = carDal;
29 | }
30 |
31 | [CacheAspect]
32 | public IDataResult> GetAll()
33 | {
34 | //if (DateTime.Now.Hour==15)
35 | //{
36 | // return new ErrorDataResult>(Messages.MaintenanceTime);
37 | //}
38 | return new SuccessDataResult>( _carDal.GetAll(),Messages.Listed);
39 | }
40 |
41 | [CacheAspect]
42 | //[PerformanceAspect(5)] Core katmanındaki AspectInterceptorSelector ekledim(Her methodu takip etsın diye)
43 | public IDataResult> GetCarsByCarId(int carId)
44 | {
45 | return new SuccessDataResult>( _carDal.GetAll(c => c.CarId == carId));
46 | }
47 |
48 | public IDataResult> GetCarsByBrandId(int brandId)
49 | {
50 | return new SuccessDataResult>( _carDal.GetAll(c => c.BrandId == brandId));
51 | }
52 |
53 | public IDataResult> GetCarsByColorId(int colorId)
54 | {
55 | return new SuccessDataResult>( _carDal.GetAll(c => c.ColorId == colorId));
56 | }
57 |
58 | public IDataResult> GetCarDetailsByCarsId(int carId)
59 | {
60 | return new SuccessDataResult>(_carDal.GetCarDetails(c=>c.CarId==carId));
61 | }
62 |
63 | public IDataResult> GetCarsDetailsByBrandId(int brandId)
64 | {
65 | return new SuccessDataResult>(_carDal.GetCarDetails(c=>c.BrandId==brandId));
66 | }
67 |
68 | public IDataResult> GetCarsDetailsByColorId(int colorId)
69 | {
70 | return new SuccessDataResult>(_carDal.GetCarDetails(c=>c.ColorId==colorId));
71 | }
72 |
73 | public IDataResult> GetCarsDetailsByBrandIdAndColorId(int brandId, int colorId)
74 | {
75 | return new SuccessDataResult>(_carDal.GetCarDetails(c => c.BrandId == brandId && c.ColorId==colorId));
76 | }
77 |
78 | public IDataResult> GetCarDetails()
79 | {
80 | return new SuccessDataResult>( _carDal.GetCarDetails());
81 | }
82 |
83 | [SecuredOperation("car.add,admin")]
84 | [ValidationAspect(typeof(CarValidator))]
85 | [CacheRemoveAspect("ICarService.Get")]
86 | public IResult Add(Car car)
87 | {
88 | IResult result = BusinessRules.Run(CheckIfProductNameExists(car.Description));
89 | if (result!=null)
90 | {
91 | return result;
92 | }
93 | _carDal.Add(car);
94 | return new SuccessResult(Messages.Added);
95 | }
96 |
97 | [ValidationAspect(typeof(CarValidator))]
98 | [CacheRemoveAspect("ICarService.Get")]
99 | public IResult Update(Car car)
100 | {
101 | _carDal.Update(car);
102 | return new SuccessResult(Messages.Updated);
103 | }
104 |
105 | [CacheRemoveAspect("ICarService.Get")]
106 | public IResult Delete(int carId)
107 | {
108 | foreach (var id in _carDal.GetAll())
109 | {
110 | if (id.CarId == carId)
111 | {
112 | _carDal.Delete(id);
113 | return new SuccessResult(Messages.Deleted);
114 | }
115 | }
116 |
117 | return new ErrorResult("Hata");
118 | }
119 |
120 | [TransactionScopeAspect]
121 | public IResult TransactionalOperation(Car car)
122 | {
123 | _carDal.Update(car);
124 | _carDal.Add(car);
125 | return new SuccessResult(Messages.Updated);
126 | }
127 |
128 | private IResult CheckIfProductNameExists(string firstName)
129 | {
130 | var result = _carDal.GetAll(c => c.Description == firstName).Any();
131 | if (result)
132 | {
133 | return new ErrorResult(Messages.ProductNameAlreadyExists);
134 | }
135 | return new SuccessResult();
136 | }
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Concrete/ColorManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using ReCapProject.Business.Abstract;
5 | using ReCapProject.Business.Constants;
6 | using ReCapProject.Business.ValidationRules.FluentValidation;
7 | using ReCapProject.Core.Aspects.Validation;
8 | using ReCapProject.Core.Utilities.Results;
9 | using ReCapProject.DataAccess.Abstract;
10 | using ReCapProject.Entities.Concrete;
11 |
12 | namespace ReCapProject.Business.Concrete
13 | {
14 | public class ColorManager:IColorService
15 | {
16 | private IColorDal _colorDal;
17 |
18 | public ColorManager(IColorDal colorDal)
19 | {
20 | _colorDal = colorDal;
21 | }
22 |
23 | public IDataResult> GetAll()
24 | {
25 | return new SuccessDataResult>(_colorDal.GetAll(),Messages.Listed);
26 | }
27 |
28 | public IDataResult> GetColorsByColorId(int colorId)
29 | {
30 | return new SuccessDataResult>(_colorDal.GetAll(c=>c.ColorId==colorId));
31 | }
32 |
33 | [ValidationAspect(typeof(ColorValidator))]
34 | public IResult Add(Color color)
35 | {
36 | _colorDal.Add(color);
37 | return new SuccessResult(Messages.Added);
38 | }
39 |
40 | public IResult Update(Color color)
41 | {
42 | _colorDal.Update(color);
43 | return new SuccessResult(Messages.Updated);
44 | }
45 |
46 | public IResult Delete(Color color)
47 | {
48 | _colorDal.Delete(color);
49 | return new SuccessResult(Messages.Deleted);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Concrete/CustomerManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using ReCapProject.Business.Abstract;
5 | using ReCapProject.Business.Constants;
6 | using ReCapProject.Business.ValidationRules.FluentValidation;
7 | using ReCapProject.Core.Aspects.Validation;
8 | using ReCapProject.Core.Utilities.Results;
9 | using ReCapProject.DataAccess.Abstract;
10 | using ReCapProject.Entities.Concrete;
11 | using ReCapProject.Entities.DTOs;
12 |
13 | namespace ReCapProject.Business.Concrete
14 | {
15 | public class CustomerManager:ICustomerService
16 | {
17 | private ICustomerDal _customerDal;
18 |
19 | public CustomerManager(ICustomerDal customerDal)
20 | {
21 | _customerDal = customerDal;
22 | }
23 |
24 | public IDataResult> GetAll()
25 | {
26 | return new SuccessDataResult>(_customerDal.GetAll(),Messages.Listed);
27 | }
28 |
29 | public IDataResult> GetCustomerDetails()
30 | {
31 | return new SuccessDataResult>(_customerDal.GetCustomerDetails());
32 | }
33 |
34 | public IDataResult> GetCustomersByCustomerId(int customerId)
35 | {
36 | return new SuccessDataResult>(_customerDal.GetAll(c=>c.CustomerId==customerId));
37 | }
38 |
39 | [ValidationAspect(typeof(CustomerValidator))]
40 | public IResult Add(Customer customer)
41 | {
42 | _customerDal.Add(customer);
43 | return new SuccessResult(Messages.Added);
44 | }
45 |
46 | public IResult Update(Customer customer)
47 | {
48 | _customerDal.Update(customer);
49 | return new SuccessResult(Messages.Updated);
50 | }
51 |
52 | public IResult Delete(Customer customer)
53 | {
54 | _customerDal.Delete(customer);
55 | return new SuccessResult(Messages.Deleted);
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Concrete/FakeCardManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using ReCapProject.Business.Abstract;
5 | using ReCapProject.Business.Constants;
6 | using ReCapProject.Core.Utilities.Results;
7 | using ReCapProject.DataAccess.Abstract;
8 | using ReCapProject.Entities.Concrete;
9 |
10 | namespace ReCapProject.Business.Concrete
11 | {
12 | public class FakeCardManager:IFakeCardService
13 | {
14 | private IFakeCardDal _fakeCardDal;
15 |
16 | public FakeCardManager(IFakeCardDal fakeCardDal)
17 | {
18 | _fakeCardDal = fakeCardDal;
19 | }
20 |
21 | public IResult Add(FakeCard fakeCard)
22 | {
23 | _fakeCardDal.Add(fakeCard);
24 | return new SuccessResult(Messages.Added);
25 | }
26 |
27 | public IResult Update(FakeCard fakeCard)
28 | {
29 | _fakeCardDal.Update(fakeCard);
30 | return new SuccessResult(Messages.Updated);
31 | }
32 |
33 | public IResult Delete(FakeCard fakeCard)
34 | {
35 | _fakeCardDal.Delete(fakeCard);
36 | return new SuccessResult(Messages.Deleted);
37 | }
38 |
39 | public IDataResult> GetAll()
40 | {
41 | return new SuccessDataResult>(_fakeCardDal.GetAll());
42 | }
43 |
44 | public IDataResult GetById(int id)
45 | {
46 | return new SuccessDataResult(_fakeCardDal.Get(f=>f.Id==id));
47 | }
48 |
49 | public IDataResult> GetByCardNumber(string cardNumber)
50 | {
51 | return new SuccessDataResult>(_fakeCardDal.GetAll(f=>f.CardNumber==cardNumber));
52 | }
53 |
54 | public IResult IsCardExist(FakeCard fakeCard)
55 | {
56 | var result = _fakeCardDal.Get(f =>
57 | f.CardNumber == fakeCard.CardName && f.CardNumber == fakeCard.CardNumber &&
58 | f.CardCvv == fakeCard.CardCvv);
59 |
60 | if (result==null)
61 | {
62 | return new ErrorResult();
63 | }
64 | return new SuccessResult();
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Concrete/RentalManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using ReCapProject.Business.Abstract;
6 | using ReCapProject.Business.Constants;
7 | using ReCapProject.Business.ValidationRules.FluentValidation;
8 | using ReCapProject.Core.Aspects.Validation;
9 | using ReCapProject.Core.CrossCuttingConcerns.Validation;
10 | using ReCapProject.Core.Utilities.Results;
11 | using ReCapProject.DataAccess.Abstract;
12 | using ReCapProject.Entities.Concrete;
13 | using ReCapProject.Entities.DTOs;
14 |
15 | namespace ReCapProject.Business.Concrete
16 | {
17 | public class RentalManager : IRentalService
18 | {
19 | private IRentalDal _rentalDal;
20 |
21 | public RentalManager(IRentalDal rentalDal)
22 | {
23 | _rentalDal = rentalDal;
24 | }
25 |
26 | public IDataResult> GetAll()
27 | {
28 | return new SuccessDataResult>(_rentalDal.GetAll(), Messages.Listed);
29 | }
30 |
31 | public IDataResult> GetRentalsByRentalId(int rentalId)
32 | {
33 | return new SuccessDataResult>(_rentalDal.GetAll(r => r.RentalId == rentalId));
34 | }
35 |
36 | public IDataResult> GetRentalDetails()
37 | {
38 | return new SuccessDataResult>(_rentalDal.GetRentalDetails());
39 | }
40 |
41 | public IDataResult> GetAllByCarId(int carId)
42 | {
43 | return new SuccessDataResult>(_rentalDal.GetAll(r=>r.CarId==carId));
44 | }
45 |
46 | public IDataResult> GetAllByCustomerId(int customerId)
47 | {
48 | return new SuccessDataResult>(_rentalDal.GetAll(r => r.CustomerId == customerId));
49 | }
50 |
51 | [ValidationAspect(typeof(RentalValidator))]
52 | public IResult Add(Rental rental)
53 | {
54 | //İf in kapalı olan bölümünü RentalValidator de yazdım oyüzden burayı kapattım nasıl yazdığımı inceleyin diye silmedim.
55 | //if (/*rental.ReturnDate == null || */rental.RentDate.Date > rental.ReturnDate.Date)
56 | //{
57 | // return new ErrorResult(Messages.CarNotRented);
58 | //}
59 | _rentalDal.Add(rental);
60 | return new SuccessResult(Messages.CarRented);
61 | }
62 |
63 | public IResult Update(Rental rental)
64 | {
65 | _rentalDal.Update(rental);
66 | return new SuccessResult(Messages.Updated);
67 | }
68 |
69 | public IResult Delete(Rental rental)
70 | {
71 | _rentalDal.Delete(rental);
72 | return new SuccessResult(Messages.Deleted);
73 | }
74 |
75 | public IResult IsDelivered(Rental rental)
76 | {
77 | var result = this.GetAllByCarId(rental.CarId).Data.LastOrDefault();
78 | if (result==null || result.ReturnDate !=default)
79 | {
80 | return new SuccessResult();
81 | }
82 | return new ErrorResult();
83 | }
84 |
85 | public IResult IsRentable(Rental rental)
86 | {
87 | var result = this.GetAllByCarId(rental.CarId).Data.LastOrDefault();
88 | if (IsDelivered(rental).Success || (
89 | !(rental.RentDate < result.ReturnDate && rental.RentDate > result.RentDate) &&
90 | !(rental.ReturnDate < result.ReturnDate && rental.ReturnDate > result.RentDate) &&
91 | !(rental.RentDate < result.RentDate && rental.ReturnDate > result.ReturnDate) &&
92 | rental.RentDate >= DateTime.Now))
93 | {
94 | return new SuccessResult();
95 | }
96 | return new ErrorResult();
97 | }
98 |
99 | public bool Rentable(Rental rental)
100 | {
101 | var result = _rentalDal.GetAll(r => r.CarId == rental.CarId);
102 | if (result.Any(r=>r.RentEndDate >= rental.ReturnDate &&
103 | r.RentDate <=rental.RentEndDate))
104 | {
105 | return true;
106 | }
107 |
108 | return false;
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Concrete/UserManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using ReCapProject.Business.Abstract;
5 | using ReCapProject.Business.Constants;
6 | using ReCapProject.Business.ValidationRules.FluentValidation;
7 | using ReCapProject.Core.Aspects.Validation;
8 | using ReCapProject.Core.Entities.Concrete;
9 | using ReCapProject.Core.Utilities.Results;
10 | using ReCapProject.DataAccess.Abstract;
11 | using ReCapProject.Entities.Concrete;
12 |
13 | namespace ReCapProject.Business.Concrete
14 | {
15 | public class UserManager:IUserService
16 | {
17 | private IUserDal _userDal;
18 |
19 | public UserManager(IUserDal userDal)
20 | {
21 | _userDal = userDal;
22 | }
23 |
24 | public IDataResult> GetAll()
25 | {
26 | return new SuccessDataResult>(_userDal.GetAll(),Messages.Listed);
27 | }
28 |
29 | public IDataResult> GetUsersByUserId(int userId)
30 | {
31 | return new SuccessDataResult>(_userDal.GetAll(u=>u.UserId==userId));
32 | }
33 |
34 | public IDataResult> GetByEmail(string email)
35 | {
36 | return new SuccessDataResult>(_userDal.GetAll(u=>u.Email==email));
37 | }
38 |
39 | public IDataResult> GetByName(string name)
40 | {
41 | return new SuccessDataResult>(_userDal.GetAll(u=>u.FirstName==name));
42 | }
43 |
44 | [ValidationAspect(typeof(UserValidator))]
45 | public IResult Add(User user)
46 | {
47 | _userDal.Add(user);
48 | return new SuccessResult(Messages.Added);
49 | }
50 |
51 | public IResult Update(User user)
52 | {
53 | _userDal.Update(user);
54 | return new SuccessResult(Messages.Updated);
55 | }
56 |
57 | public IResult Delete(User user)
58 | {
59 | _userDal.Delete(user);
60 | return new SuccessResult(Messages.Deleted);
61 | }
62 |
63 | public List GetClaims(User user)
64 | {
65 | return _userDal.GetClaims(user);
66 | }
67 |
68 | public User GetByMail(string email)
69 | {
70 | return _userDal.Get(u => u.Email == email);
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/ReCapProject.Business/Constants/Messages.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.Serialization;
2 | using ReCapProject.Core.Entities.Concrete;
3 |
4 | namespace ReCapProject.Business.Constants
5 | {
6 | public static class Messages
7 | {
8 | public static string CarNameAndPriceInvalid = "Araç Modeli en az iki karakter ve Kiralama Ücreti sıfır liradan yüksek olmalıdır.";
9 | public static string Updated = "Güncellendi.";
10 | public static string Added = "Eklendi.";
11 | public static string Deleted = "Silindi.";
12 | public static string Listed = "Listelendi.";
13 | public static string Successful ="Başarılı";
14 | public static string MaintenanceTime = "Site bakımdadır.";
15 | public static string CarNotRented = "Araç kiralanamadı.";
16 | public static string CarRented = "Araç kiralandı.";
17 | public static string ProductNameAlreadyExists = "Aynı isimde ürün bulunmaktadır.";
18 | public static string ImageLimit = "Fotoğraf limiti aşıldı.";
19 | public static string ImageLimitExpiredForCar = "Bir arabaya maximum 5 fotoğraf eklenebilir";
20 | public static string[] ValidImageFileTypes = { ".JPG", ".JPEG", ".PNG", ".TIF", ".TIFF", ".GIF", ".BMP", ".ICO" };
21 | public static string InvalidImageExtension = "Geçersiz dosya uzantısı, fotoğraf için kabul edilen uzantılar" + string.Join(",", ValidImageFileTypes);
22 | public static string CarImageMustBeExists = "Böyle bi resim bulunamadı";
23 | public static string AuthorizationDenied = "Yetkiniz yok.";
24 | public static string UserRegistered = "Kullanıcı başarıyla kaydedildi";
25 | public static string UserNotFound="Kullanıcı bulunamadı";
26 | public static string PasswordError = "Şifre hatalı";
27 | public static string SuccessfulLogin = "Sisteme giriş başarılı";
28 | public static string UserAlreadyExists = "Bu kullanıcı zaten mevcut";
29 | public static string AccessTokenCreated = "Access token başarıyla oluşturuldu";
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/ReCapProject.Business/DependencyResolvers/Autofac/AutofacBusinessModule.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Autofac;
5 | using Autofac.Extras.DynamicProxy;
6 | using Castle.DynamicProxy;
7 | using ReCapProject.Business.Abstract;
8 | using ReCapProject.Business.Concrete;
9 | using ReCapProject.Core.Utilities.İnterceptors;
10 | using ReCapProject.Core.Utilities.Security.JWT;
11 | using ReCapProject.DataAccess.Abstract;
12 | using ReCapProject.DataAccess.Concrete.EntityFramework;
13 |
14 | namespace ReCapProject.Business.DependencyResolvers.Autofac
15 | {
16 | public class AutofacBusinessModule:Module
17 | {
18 | protected override void Load(ContainerBuilder builder)
19 | {
20 | builder.RegisterType().As().SingleInstance();
21 | builder.RegisterType().As().SingleInstance();
22 | builder.RegisterType().As().SingleInstance();
23 | builder.RegisterType().As().SingleInstance();
24 | builder.RegisterType().As().SingleInstance();
25 | builder.RegisterType().As().SingleInstance();
26 | builder.RegisterType().As().SingleInstance();
27 | builder.RegisterType().As().SingleInstance();
28 | builder.RegisterType().As().SingleInstance();
29 | builder.RegisterType().As().SingleInstance();
30 | builder.RegisterType().As().SingleInstance();
31 | builder.RegisterType().As().SingleInstance();
32 | builder.RegisterType().As().SingleInstance();
33 | builder.RegisterType().As().SingleInstance();
34 | builder.RegisterType().As().SingleInstance();
35 | builder.RegisterType().As().SingleInstance();
36 | builder.RegisterType().As().SingleInstance();
37 | builder.RegisterType().As().SingleInstance();
38 |
39 |
40 | var assembly = System.Reflection.Assembly.GetExecutingAssembly();
41 |
42 | builder.RegisterAssemblyTypes(assembly).AsImplementedInterfaces()
43 | .EnableInterfaceInterceptors(new ProxyGenerationOptions()
44 | {
45 | Selector = new AspectInterceptorSelector()
46 | }).SingleInstance();
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/ReCapProject.Business/ReCapProject.Business.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ReCapProject.Business/ValidationRules/FluentValidation/BrandValidator.cs:
--------------------------------------------------------------------------------
1 | using FluentValidation;
2 | using ReCapProject.Entities.Concrete;
3 |
4 | namespace ReCapProject.Business.ValidationRules.FluentValidation
5 | {
6 | public class BrandValidator:AbstractValidator
7 | {
8 | public BrandValidator()
9 | {
10 | RuleFor(b => b.BrandName).NotEmpty();
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ReCapProject.Business/ValidationRules/FluentValidation/CarImageValidator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using FluentValidation;
5 | using ReCapProject.Entities.Concrete;
6 |
7 | namespace ReCapProject.Business.ValidationRules.FluentValidation
8 | {
9 | public class CarImageValidator:AbstractValidator
10 | {
11 | public CarImageValidator()
12 | {
13 | RuleFor(p => p.CarId).NotEmpty();
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ReCapProject.Business/ValidationRules/FluentValidation/CarValidator.cs:
--------------------------------------------------------------------------------
1 | using FluentValidation;
2 | using ReCapProject.Entities.Concrete;
3 |
4 | namespace ReCapProject.Business.ValidationRules.FluentValidation
5 | {
6 | public class CarValidator:AbstractValidator
7 | {
8 | public CarValidator()
9 | {
10 | RuleFor(c => c.ColorId).NotEmpty();
11 | RuleFor(c => c.BrandId).NotEmpty();
12 | RuleFor(c => c.DailyPrice).NotEmpty();
13 | RuleFor(c => c.DailyPrice).GreaterThan(0);
14 | RuleFor(c => c.ModelYear).NotEmpty();
15 | RuleFor(c => c.Description).NotEmpty();
16 | RuleFor(c => c.Description).MinimumLength(2);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/ReCapProject.Business/ValidationRules/FluentValidation/ColorValidator.cs:
--------------------------------------------------------------------------------
1 | using FluentValidation;
2 | using ReCapProject.Entities.Concrete;
3 |
4 | namespace ReCapProject.Business.ValidationRules.FluentValidation
5 | {
6 | public class ColorValidator:AbstractValidator
7 | {
8 | public ColorValidator()
9 | {
10 | RuleFor(c => c.ColorName).NotEmpty();
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ReCapProject.Business/ValidationRules/FluentValidation/CustomerValidator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using FluentValidation;
5 | using ReCapProject.Entities.Concrete;
6 |
7 | namespace ReCapProject.Business.ValidationRules.FluentValidation
8 | {
9 | public class CustomerValidator:AbstractValidator
10 | {
11 | public CustomerValidator()
12 | {
13 | RuleFor(c => c.UserId).NotEmpty();
14 | RuleFor(c => c.CompanyName).NotEmpty();
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/ReCapProject.Business/ValidationRules/FluentValidation/RentalValidator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using FluentValidation;
5 | using ReCapProject.Entities.Concrete;
6 |
7 | namespace ReCapProject.Business.ValidationRules.FluentValidation
8 | {
9 | public class RentalValidator:AbstractValidator
10 | {
11 | public RentalValidator()
12 | {
13 | RuleFor(r => r.CarId).NotEmpty();
14 | RuleFor(r => r.CustomerId).NotEmpty();
15 | RuleFor(r => r.RentDate).NotEmpty();
16 | RuleFor(r => r.RentDate).Must(RentalDateCannotBeLessThanTodayDate).WithMessage("Verilen tarih bugünün tarihinden küçük olmamalıdır!");
17 | RuleFor(r => r.ReturnDate).NotEmpty();
18 | //RuleFor(r => r.ReturnDate).Must(DeliveryDateShouldBeGreater).WithMessage("Verilen tarih bugünün tarihinden büyük olmalıdır!");
19 | }
20 |
21 | private bool RentalDateCannotBeLessThanTodayDate(DateTime arg)
22 | {
23 | return arg.Date >= DateTime.Today;
24 | }
25 |
26 | private bool DeliveryDateShouldBeGreater(DateTime arg)
27 | {
28 | return arg.Date > DateTime.Now;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/ReCapProject.Business/ValidationRules/FluentValidation/UserValidator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using FluentValidation;
5 | using ReCapProject.Core.Entities.Concrete;
6 | using ReCapProject.Entities.Concrete;
7 |
8 | namespace ReCapProject.Business.ValidationRules.FluentValidation
9 | {
10 | public class UserValidator:AbstractValidator
11 | {
12 | public UserValidator()
13 | {
14 | RuleFor(u => u.FirstName).NotEmpty();
15 | RuleFor(u => u.LastName).NotEmpty();
16 | RuleFor(u => u.Email).NotEmpty();
17 | RuleFor(u => u.Email).EmailAddress();
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/ReCapProject.Console/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using ReCapProject.Business.Concrete;
3 | using ReCapProject.Business.Constants;
4 | using ReCapProject.Core.Utilities.Results;
5 | using ReCapProject.DataAccess.Abstract;
6 | using ReCapProject.DataAccess.Concrete.EntityFramework;
7 | using ReCapProject.Entities.Concrete;
8 |
9 | namespace ReCapProject.Console
10 | {
11 | class Program
12 | {
13 | static void Main(string[] args)
14 | {
15 | //CarAddUpdateDeleteTest(carManager);
16 | //CarManagerTest();
17 |
18 | //RentalManagerAddTest();
19 | //RentalUpdateTest();
20 | }
21 |
22 | private static void RentalUpdateTest()
23 | {
24 | RentalManager rentalManager = new RentalManager(new EfRentalDal());
25 | var result = rentalManager.Update(new Rental
26 | {
27 | RentalId = 1,
28 | CarId = 3,
29 | CustomerId = 1,
30 | RentDate = new DateTime(2021, 2, 15),
31 | ReturnDate = new DateTime(2021, 4, 11)
32 | });
33 | System.Console.WriteLine(result.Message);
34 | }
35 |
36 | private static void RentalManagerAddTest()
37 | {
38 | RentalManager rentalManager = new RentalManager(new EfRentalDal());
39 | var result = rentalManager.Add(new Rental
40 | {
41 | CarId = 2,
42 | CustomerId = 1,
43 | RentDate = new DateTime(2021, 3, 15),
44 | ReturnDate = new DateTime(2021, 5, 12)
45 | });
46 | System.Console.WriteLine(result.Message);
47 | }
48 |
49 | private static void CarManagerTest()
50 | {
51 | CarManager carManager = new CarManager(new EfCarDal());
52 | var result = carManager.GetAll();
53 |
54 | if (result.Success)
55 | {
56 | foreach (var car in result.Data)
57 | {
58 | //Console.WriteLine("Marka:{0} Model:{1} Kiralama Ücreti:{2}",car.Description,car.ModelYear,car.DailyPrice );
59 | System.Console.WriteLine("Araba Adı:{0} / Kiralama Ücreti:{1}", car.Description, car.DailyPrice);
60 | }
61 | }
62 | else
63 | {
64 | System.Console.WriteLine(result.Message);
65 | }
66 | }
67 |
68 | private static void CarAddUpdateDeleteTest(CarManager carManager)
69 | {
70 | //carManager.Add(new Car
71 | //{
72 | // BrandId = 1,
73 | // ColorId = 2,
74 | // Description = "ugr",
75 | // DailyPrice = 152,
76 | // ModelYear = 2015
77 | //});
78 |
79 | //carManager.Update(new Car
80 | //{
81 | // CarId = 3,
82 | // BrandId = 2,
83 | // ColorId = 1,
84 | // Description = "ozan",
85 | // DailyPrice = 110,
86 | // ModelYear = 2016
87 | //});
88 |
89 | //carManager.Delete(new Car
90 | //{
91 | // CarId = 3,
92 | // BrandId = 2,
93 | // ColorId = 1,
94 | // Description = "Reno",
95 | // DailyPrice = 120,
96 | // ModelYear = 2016
97 | //}
98 | //);
99 |
100 |
101 |
102 | }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/ReCapProject.Console/ReCapProject.Console.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/ReCapProject.Core/Aspects/Caching/CacheAspect.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Castle.DynamicProxy;
6 | using ReCapProject.Core.CrossCuttingConcerns.Caching;
7 | using ReCapProject.Core.Utilities.İnterceptors;
8 | using ReCapProject.Core.Utilities.IoC;
9 | using Microsoft.Extensions.DependencyInjection;
10 |
11 | namespace ReCapProject.Core.Aspects.Caching
12 | {
13 | public class CacheAspect : MethodInterception
14 | {
15 | private int _duration;
16 | private ICacheManager _cacheManager;
17 |
18 | public CacheAspect(int duration = 60)
19 | {
20 | _duration = duration;
21 | _cacheManager = ServiceTool.ServiceProvider.GetService();
22 | }
23 |
24 | public override void Intercept(IInvocation invocation)
25 | {
26 | var methodName = string.Format($"{invocation.Method.ReflectedType.FullName}.{invocation.Method.Name}");
27 | var arguments = invocation.Arguments.ToList();
28 | var key = $"{methodName}({string.Join(",", arguments.Select(x => x?.ToString() ?? ""))})";
29 | if (_cacheManager.IsAdd(key))
30 | {
31 | invocation.ReturnValue = _cacheManager.Get(key);
32 | return;
33 | }
34 | invocation.Proceed();
35 | _cacheManager.Add(key, invocation.ReturnValue, _duration);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/ReCapProject.Core/Aspects/Caching/CacheRemoveAspect.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Castle.DynamicProxy;
5 | using ReCapProject.Core.CrossCuttingConcerns.Caching;
6 | using ReCapProject.Core.Utilities.İnterceptors;
7 | using ReCapProject.Core.Utilities.IoC;
8 | using Microsoft.Extensions.DependencyInjection;
9 |
10 | namespace ReCapProject.Core.Aspects.Caching
11 | {
12 | public class CacheRemoveAspect : MethodInterception
13 | {
14 | private string _pattern;
15 | private ICacheManager _cacheManager;
16 |
17 | public CacheRemoveAspect(string pattern)
18 | {
19 | _pattern = pattern;
20 | _cacheManager = ServiceTool.ServiceProvider.GetService();
21 | }
22 |
23 | protected override void OnSuccess(IInvocation invocation)
24 | {
25 | _cacheManager.RemoveByPattern(_pattern);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/ReCapProject.Core/Aspects/Performance/PerformanceAspect.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Text;
5 | using Castle.DynamicProxy;
6 | using Microsoft.Extensions.DependencyInjection;
7 | using ReCapProject.Core.Utilities.İnterceptors;
8 | using ReCapProject.Core.Utilities.IoC;
9 |
10 | namespace ReCapProject.Core.Aspects.Performance
11 | {
12 | public class PerformanceAspect:MethodInterception
13 | {
14 | private int _interval;
15 | private Stopwatch _stopwatch;
16 |
17 | public PerformanceAspect(int interval)
18 | {
19 | _interval = interval;
20 | _stopwatch = ServiceTool.ServiceProvider.GetService();
21 | }
22 |
23 |
24 | protected override void OnBefore(IInvocation invocation)
25 | {
26 | _stopwatch.Start();
27 | }
28 |
29 | protected override void OnAfter(IInvocation invocation)
30 | {
31 | if (_stopwatch.Elapsed.TotalSeconds > _interval)
32 | {
33 | Debug.WriteLine($"Performance : {invocation.Method.DeclaringType.FullName}.{invocation.Method.Name}-->{_stopwatch.Elapsed.TotalSeconds}");
34 | }
35 | _stopwatch.Reset();
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/ReCapProject.Core/Aspects/Transaction/TransactionScopeAspect.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Transactions;
5 | using Castle.DynamicProxy;
6 | using ReCapProject.Core.Utilities.İnterceptors;
7 |
8 | namespace ReCapProject.Core.Aspects.Transaction
9 | {
10 | public class TransactionScopeAspect:MethodInterception
11 | {
12 | public override void Intercept(IInvocation invocation)
13 | {
14 | using (TransactionScope transactionScope = new TransactionScope())
15 | {
16 | try
17 | {
18 | invocation.Proceed();
19 | transactionScope.Complete();
20 | }
21 | catch (System.Exception e)
22 | {
23 | transactionScope.Dispose();
24 | throw e;
25 | }
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/ReCapProject.Core/Aspects/Validation/ValidationAspect.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Castle.DynamicProxy;
6 | using FluentValidation;
7 | using ReCapProject.Core.CrossCuttingConcerns.Validation;
8 | using ReCapProject.Core.Utilities.İnterceptors;
9 |
10 | namespace ReCapProject.Core.Aspects.Validation
11 | {
12 | public class ValidationAspect : MethodInterception
13 | {
14 | private Type _validatorType;
15 |
16 | public ValidationAspect(Type validatorType)
17 | {
18 | if (!typeof(IValidator).IsAssignableFrom(validatorType))
19 | {
20 | throw new System.Exception("Bu bir doğrulama sınıf değildir");
21 | }
22 | _validatorType = validatorType;
23 | }
24 |
25 | protected override void OnBefore(IInvocation invocation)
26 | {
27 | var validator = (IValidator)Activator.CreateInstance(_validatorType);
28 | var entityType = _validatorType.BaseType.GetGenericArguments()[0];
29 | var entities = invocation.Arguments.Where(t => t.GetType() == entityType);
30 | foreach (var entity in entities)
31 | {
32 | ValidationTool.Validate(validator, entity);
33 | }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/ReCapProject.Core/CrossCuttingConcerns/Caching/ICacheManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace ReCapProject.Core.CrossCuttingConcerns.Caching
6 | {
7 | public interface ICacheManager
8 | {
9 | T Get(string key);
10 | object Get(string key);
11 | void Add(string key, object value, int duration);
12 | bool IsAdd(string key);
13 | void Remove(string key);
14 | void RemoveByPattern(string pattern);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ReCapProject.Core/CrossCuttingConcerns/Caching/Microsoft/MemoryCacheManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Text.RegularExpressions;
6 | using Microsoft.Extensions.Caching.Memory;
7 | using Microsoft.Extensions.DependencyInjection;
8 | using ReCapProject.Core.Utilities.IoC;
9 |
10 | namespace ReCapProject.Core.CrossCuttingConcerns.Caching.Microsoft
11 | {
12 | public class MemoryCacheManager : ICacheManager
13 | {
14 | private IMemoryCache _memoryCache;
15 |
16 | public MemoryCacheManager()
17 | {
18 | _memoryCache = ServiceTool.ServiceProvider.GetService();
19 | }
20 |
21 | public T Get(string key)
22 | {
23 | return _memoryCache.Get(key);
24 | }
25 |
26 | public object Get(string key)
27 | {
28 | return _memoryCache.Get(key);
29 | }
30 |
31 | public void Add(string key, object value, int duration)
32 | {
33 | _memoryCache.Set(key, value, TimeSpan.FromMinutes(duration));
34 | }
35 |
36 | public bool IsAdd(string key)
37 | {
38 | return _memoryCache.TryGetValue(key, out _);
39 | }
40 |
41 | public void Remove(string key)
42 | {
43 | _memoryCache.Remove(key);
44 | }
45 |
46 | public void RemoveByPattern(string pattern)
47 | {
48 | var cacheEntriesCollectionDefinition = typeof(MemoryCache).GetProperty("EntriesCollection", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
49 | var cacheEntriesCollection = cacheEntriesCollectionDefinition.GetValue(_memoryCache) as dynamic;
50 | List cacheCollectionValues = new List();
51 |
52 | foreach (var cacheItem in cacheEntriesCollection)
53 | {
54 | ICacheEntry cacheItemValue = cacheItem.GetType().GetProperty("Value").GetValue(cacheItem, null);
55 | cacheCollectionValues.Add(cacheItemValue);
56 | }
57 |
58 | var regex = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase);
59 | var keysToRemove = cacheCollectionValues.Where(d => regex.IsMatch(d.Key.ToString())).Select(d => d.Key).ToList();
60 |
61 | foreach (var key in keysToRemove)
62 | {
63 | _memoryCache.Remove(key);
64 | }
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/ReCapProject.Core/CrossCuttingConcerns/Validation/ValidationTool.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using FluentValidation;
5 |
6 | namespace ReCapProject.Core.CrossCuttingConcerns.Validation
7 | {
8 | public static class ValidationTool
9 | {
10 | public static void Validate(IValidator validator,object entity)
11 | {
12 | var context=new ValidationContext