├── .gitattributes
├── .gitignore
├── .idea
├── .idea.ReCapProject
│ └── .idea
│ │ ├── .gitignore
│ │ ├── dataSources.xml
│ │ ├── encodings.xml
│ │ ├── indexLayout.xml
│ │ └── vcs.xml
└── config
│ └── applicationhost.config
├── Business
├── Abstract
│ ├── IAuthService.cs
│ ├── IBrandService.cs
│ ├── ICarImageService.cs
│ ├── ICarService.cs
│ ├── IColorService.cs
│ ├── ICustomerCreditCardService.cs
│ ├── ICustomerService.cs
│ ├── IPaymentService.cs
│ ├── IRentalService.cs
│ └── IUserService.cs
├── Business.csproj
├── BusinessAspects
│ └── Autofac
│ │ └── SecuredOperation.cs
├── Concrete
│ ├── AuthManager.cs
│ ├── BrandManager.cs
│ ├── CarImageManager.cs
│ ├── CarManager.cs
│ ├── ColorManager.cs
│ ├── CustomerCreditCardmanager.cs
│ ├── CustomerManager.cs
│ ├── PaymentManager.cs
│ ├── RentalManager.cs
│ └── UserManager.cs
├── Constans
│ └── Messages.cs
├── DependencyResolvers
│ └── Autofac
│ │ └── AutofacBusinessModule.cs
└── ValidationRules
│ └── FluentValidation
│ ├── BrandValidator.cs
│ ├── CarImageValidator.cs
│ ├── CarValidator.cs
│ ├── ColorValidator.cs
│ └── RentalValidator.cs
├── ConsoleUI
├── ConsoleUI.csproj
└── Program.cs
├── Core
├── Aspects
│ └── Autofac
│ │ ├── Caching
│ │ ├── CacheAspect.cs
│ │ └── CacheRemoveAspect.cs
│ │ ├── Exception
│ │ └── ExceptionLogAspect.cs
│ │ ├── Logging
│ │ └── LogAspect.cs
│ │ ├── Performance
│ │ └── PerformanceAspect.cs
│ │ ├── Transaction
│ │ └── TransactionScopeAspect.cs
│ │ └── Validation
│ │ └── ValidationAspect.cs
├── Core.csproj
├── CrossCuttingConcerns
│ ├── Caching
│ │ ├── ICacheManager.cs
│ │ └── Microsoft
│ │ │ └── MemoryCacheManager.cs
│ ├── Validate
│ │ └── ValidationTool.cs
│ └── logging
│ │ ├── Log4Net
│ │ ├── Layouts
│ │ │ └── JsonLayout.cs
│ │ ├── LoggerServiceBase.cs
│ │ ├── Loggers
│ │ │ ├── FileLogger.cs
│ │ │ └── SeqLogger.cs
│ │ └── SerializableLogEvent.cs
│ │ ├── LogDetail.cs
│ │ ├── LogDetailWithException.cs
│ │ └── LogParameter.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
└── Utilities
│ ├── Helpers
│ ├── Business
│ │ └── BusinessRules.cs
│ └── FileOperationsHelper.cs
│ ├── Interceptors
│ ├── AspectInterceptorSelector.cs
│ ├── MethodInterception.cs
│ └── MethodInterceptionBaseAttribute.cs
│ ├── IoC
│ ├── ICoreModule.cs
│ └── ServiceTool.cs
│ ├── Messages
│ └── AspectMessages.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
│ └── HasingHelper.cs
│ └── JWT
│ ├── AccessToken.cs
│ ├── ITokenHelper.cs
│ ├── JwtHelper.cs
│ └── TokenOptions.cs
├── DataAccess
├── Abstract
│ ├── ColorDal.cs
│ ├── IBrandDal.cs
│ ├── ICarDal.cs
│ ├── ICarImageDal.cs
│ ├── ICustomerCreditCardDal.cs
│ ├── ICustomerDal.cs
│ ├── IPaymentDal.cs
│ ├── IRentalDal.cs
│ └── IUsersDal.cs
├── Concrete
│ └── EntityFramework
│ │ ├── EfBrandDal.cs
│ │ ├── EfCarDal.cs
│ │ ├── EfCarImageDal.cs
│ │ ├── EfCardDal.cs
│ │ ├── EfColorDal.cs
│ │ ├── EfCustomerCreditCardDal.cs
│ │ ├── EfCustomerDal.cs
│ │ ├── EfRentalDal.cs
│ │ ├── EfUserDal.cs
│ │ └── ReCapContext.cs
└── DataAccess.csproj
├── Entities
├── Concrete
│ ├── Brand.cs
│ ├── Car.cs
│ ├── CarImage.cs
│ ├── Color.cs
│ ├── Customer.cs
│ ├── CustomerCreditCard.cs
│ ├── Payment.cs
│ └── Rental.cs
├── DTOs
│ ├── CarDetailsDto.cs
│ ├── CustomerDetailDto.cs
│ ├── RentalsDetailDto.cs
│ ├── UserForLoginDto.cs
│ ├── UserForRegisterDto.cs
│ └── UserForUpdateDto.cs
└── Entities.csproj
├── README.md
├── ReCapProject.sln
└── WebAPI
├── Controllers
├── AuthController.cs
├── BrandController.cs
├── CarImagesController.cs
├── Card.cs
├── CarsController.cs
├── ColorsController.cs
├── CustomerCreditCardController.cs
├── CustomersController.cs
├── RentalController.cs
├── UsersController.cs
└── WeatherForecastController.cs
├── Middlewares
├── AuthorizationMiddleware.cs
└── AuthorizationMiddlewareExtensions.cs
├── Program.cs
├── Properties
└── launchSettings.json
├── Startup.cs
├── WeatherForecast.cs
├── WebAPI.csproj
├── appsettings.Development.json
├── appsettings.json
└── wwwroot
└── Images
├── 330f6c7f-4e58-462b-bdd7-adf91fceb72f.png
└── 3fe22022-24ee-4b19-a6d5-6153d52754c4.jpg
/.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 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Oo]ut/
33 | [Ll]og/
34 | [Ll]ogs/
35 |
36 | # Visual Studio 2015/2017 cache/options directory
37 | .vs/
38 | # Uncomment if you have tasks that create the project's static files in wwwroot
39 | #wwwroot/
40 |
41 | # Visual Studio 2017 auto generated files
42 | Generated\ Files/
43 |
44 | # MSTest test Results
45 | [Tt]est[Rr]esult*/
46 | [Bb]uild[Ll]og.*
47 |
48 | # NUnit
49 | *.VisualState.xml
50 | TestResult.xml
51 | nunit-*.xml
52 |
53 | # Build Results of an ATL Project
54 | [Dd]ebugPS/
55 | [Rr]eleasePS/
56 | dlldata.c
57 |
58 | # Benchmark Results
59 | BenchmarkDotNet.Artifacts/
60 |
61 | # .NET Core
62 | project.lock.json
63 | project.fragment.lock.json
64 | artifacts/
65 |
66 | # ASP.NET Scaffolding
67 | ScaffoldingReadMe.txt
68 |
69 | # StyleCop
70 | StyleCopReport.xml
71 |
72 | # Files built by Visual Studio
73 | *_i.c
74 | *_p.c
75 | *_h.h
76 | *.ilk
77 | *.meta
78 | *.obj
79 | *.iobj
80 | *.pch
81 | *.pdb
82 | *.ipdb
83 | *.pgc
84 | *.pgd
85 | *.rsp
86 | *.sbr
87 | *.tlb
88 | *.tli
89 | *.tlh
90 | *.tmp
91 | *.tmp_proj
92 | *_wpftmp.csproj
93 | *.log
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio LightSwitch build output
298 | **/*.HTMLClient/GeneratedArtifacts
299 | **/*.DesktopClient/GeneratedArtifacts
300 | **/*.DesktopClient/ModelManifest.xml
301 | **/*.Server/GeneratedArtifacts
302 | **/*.Server/ModelManifest.xml
303 | _Pvt_Extensions
304 |
305 | # Paket dependency manager
306 | .paket/paket.exe
307 | paket-files/
308 |
309 | # FAKE - F# Make
310 | .fake/
311 |
312 | # CodeRush personal settings
313 | .cr/personal
314 |
315 | # Python Tools for Visual Studio (PTVS)
316 | __pycache__/
317 | *.pyc
318 |
319 | # Cake - Uncomment if you are using it
320 | # tools/**
321 | # !tools/packages.config
322 |
323 | # Tabs Studio
324 | *.tss
325 |
326 | # Telerik's JustMock configuration file
327 | *.jmconfig
328 |
329 | # BizTalk build output
330 | *.btp.cs
331 | *.btm.cs
332 | *.odx.cs
333 | *.xsd.cs
334 |
335 | # OpenCover UI analysis results
336 | OpenCover/
337 |
338 | # Azure Stream Analytics local run output
339 | ASALocalRun/
340 |
341 | # MSBuild Binary and Structured Log
342 | *.binlog
343 |
344 | # NVidia Nsight GPU debugger configuration file
345 | *.nvuser
346 |
347 | # MFractors (Xamarin productivity tool) working folder
348 | .mfractor/
349 |
350 | # Local History for Visual Studio
351 | .localhistory/
352 |
353 | # BeatPulse healthcheck temp database
354 | healthchecksdb
355 |
356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
357 | MigrationBackup/
358 |
359 | # Ionide (cross platform F# VS Code tools) working folder
360 | .ionide/
361 |
362 | # Fody - auto-generated XML schema
363 | FodyWeavers.xsd
--------------------------------------------------------------------------------
/.idea/.idea.ReCapProject/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Rider ignored files
5 | /projectSettingsUpdater.xml
6 | /.idea.ReCapProject.iml
7 | /modules.xml
8 | /contentModel.xml
9 | # Datasource local storage ignored files
10 | /dataSources/
11 | /dataSources.local.xml
12 | # Editor-based HTTP Client requests
13 | /httpRequests/
14 |
--------------------------------------------------------------------------------
/.idea/.idea.ReCapProject/.idea/dataSources.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | sqlserver.ms
6 | true
7 | com.microsoft.sqlserver.jdbc.SQLServerDriver
8 | jdbc:sqlserver://localhost\.:1433;database=ReCapProject
9 | $ProjectFileDir$
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/.idea.ReCapProject/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/.idea.ReCapProject/.idea/indexLayout.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/.idea.ReCapProject/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Business/Abstract/IAuthService.cs:
--------------------------------------------------------------------------------
1 | using Core.Entities.Concrete;
2 | using Core.Utilities.Results;
3 | using Core.Utilities.Security.JWT;
4 | using Entities.DTOs;
5 |
6 | namespace Business.Abstract
7 | {
8 | public interface IAuthService
9 | {
10 | IDataResult Register(UserForRegisterDto userForRegisterDto, string password);
11 | IDataResult Login(UserForLoginDto userForLoginDto);
12 |
13 | IDataResult CreateAccessToken(User user);
14 | IResult UserExists(string email);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Business/Abstract/IBrandService.cs:
--------------------------------------------------------------------------------
1 | using Core.Utilities.Results;
2 | using DataAccess.Abstract;
3 | using Entities.Concrete;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Text;
7 |
8 | namespace Business.Abstract
9 | {
10 | public interface IBrandService
11 | {
12 | IDataResult> GetAll();
13 | IDataResult GetById(int Id);
14 | IResult Add(Brand brand);
15 | IResult Delete(Brand brand);
16 | IResult Update(Brand brand);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Business/Abstract/ICarImageService.cs:
--------------------------------------------------------------------------------
1 |
2 | using Core.Utilities;
3 | using Core.Utilities.Results;
4 | using Entities.Concrete;
5 | using Microsoft.AspNetCore.Http;
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Text;
9 |
10 | namespace Business.Abstract
11 | {
12 | public interface ICarImageService
13 | {
14 | IDataResult> GetAll();
15 | IResult Add(IFormFile file, CarImage carImage);
16 | IResult Update(IFormFile file, CarImage carImage);
17 | IResult Delete(CarImage carImage);
18 | IDataResult> GetCarListByCarID(int carID);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Business/Abstract/ICarService.cs:
--------------------------------------------------------------------------------
1 | using Core.Utilities.Results;
2 | using DataAccess.Abstract;
3 | using Entities.Concrete;
4 | using Entities.DTOs;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Text;
8 |
9 | namespace Business.Abstract
10 | {
11 | public interface ICarService
12 | {
13 | IDataResult GetById(int Id);
14 | IDataResult> GetAll();
15 | IDataResult> GetByColorId(int colorid);
16 | IDataResult> GetByBrandIdAndColorId(int brandId,int colorid);
17 | IResult Add(Car car);
18 | IDataResult> GetAllDetails();
19 | IResult Delete(Car car);
20 | IDataResult> GetByBrandId(int Brandid);
21 | IDataResult GetCarsByCarId(int carId);
22 | IDataResult GetDetailsByCarId(int carId);
23 |
24 | IResult Update(Car car);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Business/Abstract/IColorService.cs:
--------------------------------------------------------------------------------
1 | using Core.Utilities.Results;
2 | using DataAccess.Abstract;
3 | using Entities.Concrete;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Text;
7 |
8 | namespace Business.Abstract
9 | {
10 | public interface IColorService
11 | {
12 | IDataResult> GetAll();
13 | IDataResult GetById(int Id);
14 | IResult Add(Color color);
15 | IResult Update(Color color);
16 | IResult Delete(Color color);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Business/Abstract/ICustomerCreditCardService.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Core.Utilities.Results;
3 | using Entities.Concrete;
4 |
5 | namespace Business.Abstract
6 | {
7 | public interface ICustomerCreditCardService
8 | {
9 | IDataResult> GetAll();
10 | IDataResult> GetByCustomerId(int customerId);
11 | IResult Add(CustomerCreditCard customerCreditCard);
12 | IResult Delete(CustomerCreditCard customerCreditCard);
13 | IResult Update(CustomerCreditCard customerCreditCard);
14 | IResult Pay(CustomerCreditCard customerCreditCard);
15 | }
16 | }
--------------------------------------------------------------------------------
/Business/Abstract/ICustomerService.cs:
--------------------------------------------------------------------------------
1 | using Core.Utilities.Results;
2 | using Entities.Concrete;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 | using Entities.DTOs;
7 |
8 | namespace Business.Abstract
9 | {
10 | public interface ICustomerService
11 | {
12 | IDataResult> GetAll();
13 | IResult Add(Customer customer);
14 | IResult Update(Customer customer);
15 | IResult Delete(Customer customer);
16 | IDataResult GetById(int id);
17 | IDataResult> GetCustomerDetails();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Business/Abstract/IPaymentService.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Core.Utilities.Results;
3 | using Entities.Concrete;
4 |
5 | namespace Business.Abstract
6 | {
7 | public interface IPaymentService
8 | {
9 | IResult Add(Payment fakeCard);
10 | IResult Delete(Payment fakeCard);
11 | IResult Update(Payment fakeCard);
12 | IDataResult> GetAll();
13 | IDataResult GetById(int id);
14 | IDataResult> GetByCardNumber(string cardNumber);
15 | IResult IsCardExist(Payment fakeCard);
16 | }
17 | }
--------------------------------------------------------------------------------
/Business/Abstract/IRentalService.cs:
--------------------------------------------------------------------------------
1 | using Core.Utilities.Results;
2 | using Entities.Concrete;
3 | using Entities.DTOs;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Text;
7 |
8 | namespace Business.Abstract
9 | {
10 | public interface IRentalService
11 | {
12 | IDataResult> GetAllDetails();
13 | IResult Add(Rental rental);
14 | IDataResult> GetAll();
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Business/Abstract/IUserService.cs:
--------------------------------------------------------------------------------
1 | using Core.Entities.Concrete;
2 | using Core.Utilities.Results;
3 | using Entities.Concrete;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Text;
7 |
8 | namespace Business.Concrete
9 | {
10 | public interface IUserService
11 | {
12 | IDataResult> GetAll();
13 | IResult Add(User user);
14 | IResult Update(User user);
15 | IResult Delete(User user);
16 | IDataResult GetById(int Id);
17 | IDataResult> GetClaims(int id);
18 | IResult EditProfil(User user, string password);
19 | IDataResult GetUserByEmail(string email);
20 | User GetByMail(string mail);
21 |
22 |
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Business/Business.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.1
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Business/BusinessAspects/Autofac/SecuredOperation.cs:
--------------------------------------------------------------------------------
1 | using Castle.DynamicProxy;
2 | using Core.Extensions;
3 | using Core.Utilities.Interceptors;
4 | using Microsoft.AspNetCore.Http;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Text;
8 | using Business.Constans;
9 | using Microsoft.Extensions.DependencyInjection;
10 | using Core.Utilities.IoC;
11 |
12 | namespace 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 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Business/Concrete/AuthManager.cs:
--------------------------------------------------------------------------------
1 | using Business.Abstract;
2 | using Business.Constans;
3 | using Core.Entities.Concrete;
4 | using Core.Utilities.Results;
5 | using Core.Utilities.Security.JWT;
6 | using Core.Utilities.Security.Hashing;
7 | using Entities.DTOs;
8 | using System;
9 | using System.Collections.Generic;
10 | using System.Text;
11 |
12 | namespace Business.Concrete
13 | {
14 | public class AuthManager : IAuthService
15 | {
16 | private IUserService _userService;
17 | private ITokenHelper _tokenHelper;
18 |
19 |
20 |
21 | public AuthManager(IUserService userService, ITokenHelper tokenHelper)
22 | {
23 | _userService = userService;
24 | _tokenHelper = tokenHelper;
25 | }
26 |
27 | public IDataResult Register(UserForRegisterDto userForRegisterDto, string password)
28 | {
29 | byte[] passwordHash, passwordSalt;
30 |
31 | HasingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt);
32 | var user = new User
33 | {
34 | Email = userForRegisterDto.Email,
35 | FirstName = userForRegisterDto.FirstName,
36 | LastName = userForRegisterDto.LastName,
37 | PasswordHash = passwordHash,
38 | PasswordSalt = passwordSalt,
39 | Status = true
40 | };
41 | _userService.Add(user);
42 | return new SuccessDataResult(user, Messages.UserRegistered);
43 | }
44 |
45 | public IDataResult Login(UserForLoginDto userForLoginDto)
46 | {
47 | // buraya gelmesi lazımdı ?
48 | var userToCheck = _userService.GetByMail(userForLoginDto.Email);
49 | if (userToCheck == null)
50 | {
51 | return new ErrorDataResult("Kullanıcı bulunamadı");
52 | }
53 |
54 | if (!HasingHelper.VerifyPasswordHash(userForLoginDto.Password, userToCheck.PasswordHash, userToCheck.PasswordSalt))
55 | {
56 | return new ErrorDataResult("Parola hatası");
57 | }
58 |
59 | return new SuccessDataResult(userToCheck, "Başarılı giriş");
60 | }
61 |
62 |
63 | public IResult UserExists(string email)
64 | {
65 | if (_userService.GetByMail(email) != null)
66 | {
67 | return new ErrorResult(Messages.UserAlreadyExists);
68 | }
69 | return new SuccessResult("ekleme başarılı");
70 | }
71 |
72 | public IDataResult CreateAccessToken(User user)
73 | {
74 | var claims = _userService.GetClaims(user.Id);
75 | var accessToken = _tokenHelper.CreateToken(user, claims.Data);
76 | return new SuccessDataResult(accessToken, Messages.AccessTokenCreated);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/Business/Concrete/BrandManager.cs:
--------------------------------------------------------------------------------
1 | using Business.Abstract;
2 | using Business.Constans;
3 | using Business.ValidationRules.FluentValidation;
4 | using Core.Aspects.Autofac.Caching;
5 | using Core.Aspects.Autofac.Transaction;
6 | using Core.Aspects.Autofac.Validation;
7 | using Core.DataAccess;
8 | using Core.Utilities.Business;
9 | using Core.Utilities.Results;
10 | using DataAccess.Abstract;
11 | using Entities.Concrete;
12 | using System;
13 | using System.Collections.Generic;
14 | using System.Linq;
15 | using System.Linq.Expressions;
16 | using System.Text;
17 |
18 | namespace Business.Concrete
19 | {
20 | public class BrandManager : IBrandService
21 | {
22 |
23 | IBrandDal _branddal;
24 |
25 | public BrandManager(IBrandDal branddal)
26 | {
27 | _branddal = branddal;
28 | }
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | // [ValidationAspect(typeof(BrandValidator))]
37 | //[CacheRemoveAspect("get")]
38 | //[TransactionScopeAspect]
39 | public IResult Add(Brand brand)
40 | {
41 | IResult Result = BusinessRules.Run(SameBrandName(brand.BrandName));
42 | if (Result != null)
43 | {
44 | return Result;
45 | }
46 | _branddal.Add(brand);
47 | return new SuccessResult(Messages.AddedBrand);
48 |
49 | }
50 |
51 | public IResult Delete(Brand brand)
52 | {
53 | _branddal.Delete(brand);
54 | return new SuccessResult(Messages.Deleted);
55 | }
56 |
57 |
58 |
59 | public IDataResult> GetAll()
60 | {
61 | return new SuccessDataResult>(_branddal.GetAll());
62 | }
63 |
64 |
65 | public IDataResult GetById(int Id)
66 | {
67 | return new SuccessDataResult(_branddal.Get(p => p.BrandId == Id));
68 | }
69 |
70 | public IResult Update(Brand brand)
71 | {
72 | _branddal.Update(brand);
73 | return new SuccessResult(Messages.Updated);
74 |
75 | }
76 |
77 | private IResult SameBrandName(string brand)
78 | {
79 | var result = _branddal.GetAll(p => p.BrandName == brand).Any();
80 | if (result)
81 | {
82 | return new ErrorResult(Messages.SameBrandName);
83 | }
84 |
85 | return new SuccessResult(Messages.AddedBrand);
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/Business/Concrete/CarImageManager.cs:
--------------------------------------------------------------------------------
1 | using Business.Abstract;
2 | using Business.Constans;
3 | using Core.Utilities.Business;
4 | using Core.Utilities.Results;
5 | using DataAccess.Abstract;
6 | using Entities.Concrete;
7 | using Microsoft.AspNetCore.Http;
8 | using System;
9 | using System.Collections.Generic;
10 | using System.Text;
11 | using System.Linq;
12 | using Core.Utilities.Helper;
13 | using System.Text.RegularExpressions;
14 | using Core.Aspects.Autofac.Validation;
15 | using Business.ValidationRules.FluentValidation;
16 |
17 | namespace Business.Concrete
18 | {
19 | public class CarImageManager : ICarImageService
20 | {
21 | private readonly ICarImageDal _carImageDal;
22 | public CarImageManager(ICarImageDal carImageDal)
23 | {
24 | _carImageDal = carImageDal;
25 | }
26 |
27 | //[ValidationAspect(typeof(CarImageValidator))]
28 | public IResult Add(IFormFile file, CarImage carImage)
29 | {
30 | var imageLımıt = _carImageDal.GetAll(c => c.CarId == carImage.CarId).Count;
31 | if (imageLımıt > 5)
32 | {
33 | return new ErrorResult(Messages.CarImageLimit);
34 | }
35 | var carImageResult = FileHelper.Upload(file);
36 | if (!carImageResult.Success)
37 | {
38 | return new ErrorResult(carImageResult.Message);
39 | }
40 | carImage.ImagePath = carImageResult.Message;
41 | carImage.Date_ = DateTime.Now;
42 | _carImageDal.Add(carImage);
43 | return new SuccessResult(Messages.CarImageAdded);
44 | }
45 |
46 |
47 |
48 | public IResult Delete(CarImage carImage)
49 | {
50 | var image = _carImageDal.Get(c => c.Id == carImage.Id);
51 | if (image != null)
52 | {
53 | FileHelper.Delete(image.ImagePath);
54 | _carImageDal.Delete(carImage);
55 | return new SuccessResult(Messages.CarImageDeleted);
56 | }
57 | return new ErrorResult(Messages.CarImageNotFound);
58 |
59 |
60 |
61 | //var images = _carImageDal.GetAll();
62 |
63 | //foreach (var image in images)
64 | //{
65 | // if (image.Id == carImage.Id)
66 | // {
67 | // FileHelper.Delete(carImage.ImagePath);
68 | // return new SuccessResult();
69 | // }
70 |
71 |
72 | //}
73 | //return new ErrorResult();
74 |
75 | }
76 |
77 | public IDataResult> GetAll()
78 | {
79 | return new SuccessDataResult>(_carImageDal.GetAll());
80 | }
81 |
82 | public IDataResult GetById(int carImageId)
83 | {
84 | return new SuccessDataResult(_carImageDal.Get(c => c.CarId == carImageId));
85 |
86 | }
87 |
88 | public IDataResult> GetCarListByCarID(int carID)
89 | {
90 | IResult result = BusinessRules.Run(CarImageCheck(carID));
91 | if (result != null)
92 | {
93 | return new ErrorDataResult>(result.Message);
94 | }
95 | return new SuccessDataResult>(CarImageCheck(carID).Data);
96 | }
97 |
98 | // [ValidationAspect(typeof(CarImageValidator))]
99 | public IResult Update(IFormFile file, CarImage carImage)
100 | {
101 | var image = _carImageDal.Get(c => c.Id == carImage.Id);
102 | if (image == null)
103 | {
104 | return new ErrorResult(Messages.CarImageNotFound);
105 | }
106 | var updated = FileHelper.Update(file, image.ImagePath);
107 | if (!updated.Success)
108 | {
109 | return new ErrorResult(updated.Message);
110 | }
111 | carImage.ImagePath = updated.Message;
112 | _carImageDal.Update(carImage);
113 | return new SuccessResult(Messages.CarImageUpdated);
114 | }
115 |
116 | //BUSINESS RULES
117 | private IDataResult> CarImageCheck(int carId)
118 | {
119 | try
120 | {
121 | string path = @"\images\logo.jpg";
122 | var result = _carImageDal.GetAll(c => c.CarId == carId).Any();
123 | if (!result)
124 | {
125 | List carimage = new List();
126 | carimage.Add(new CarImage { CarId = carId, ImagePath = path, Date_ = DateTime.Now });
127 | return new SuccessDataResult>(carimage);
128 | }
129 | }
130 | catch (Exception exception)
131 | {
132 |
133 | return new ErrorDataResult>(exception.Message);
134 | }
135 |
136 | return new SuccessDataResult>(_carImageDal.GetAll(p => p.CarId == carId).ToList());
137 | }
138 |
139 | }
140 |
141 | }
142 |
--------------------------------------------------------------------------------
/Business/Concrete/CarManager.cs:
--------------------------------------------------------------------------------
1 | using Business.Abstract;
2 | using DataAccess.Abstract;
3 | using Entities.Concrete;
4 | using Entities.DTOs;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Text;
8 | using System.Linq;
9 | using Core.Utilities.Results;
10 | using Business.Constans;
11 | using Core.Utilities.Interceptors;
12 | using Core.Aspects.Autofac.Validation;
13 | using Business.ValidationRules.FluentValidation;
14 | using Business.BusinessAspects.Autofac;
15 | using Core.Utilities.Business;
16 | using Core.Aspects.Autofac.Caching;
17 |
18 | namespace Business.Concrete
19 | {
20 | public class CarManager : ICarService
21 | {
22 | ICarDal _cardal;
23 |
24 | public CarManager(ICarDal cardal)
25 | {
26 | _cardal = cardal;
27 | }
28 | [ValidationAspect(typeof(CarValidator))]
29 | // [SecuredOperation("product.add,admin")]
30 | public IResult Add(Car car)
31 | {
32 | IResult Result = BusinessRules.Run(SameCarName(car.CarName));
33 | if (Result != null)
34 | {
35 | return Result;
36 | }
37 | _cardal.Add(car);
38 | return new SuccessResult(Messages.Added);
39 | }
40 |
41 | public IResult Delete(Car car)
42 | {
43 | _cardal.Delete(car);
44 | return new SuccessResult("silme başarılı");
45 | }
46 |
47 | public IDataResult> GetAll()
48 | {
49 | return new SuccessDataResult>(_cardal.GetAll());
50 | }
51 |
52 | public IDataResult> GetAllDetails()
53 | {
54 | return new SuccessDataResult>(_cardal.GetCarDetails());
55 | }
56 |
57 | public IDataResult> GetByBrandId(int Brandid)
58 | {
59 | return new SuccessDataResult>(_cardal.GetCarDetails(P => P.BrandId == Brandid));
60 | }
61 |
62 | public IDataResult> GetByBrandIdAndColorId(int brandId, int colorid)
63 | {
64 | if (brandId != 0)
65 | {
66 | return new SuccessDataResult>(_cardal.GetCarDetails(P => P.BrandId == brandId && P.ColorId == colorid));
67 | }
68 |
69 | if (colorid != 0)
70 | {
71 | return new SuccessDataResult>(_cardal.GetCarDetails(P => P.BrandId == brandId && P.ColorId == colorid));
72 | }
73 |
74 |
75 |
76 | return new SuccessDataResult>(_cardal.GetCarDetails());
77 | }
78 |
79 | public IDataResult> GetByColorId(int colorid)
80 | {
81 | return new SuccessDataResult>(_cardal.GetCarDetails(p => p.ColorId == colorid));
82 | }
83 |
84 | public IDataResult GetById(int Id)
85 | {
86 | return new SuccessDataResult(_cardal.Get(p => p.CarId == Id));
87 | }
88 |
89 |
90 | public IDataResult GetCarsByCarId(int carId)
91 | {
92 | return new SuccessDataResult(_cardal.Get(p => p.CarId == carId));
93 | }
94 |
95 | public IDataResult GetDetailsByCarId(int Carid)
96 | {
97 | return new SuccessDataResult(_cardal.GetCarDetail(p=> p.CarId== Carid));
98 | }
99 |
100 | public IResult Update(Car car)
101 | {
102 | _cardal.Update(car);
103 | return new SuccessResult();
104 |
105 | }
106 |
107 | private IResult SameCarName(string CarName)
108 | {
109 | var result = _cardal.GetAll(p=> p.CarName==CarName).Any();
110 | if (result)
111 | {
112 | return new ErrorResult(Messages.SameCarName);
113 | }
114 | return new SuccessResult(Messages.Added);
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/Business/Concrete/ColorManager.cs:
--------------------------------------------------------------------------------
1 | using Business.Abstract;
2 | using Business.Constans;
3 | using Business.ValidationRules.FluentValidation;
4 | using Core.Aspects.Autofac.Validation;
5 | using Core.Utilities.Results;
6 | using DataAccess.Abstract;
7 | using Entities.Concrete;
8 | using System;
9 | using System.Collections.Generic;
10 | using System.Linq.Expressions;
11 | using System.Text;
12 |
13 | namespace Business.Concrete
14 | {
15 | public class ColorManager : IColorService
16 | {
17 | IColorDal _colordal;
18 |
19 | public ColorManager(IColorDal _colordal)
20 | {
21 | this._colordal = _colordal;
22 | }
23 | [ValidationAspect(typeof(ColorValidator))]
24 | public IResult Add(Color color)
25 | {
26 | _colordal.Add(color);
27 | return new SuccessResult("ekleme başarılı");
28 | }
29 |
30 | public IResult Delete(Color color)
31 | {
32 | _colordal.Delete(color);
33 | return new SuccessResult(Messages.CarImageDeleted);
34 | }
35 |
36 | public IDataResult> GetAll()
37 | {
38 | var result = _colordal.GetAll();
39 | return new SuccessDataResult>(result);
40 | }
41 |
42 | public IDataResult GetById(int Id)
43 | {
44 | return new SuccessDataResult(_colordal.Get(p=> p.ColorId==Id));
45 | }
46 |
47 | public IResult Update(Color color)
48 | {
49 | _colordal.Update(color);
50 | return new SuccessResult(Messages.CarImageUpdated);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Business/Concrete/CustomerCreditCardmanager.cs:
--------------------------------------------------------------------------------
1 |
2 | using System.Collections.Generic;
3 | using Business.Abstract;
4 | using Core.Utilities.Results;
5 | using DataAccess.Abstract;
6 | using Entities.Concrete;
7 |
8 | namespace Business.Concrete
9 | {
10 | public class CustomerCreditCardManager:ICustomerCreditCardService
11 | {
12 | private ICustomerCreditCardDal _customerCreditCardDal;
13 |
14 | public CustomerCreditCardManager(ICustomerCreditCardDal customerCreditCardDal)
15 | {
16 | _customerCreditCardDal = customerCreditCardDal;
17 | }
18 |
19 | public IDataResult> GetAll()
20 | {
21 | return new SuccessDataResult> (_customerCreditCardDal.GetAll());
22 | }
23 |
24 | public IDataResult> GetByCustomerId(int customerId)
25 | {
26 | return new SuccessDataResult>(
27 | _customerCreditCardDal.GetAll(c => c.UserId == customerId));
28 | }
29 |
30 | public IResult Add(CustomerCreditCard customerCreditCard)
31 | {
32 | _customerCreditCardDal.Add(customerCreditCard);
33 | return new SuccessResult();
34 | }
35 |
36 | public IResult Delete(CustomerCreditCard customerCreditCard)
37 | {
38 | _customerCreditCardDal.Delete(customerCreditCard);
39 | return new SuccessResult();
40 | }
41 |
42 | public IResult Update(CustomerCreditCard customerCreditCard)
43 | {
44 | _customerCreditCardDal.Update(customerCreditCard);
45 | return new SuccessResult();
46 | }
47 |
48 | public IResult Pay(CustomerCreditCard customerCreditCard)
49 | {
50 | _customerCreditCardDal.Add(customerCreditCard);
51 | return new SuccessResult("ödeme başarılı");
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/Business/Concrete/CustomerManager.cs:
--------------------------------------------------------------------------------
1 | using Business.Abstract;
2 | using Core.Aspects.Autofac.Validation;
3 | using Core.Utilities.Results;
4 | using DataAccess.Concrete.EntityFramework;
5 | using Entities.Concrete;
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Text;
9 | using System.Linq;
10 | using Core.Utilities.Business;
11 | using Business.Constans;
12 | using Entities.DTOs;
13 |
14 | namespace Business.Concrete
15 | {
16 | public class CustomerManager:ICustomerService
17 | {
18 | ICustomerDal _customerDal;
19 |
20 | public CustomerManager(ICustomerDal customerDal)
21 | {
22 | _customerDal = customerDal;
23 | }
24 |
25 | public IDataResult> GetAll()
26 | {
27 | return new SuccessDataResult>(_customerDal.GetAll());
28 | }
29 |
30 | public IResult Add(Customer customer)
31 | {
32 | _customerDal.Add(customer);
33 | return new SuccessResult(Messages.Added);
34 | }
35 |
36 | public IResult Update(Customer customer)
37 | {
38 | _customerDal.Update(customer);
39 | return new SuccessResult("güncelleme işlemi başarılı");
40 | }
41 |
42 | public IResult Delete(Customer customer)
43 | {
44 | _customerDal.Delete(customer);
45 | return new SuccessResult("silme başarılı");
46 | }
47 |
48 | public IDataResult GetById(int id)
49 | {
50 | return new SuccessDataResult(_customerDal.Get(P =>P.Id==id));
51 | }
52 |
53 | public IDataResult> GetCustomerDetails()
54 | {
55 | return new SuccessDataResult>( _customerDal.GetCustomerDetails());
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/Business/Concrete/PaymentManager.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Business.Abstract;
3 | using Core.Utilities.Results;
4 | using DataAccess.Abstract;
5 | using Entities.Concrete;
6 |
7 | namespace Business.Concrete
8 | {
9 | public class PaymentManager:IPaymentService
10 | {
11 | IPaymentDal _fakeCardDal;
12 |
13 | public PaymentManager(IPaymentDal fakeCardDal)
14 | {
15 | _fakeCardDal = fakeCardDal;
16 | }
17 |
18 | public IResult Add(Payment fakeCard)
19 | {
20 | _fakeCardDal.Add(fakeCard);
21 | return new SuccessResult();
22 | }
23 |
24 | public IResult Delete(Payment fakeCard)
25 | {
26 | _fakeCardDal.Delete(fakeCard);
27 | return new SuccessResult();
28 | }
29 |
30 | public IDataResult> GetAll()
31 | {
32 | return new SuccessDataResult>(_fakeCardDal.GetAll());
33 | }
34 |
35 | public IDataResult GetById(int id)
36 | {
37 | return new SuccessDataResult(_fakeCardDal.Get(c => c.Id == id));
38 | }
39 |
40 | public IDataResult> GetByCardNumber(string cardNumber)
41 | {
42 | return new SuccessDataResult>(_fakeCardDal.GetAll(c => c.CardNumber == cardNumber));
43 | }
44 |
45 | public IResult IsCardExist(Payment fakeCard)
46 | {
47 | var result = _fakeCardDal.Get(c =>
48 | c.NameOnTheCard == fakeCard.NameOnTheCard && c.CardNumber == fakeCard.CardNumber &&
49 | c.CardCvv == fakeCard.CardCvv);
50 | if (result == null)
51 | {
52 | return new ErrorResult();
53 | }
54 |
55 | return new SuccessResult();
56 | }
57 |
58 | public IResult Update(Payment fakeCard)
59 | {
60 | _fakeCardDal.Update(fakeCard);
61 | return new SuccessResult();
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/Business/Concrete/RentalManager.cs:
--------------------------------------------------------------------------------
1 | using Business.Abstract;
2 | using Business.ValidationRules.FluentValidation;
3 | using Core.Aspects.Autofac.Validation;
4 | using Core.Utilities.Results;
5 | using DataAccess.Abstract;
6 | using Entities.Concrete;
7 | using Entities.DTOs;
8 | using System;
9 | using System.Collections.Generic;
10 | using System.Text;
11 |
12 | namespace Business.Concrete
13 | {
14 | public class RentalManager : IRentalService
15 | {
16 | IRentalDal _rentaldal;
17 |
18 | public RentalManager(IRentalDal rentaldal)
19 | {
20 | _rentaldal = rentaldal;
21 | }
22 | [ValidationAspect(typeof(RentalValidator))]
23 | public IResult Add(Rental rental)
24 | {
25 | //var result = _rentaldal.Get(p=> p.CarId== rental.CarId);
26 |
27 | _rentaldal.Add(rental);
28 | return new SuccessResult("başarılı bir şekilde kiralandı");
29 |
30 |
31 | }
32 |
33 | public IDataResult> GetAll()
34 | {
35 | return new SuccessDataResult>(_rentaldal.GetAll());
36 | }
37 |
38 | public IDataResult> GetAllDetails()
39 | {
40 | return new SuccessDataResult>(_rentaldal.GetAllDetails(),"Listeleme onaylandı");
41 | }
42 |
43 |
44 |
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Business/Concrete/UserManager.cs:
--------------------------------------------------------------------------------
1 | using Core.Utilities.Results;
2 | using DataAccess.Concrete.EntityFramework;
3 | using Entities.Concrete;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Text;
7 | using System.Linq;
8 | using Business.Constans;
9 | using Core.Utilities.Business;
10 | using Core.Entities.Concrete;
11 | using Core.Utilities.Security.Hashing;
12 |
13 | namespace Business.Concrete
14 | {
15 | public class UserManager : IUserService
16 | {
17 |
18 | IUsersDal _userDal;
19 |
20 | public UserManager(IUsersDal userDal)
21 | {
22 | _userDal = userDal;
23 | }
24 |
25 |
26 | public IResult Add(User user)
27 | {
28 | IResult result = BusinessRules.Run(SameUserName(user.Email));
29 |
30 | if (result!=null)
31 | {
32 | return result;
33 | }
34 |
35 | _userDal.Add(user);
36 | return new SuccessResult(Messages.AddedUser);
37 | }
38 |
39 |
40 |
41 | public IResult Delete(User user)
42 | {
43 | if (_userDal.GetAll(p=> p.Email==user.Email).Any())
44 | {
45 | _userDal.Delete(user);
46 | return new SuccessResult(Messages.Deleted);
47 | }
48 | return new ErrorResult("kullanıcı bulunamadı");
49 |
50 | }
51 |
52 | public IResult EditProfil(User user, string password)
53 | {
54 | byte[] passwordHash, passwordSalt;
55 | HasingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt);
56 | var updatedUser = new User
57 | {
58 | Id = user.Id,
59 | Email = user.Email,
60 | FirstName = user.FirstName,
61 | LastName = user.LastName,
62 | PasswordHash = passwordHash,
63 | PasswordSalt = passwordSalt,
64 | Status = user.Status
65 | };
66 | _userDal.Update(updatedUser);
67 | return new SuccessResult(Messages.UserUpdated);
68 | }
69 |
70 | public IDataResult> GetAll()
71 | {
72 |
73 | return new SuccessDataResult>("kullanıcılar listelendi");
74 | }
75 |
76 | public IDataResult GetById(int Id)
77 | {
78 | return new SuccessDataResult(_userDal.Get(p=> p.Id==Id));
79 | }
80 |
81 | public User GetByMail(string mail)
82 | {
83 | var user= (_userDal.Get(u => u.Email == mail));
84 | return user;
85 | }
86 |
87 | public IDataResult> GetClaims(int id)
88 | {
89 | return new SuccessDataResult>(_userDal.GetClaims(id));
90 | }
91 |
92 | public IDataResult GetUserByEmail(string email)
93 | {
94 | return new SuccessDataResult(_userDal.Get(u => u.Email == email));
95 | }
96 |
97 | public IResult Update(User user)
98 | {
99 | _userDal.Update(user);
100 | return new SuccessResult(Messages.Updated);
101 | }
102 |
103 |
104 |
105 | IDataResult> IUserService.GetAll()
106 | {
107 | return new SuccessDataResult>( _userDal.GetAll());
108 | }
109 |
110 |
111 |
112 | IDataResult IUserService.GetById(int Id)
113 | {
114 | return new SuccessDataResult(_userDal.Get(p=> p.Id==Id));
115 | }
116 |
117 |
118 |
119 | private IResult SameUserName(string Email)
120 | {
121 | var result = _userDal.GetAll(p=> p.Email==Email).Any();
122 | if (result)
123 | {
124 | return new ErrorResult(Messages.SameUserName);
125 | }
126 |
127 | return new SuccessResult();
128 | }
129 |
130 |
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/Business/Constans/Messages.cs:
--------------------------------------------------------------------------------
1 | using Core.Entities.Concrete;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Runtime.Serialization;
5 | using System.Text;
6 |
7 | namespace Business.Constans
8 | {
9 | public class Messages
10 | {
11 | public static string Added = "eklenme başarılı";
12 | public static string SameProductName = "aynı isme sahip ürün bulunmakta";
13 | public static string SameBrandName = "aynı isme sahip marka bulunmakta";
14 | public static string AddedBrand = "ekleme başarılı";
15 | public static string SameUserName = "aynı isme sahip kullanıcı bulunmakta";
16 | public static string AddedUser = "ekleme başarılı";
17 | public static string CarImageAdded = "ekleme başarılı";
18 | public static string CarImageDeleted = "silme başarılı";
19 | public static string CarImageNotFound = "resim bulunamadı";
20 | public static string CarImageUpdated = "güncelleme başarılı";
21 | public static string AddSingular = "resim eklendi ";
22 | public static string UpdateSingular = "resim güncellendi";
23 | public static string DeleteSingular = "resim silindi";
24 | public static string NotExist = "bulunamıyor";
25 | public static string InvalidFileExtension = "bulunamayan dosya yolu";
26 | public static string ImageNumberLimitExceeded = "resim sınırı yetersiz";
27 | public static string AuthorizationDenied = "AuthorizationDenied";
28 | public static string AccessTokenCreated = "token oluşturuldu";
29 | public static string UserRegistered = "kayır başarılı";
30 | public static string PasswordError = "şifre hatası";
31 | public static string SuccessfulLogin = "Giriş Başarılı";
32 | public static string UserNotFound = "kullanıcı bulunamadı";
33 | public static string UserAlreadyExists = "kullanıcı zaten kayıtlı";
34 | public static string Updated = "Güncelleme başarılı";
35 | public static string Deleted = "silme başarılı";
36 | public static string SameCarName = "bu araba isminde araba var";
37 | public static string Addedustomer = "müşteri eklendi";
38 | internal static string CarImageLimit = "limit hatası";
39 | internal static string UserUpdated = "profil güncellendi";
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Business/DependencyResolvers/Autofac/AutofacBusinessModule.cs:
--------------------------------------------------------------------------------
1 | using Autofac;
2 | using Autofac.Extras.DynamicProxy;
3 | using Business.Abstract;
4 | using Business.Concrete;
5 | using Castle.DynamicProxy;
6 | using Core.Utilities.Interceptors;
7 | using Core.Utilities.Security.JWT;
8 | using DataAccess.Abstract;
9 | using DataAccess.Concrete.EntityFramework;
10 | using Microsoft.AspNetCore.Http;
11 | using System;
12 | using System.Collections.Generic;
13 | using System.Text;
14 |
15 | namespace Business.DependencyResolvers.Autofac
16 | {
17 | public class AutofacBusinessModule:Module
18 | {
19 | protected override void Load(ContainerBuilder builder)
20 | {
21 | builder.RegisterType().As().SingleInstance();
22 | builder.RegisterType().As().SingleInstance();
23 |
24 | builder.RegisterType().As().SingleInstance();
25 | builder.RegisterType().As().SingleInstance();
26 |
27 | builder.RegisterType().As().SingleInstance();
28 | builder.RegisterType().As().SingleInstance();
29 |
30 | builder.RegisterType().As().SingleInstance();
31 | builder.RegisterType().As().SingleInstance();
32 |
33 | builder.RegisterType().As().SingleInstance();
34 | builder.RegisterType().As().SingleInstance();
35 |
36 | builder.RegisterType().As().SingleInstance();
37 | builder.RegisterType().As().SingleInstance();
38 |
39 | builder.RegisterType().As().SingleInstance();
40 | builder.RegisterType().As().SingleInstance();
41 |
42 | builder.RegisterType().As().SingleInstance();
43 | builder.RegisterType().As().SingleInstance();
44 |
45 |
46 | builder.RegisterType().As().SingleInstance();
47 | builder.RegisterType().As().SingleInstance();
48 |
49 |
50 | builder.RegisterType().As().SingleInstance();
51 | builder.RegisterType().As().SingleInstance();
52 |
53 | builder.RegisterType().As().SingleInstance();
54 |
55 |
56 |
57 | builder.RegisterType().As();
58 |
59 |
60 |
61 | var assembly = System.Reflection.Assembly.GetExecutingAssembly();
62 |
63 | builder.RegisterAssemblyTypes(assembly).AsImplementedInterfaces()
64 | .EnableInterfaceInterceptors(new ProxyGenerationOptions()
65 | {
66 | Selector = new AspectInterceptorSelector()
67 | }).SingleInstance();
68 | }
69 |
70 |
71 |
72 | }
73 | }
74 |
75 |
--------------------------------------------------------------------------------
/Business/ValidationRules/FluentValidation/BrandValidator.cs:
--------------------------------------------------------------------------------
1 | using Entities.Concrete;
2 | using FluentValidation;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace Business.ValidationRules.FluentValidation
8 | {
9 | public class BrandValidator : AbstractValidator
10 | {
11 | public BrandValidator()
12 | {
13 | RuleFor(p => p.BrandName).NotEmpty();
14 |
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Business/ValidationRules/FluentValidation/CarImageValidator.cs:
--------------------------------------------------------------------------------
1 | using FluentValidation;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 | using Entities.Concrete;
6 |
7 | namespace Business.ValidationRules.FluentValidation
8 | {
9 | public class CarImageValidator : AbstractValidator
10 | {
11 | public CarImageValidator()
12 | {
13 | RuleFor(p => p.CarId).NotEmpty();
14 | RuleFor(p => p.Date_).NotEmpty();
15 | RuleFor(p => p.Id).NotEmpty();
16 | RuleFor(p => p.ImagePath).NotEmpty();
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Business/ValidationRules/FluentValidation/CarValidator.cs:
--------------------------------------------------------------------------------
1 | using Entities.Concrete;
2 | using FluentValidation;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace Business.ValidationRules.FluentValidation
8 | {
9 | public class CarValidator:AbstractValidator
10 | {
11 | public CarValidator()
12 | {
13 | RuleFor(p=> p.BrandId).NotEmpty();
14 | RuleFor(p => p.ColorId).NotEmpty();
15 | RuleFor(p => p.CarName).NotEmpty();
16 | RuleFor(p => -p.DailyPrice).NotEmpty();
17 | RuleFor(p =>p.Description ).NotEmpty();
18 | RuleFor(p => p.DailyPrice).GreaterThan(0);
19 | RuleFor(p => p.ColorId).GreaterThan(0);
20 | RuleFor(p => p.BrandId).GreaterThan(0);
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Business/ValidationRules/FluentValidation/ColorValidator.cs:
--------------------------------------------------------------------------------
1 | using Entities.Concrete;
2 | using FluentValidation;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace Business.ValidationRules.FluentValidation
8 | {
9 | public class ColorValidator : AbstractValidator
10 | {
11 | public ColorValidator()
12 | {
13 |
14 | RuleFor(p => p.ColorName).NotEmpty();
15 |
16 |
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Business/ValidationRules/FluentValidation/RentalValidator.cs:
--------------------------------------------------------------------------------
1 | using Entities.Concrete;
2 | using FluentValidation;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace Business.ValidationRules.FluentValidation
8 | {
9 | public class RentalValidator : AbstractValidator
10 | {
11 | public RentalValidator()
12 | {
13 | RuleFor(p => p.CarId).NotEmpty();
14 | RuleFor(p => p.CustomerId).NotEmpty();
15 | RuleFor(p => p.RentDate).NotEmpty();
16 | RuleFor(p => p.ReturnDate).NotEmpty();
17 | RuleFor(p => p.CarId).GreaterThan(0);
18 | RuleFor(p => p.CustomerId).GreaterThan(0);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ConsoleUI/ConsoleUI.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/ConsoleUI/Program.cs:
--------------------------------------------------------------------------------
1 | using Business.Concrete;
2 | using DataAccess.Abstract;
3 | using DataAccess.Concrete.EntityFramework;
4 | using System;
5 |
6 | namespace ConsoleUI
7 | {
8 | class Program
9 | {
10 | static void Main(string[] args)
11 | {
12 | //sadece rental'deki buisness bölümünü doldurdum
13 | //diğer methodları test etmek isteyen arkadaşlar methodları dataaccess üzerinden çağırabilir
14 |
15 |
16 | RentalManager manager = new RentalManager(new EfRentalDal());
17 |
18 |
19 |
20 | }
21 |
22 |
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Core/Aspects/Autofac/Caching/CacheAspect.cs:
--------------------------------------------------------------------------------
1 | using Castle.DynamicProxy;
2 | using Core.CrossCuttingConcerns.Caching;
3 | using Core.Utilities.Interceptors;
4 | using Core.Utilities.IoC;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Text;
8 | using Microsoft.Extensions.DependencyInjection;
9 | using System.Linq;
10 |
11 | namespace Core.Aspects.Autofac.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 |
30 | if (_cacheManager.IsAdd(key))
31 | {
32 | invocation.ReturnValue = _cacheManager.Get(key);
33 | return;
34 | }
35 | invocation.Proceed();
36 | _cacheManager.Add(key, invocation.ReturnValue, _duration);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Core/Aspects/Autofac/Caching/CacheRemoveAspect.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Castle.DynamicProxy;
5 | using Core.CrossCuttingConcerns.Caching;
6 | using Core.Utilities.Interceptors;
7 | using Core.Utilities.IoC;
8 | using Microsoft.Extensions.DependencyInjection;
9 | namespace Core.Aspects.Autofac.Caching
10 | {
11 | public class CacheRemoveAspect : MethodInterception
12 | {
13 | private string _pattern;
14 | private ICacheManager _cacheManager;
15 |
16 | public CacheRemoveAspect(string pattern)
17 | {
18 | _pattern = pattern;
19 | _cacheManager = ServiceTool.ServiceProvider.GetService();
20 | }
21 |
22 | protected override void OnSuccess(IInvocation invocation)
23 | {
24 | _cacheManager.RemoveByPattern(_pattern);
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Core/Aspects/Autofac/Exception/ExceptionLogAspect.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Castle.DynamicProxy;
5 | using Core.CrossCuttingConcerns.Logging;
6 | using Core.CrossCuttingConcerns.Logging.Log4Net;
7 | using Core.Utilities.Interceptors;
8 | using Core.Utilities.Messages;
9 |
10 | namespace Core.Aspects.Autofac.Exception
11 | {
12 | public class ExceptionLogAspect:MethodInterception
13 | {
14 | private LoggerServiceBase _loggerServiceBase;
15 |
16 | public ExceptionLogAspect(Type loggerService)
17 | {
18 | if (loggerService.BaseType!=typeof(LoggerServiceBase))
19 | {
20 | throw new System.Exception(AspectMessages.WrongLoggerType);
21 | }
22 |
23 | _loggerServiceBase = (LoggerServiceBase) Activator.CreateInstance(loggerService);
24 | }
25 | protected override void OnException(IInvocation invocation,System.Exception e)
26 | {
27 | LogDetailWithException logDetailWithException = GetLogDetail(invocation);
28 | logDetailWithException.ExceptionMessage = e.Message;
29 | _loggerServiceBase.Error(logDetailWithException);
30 | }
31 |
32 | private LogDetailWithException GetLogDetail(IInvocation invocation)
33 | {
34 | var logParameters = new List();
35 |
36 | for (int i = 0; i < invocation.Arguments.Length; i++)
37 | {
38 | logParameters.Add(new LogParameter
39 | {
40 | Name= invocation.GetConcreteMethod().GetParameters()[i].Name,
41 | Value = invocation.Arguments[i],
42 | Type = invocation.Arguments[i].GetType().Name
43 | });
44 | }
45 |
46 | var logDetailWithException = new LogDetailWithException
47 | {
48 | MethodName = invocation.Method.Name,
49 | LogParameters = logParameters
50 | };
51 |
52 | return logDetailWithException;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/Core/Aspects/Autofac/Logging/LogAspect.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Castle.DynamicProxy;
6 | using Core.CrossCuttingConcerns.Logging;
7 | using Core.CrossCuttingConcerns.Logging.Log4Net;
8 | using Core.Utilities.Interceptors;
9 | using Core.Utilities.Messages;
10 |
11 | namespace Core.Aspects.Autofac.Logging
12 | {
13 | public class LogAspect:MethodInterception
14 | {
15 | private LoggerServiceBase _loggerServiceBase;
16 |
17 | public LogAspect(Type loggerService)
18 | {
19 | if (loggerService.BaseType!=typeof(LoggerServiceBase))
20 | {
21 | throw new System.Exception(AspectMessages.WrongLoggerType);
22 | }
23 |
24 | _loggerServiceBase = (LoggerServiceBase) Activator.CreateInstance(loggerService);
25 | }
26 |
27 | protected override void OnBefore(IInvocation invocation)
28 | {
29 | _loggerServiceBase.Info(GetLogDetail(invocation));
30 | }
31 |
32 | private LogDetail GetLogDetail(IInvocation invocation)
33 | {
34 | var logParameters = new List();
35 | for (int i = 0; i < invocation.Arguments.Length; i++)
36 | {
37 | logParameters.Add(new LogParameter
38 | {
39 | Name = invocation.GetConcreteMethod().GetParameters()[i].Name,
40 | Value = invocation.Arguments[i],
41 | Type = invocation.Arguments[i].GetType().Name
42 | });
43 | }
44 |
45 | var logDetail =new LogDetail
46 | {
47 | MethodName = invocation.Method.Name,
48 | LogParameters = logParameters
49 | };
50 |
51 | return logDetail;
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Core/Aspects/Autofac/Performance/PerformanceAspect.cs:
--------------------------------------------------------------------------------
1 | using Castle.DynamicProxy;
2 | using Core.Utilities.Interceptors;
3 | using Core.Utilities.IoC;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Diagnostics;
7 | using System.Text;
8 | using Microsoft.Extensions.DependencyInjection;
9 |
10 | namespace Core.Aspects.Autofac.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 |
--------------------------------------------------------------------------------
/Core/Aspects/Autofac/Transaction/TransactionScopeAspect.cs:
--------------------------------------------------------------------------------
1 | using Castle.DynamicProxy;
2 | using Core.Utilities.Interceptors;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 | using System.Transactions;
7 |
8 | namespace Core.Aspects.Autofac.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;
25 | }
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Core/Aspects/Autofac/Validation/ValidationAspect.cs:
--------------------------------------------------------------------------------
1 | using Castle.DynamicProxy;
2 | using Core.CrossCuttingConcerns;
3 | using Core.Utilities.Interceptors;
4 | using FluentValidation;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 |
10 | namespace Core.Aspects.Autofac.Validation
11 | {
12 | public class ValidationAspect : MethodInterception
13 | {
14 | private Type _validatorType;
15 | public ValidationAspect(Type validatorType)
16 | {
17 | if (!typeof(IValidator).IsAssignableFrom(validatorType))
18 | {
19 | throw new System.Exception("Bu bir doğrulama sınıfı değil.");
20 | }
21 |
22 | _validatorType = validatorType;
23 | }
24 | protected override void OnBefore(IInvocation invocation)
25 | {
26 | var validator = (IValidator)Activator.CreateInstance(_validatorType);
27 | var entityType = _validatorType.BaseType.GetGenericArguments()[0];
28 | var entities = invocation.Arguments.Where(t => t.GetType() == entityType);
29 | foreach (var entity in entities)
30 | {
31 | ValidationTool.Validate(validator, entity);
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/Core/Core.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.1
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Core/CrossCuttingConcerns/Caching/ICacheManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace 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 |
--------------------------------------------------------------------------------
/Core/CrossCuttingConcerns/Caching/Microsoft/MemoryCacheManager.cs:
--------------------------------------------------------------------------------
1 | using Core.Utilities.IoC;
2 | using Microsoft.Extensions.Caching.Memory;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 | using Microsoft.Extensions.DependencyInjection;
7 | using System.Text.RegularExpressions;
8 | using System.Linq;
9 |
10 | namespace Core.CrossCuttingConcerns.Caching.Microsoft
11 | {
12 | public class MemoryCacheManager : ICacheManager
13 | {
14 | //adapter pattern
15 | IMemoryCache _memoryCache;
16 |
17 | public MemoryCacheManager()
18 | {
19 | _memoryCache = ServiceTool.ServiceProvider.GetService();
20 | }
21 | public void Add(string key, object value, int duration)
22 | {
23 | _memoryCache.Set(key,value,TimeSpan.FromMinutes(duration));
24 | }
25 |
26 | public T Get(string key)
27 | {
28 | return _memoryCache.Get(key);
29 | }
30 |
31 | public object Get(string key)
32 | {
33 | return _memoryCache.Get(key);
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 |
--------------------------------------------------------------------------------
/Core/CrossCuttingConcerns/Validate/ValidationTool.cs:
--------------------------------------------------------------------------------
1 | using FluentValidation;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace Core.CrossCuttingConcerns
7 | {
8 | public static class ValidationTool
9 | {
10 | public static void Validate(IValidator validator,object Entity)
11 | {
12 | var Context = new ValidationContext