├── .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(Entity); 13 | var result = validator.Validate(Context); 14 | if (!result.IsValid) 15 | { 16 | throw new ValidationException(result.Errors); 17 | } 18 | 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/logging/Log4Net/Layouts/JsonLayout.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | using log4net.Core; 6 | using log4net.Layout; 7 | using Newtonsoft.Json; 8 | 9 | namespace Core.CrossCuttingConcerns.Logging.Log4Net.Layouts 10 | { 11 | public class JsonLayout:LayoutSkeleton 12 | { 13 | public override void ActivateOptions() 14 | { 15 | 16 | } 17 | 18 | public override void Format(TextWriter writer, LoggingEvent loggingEvent) 19 | { 20 | var logEvent = new SerializableLogEvent(loggingEvent); 21 | var json = JsonConvert.SerializeObject(logEvent, Formatting.Indented); 22 | writer.WriteLine(json); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/logging/Log4Net/LoggerServiceBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Xml; 7 | using log4net; 8 | using log4net.Repository; 9 | 10 | namespace Core.CrossCuttingConcerns.Logging.Log4Net 11 | { 12 | public class LoggerServiceBase 13 | { 14 | private ILog _log; 15 | public LoggerServiceBase(string name) 16 | { 17 | XmlDocument xmlDocument=new XmlDocument(); 18 | xmlDocument.Load(File.OpenRead("log4net.config")); 19 | 20 | ILoggerRepository loggerRepository = LogManager.CreateRepository(Assembly.GetEntryAssembly(), 21 | typeof(log4net.Repository.Hierarchy.Hierarchy)); 22 | log4net.Config.XmlConfigurator.Configure(loggerRepository, xmlDocument["log4net"]); 23 | 24 | _log = LogManager.GetLogger(loggerRepository.Name, name); 25 | 26 | 27 | } 28 | 29 | public bool IsInfoEnabled => _log.IsInfoEnabled; 30 | public bool IsDebugEnabled => _log.IsDebugEnabled; 31 | public bool IsWarnEnabled => _log.IsWarnEnabled; 32 | public bool IsFatalEnabled => _log.IsFatalEnabled; 33 | public bool IsErrorEnabled => _log.IsErrorEnabled; 34 | 35 | public void Info(object logMessage) 36 | { 37 | if(IsInfoEnabled) 38 | _log.Info(logMessage); 39 | } 40 | 41 | public void Debug(object logMessage) 42 | { 43 | if (IsDebugEnabled) 44 | _log.Debug(logMessage); 45 | } 46 | 47 | public void Warn(object logMessage) 48 | { 49 | if (IsWarnEnabled) 50 | _log.Warn(logMessage); 51 | } 52 | 53 | public void Fatal(object logMessage) 54 | { 55 | if (IsFatalEnabled) 56 | _log.Fatal(logMessage); 57 | } 58 | 59 | public void Error(object logMessage) 60 | { 61 | if (IsErrorEnabled) 62 | _log.Error(logMessage); 63 | } 64 | 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/logging/Log4Net/Loggers/FileLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Logging.Log4Net.Loggers 6 | { 7 | public class FileLogger : LoggerServiceBase 8 | { 9 | public FileLogger() : base("JsonFileLogger") 10 | { 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/logging/Log4Net/Loggers/SeqLogger.cs: -------------------------------------------------------------------------------- 1 | using Core.CrossCuttingConcerns.Logging.Log4Net; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.CrossCuttingConcerns.logging.Log4Net.Loggers 7 | { 8 | public class SeqLogger:LoggerServiceBase 9 | { 10 | public SeqLogger() : base("SeqAppender") 11 | { 12 | } 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/logging/Log4Net/SerializableLogEvent.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text; 3 | using System; 4 | using log4net.Core; 5 | 6 | namespace Core.CrossCuttingConcerns.Logging.Log4Net 7 | { 8 | [Serializable] 9 | public class SerializableLogEvent 10 | { 11 | private LoggingEvent _loggingEvent; 12 | 13 | public SerializableLogEvent(LoggingEvent loggingEvent) 14 | { 15 | _loggingEvent = loggingEvent; 16 | } 17 | 18 | public object Message => _loggingEvent.MessageObject; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/logging/LogDetail.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Logging 6 | { 7 | public class LogDetail 8 | { 9 | public LogDetail() 10 | { 11 | Date_ = DateTime.Now; 12 | } 13 | 14 | public string MethodName { get; set; } 15 | public DateTime Date_ { get; set; } 16 | public List LogParameters { get; set; } 17 | 18 | } 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/logging/LogDetailWithException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Logging 6 | { 7 | public class LogDetailWithException : LogDetail 8 | { 9 | public string ExceptionMessage { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/logging/LogParameter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Logging 6 | { 7 | public class LogParameter 8 | { 9 | public string Name { get; set; } 10 | public object Value { get; set; } 11 | public string Type { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/DataAccess/EntityFramework/EfEntityRepositoryBase.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using Microsoft.EntityFrameworkCore; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq.Expressions; 6 | using System.Text; 7 | using System.Linq; 8 | 9 | namespace Core.DataAccess.EntityFramework 10 | { 11 | public class EfEntityRepositoryBase : IEntityRepository 12 | where TEntity : class, IEntity, new() 13 | where TContext : DbContext, new() 14 | { 15 | public void Add(TEntity entity) 16 | { 17 | using (TContext context = new TContext()) 18 | { 19 | var AddedEntity = context.Entry(entity); 20 | AddedEntity.State = EntityState.Added; 21 | context.SaveChanges(); 22 | } 23 | } 24 | 25 | public void Delete(TEntity entity) 26 | { 27 | using (TContext context = new TContext()) 28 | { 29 | var DeletedEntity = context.Entry(entity); 30 | DeletedEntity.State = EntityState.Deleted; 31 | context.SaveChanges(); 32 | } 33 | } 34 | 35 | public TEntity Get(Expression> filter) 36 | { 37 | using (TContext context = new TContext()) 38 | { 39 | return context.Set().SingleOrDefault(filter); 40 | } 41 | } 42 | 43 | public List GetAll(Expression> filter = null) 44 | { 45 | using (TContext context = new TContext()) 46 | { 47 | return filter == null ? context.Set().ToList() 48 | : context.Set().Where(filter).ToList(); 49 | } 50 | } 51 | 52 | 53 | public void Update(TEntity entity) 54 | { 55 | using (TContext context = new TContext()) 56 | { 57 | var UpdateEntity = context.Entry(entity); 58 | UpdateEntity.State = EntityState.Modified; 59 | context.SaveChanges(); 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Core/DataAccess/IEntityRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Linq.Expressions; 5 | using Core.Entities; 6 | 7 | namespace Core.DataAccess 8 | { 9 | public interface IEntityRepository where T:class,IEntity,new() 10 | { 11 | List GetAll(Expression> filter=null); 12 | T Get(Expression> filter); 13 | void Add(T entity); 14 | void Delete(T entity); 15 | void Update(T entity); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Core/DependencyResolvers/CoreModule.cs: -------------------------------------------------------------------------------- 1 | using Core.CrossCuttingConcerns.Caching; 2 | using Core.CrossCuttingConcerns.Caching.Microsoft; 3 | using Core.Utilities.IoC; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Diagnostics; 9 | using System.Text; 10 | 11 | namespace Core.DependencyResolvers 12 | { 13 | public class CoreModule : ICoreModule 14 | { 15 | public void Load(IServiceCollection serviceCollection) 16 | { 17 | serviceCollection.AddMemoryCache(); 18 | serviceCollection.AddSingleton(); 19 | serviceCollection.AddSingleton(); 20 | serviceCollection.AddSingleton(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/OperationClaim.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | namespace Core.Entities.Concrete 5 | { 6 | public class OperationClaim:IEntity 7 | { 8 | public int Id { get; set; } 9 | public string Name { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/User.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text; 3 | 4 | namespace Core.Entities.Concrete 5 | { 6 | public class User:IEntity 7 | { 8 | public int Id { get; set; } 9 | public string FirstName { get; set; } 10 | public string LastName { get; set; } 11 | public string Email { get; set; } 12 | public byte[] PasswordSalt { get; set; } 13 | public byte[] PasswordHash { get; set; } 14 | public bool Status { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/UserOperationClaim.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities.Concrete 6 | { 7 | public class UserOperationClaim:IEntity 8 | { 9 | public int Id { get; set; } 10 | public int UserId { get; set; } 11 | public int OperationClaimId { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/Entities/IDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities 6 | { 7 | public interface IDto 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Core/Entities/IEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities 6 | { 7 | public interface IEntity 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Core/Extensions/ClaimExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IdentityModel.Tokens.Jwt; 4 | using System.Linq; 5 | using System.Security.Claims; 6 | using System.Text; 7 | 8 | namespace Core.Extensions 9 | { 10 | public static class ClaimExtensions 11 | { 12 | public static void AddEmail(this ICollection claims, string email) 13 | { 14 | claims.Add(new Claim(JwtRegisteredClaimNames.Email, email)); 15 | } 16 | 17 | public static void AddName(this ICollection claims, string name) 18 | { 19 | claims.Add(new Claim(ClaimTypes.Name, name)); 20 | } 21 | 22 | public static void AddNameIdentifier(this ICollection claims, string nameIdentifier) 23 | { 24 | claims.Add(new Claim(ClaimTypes.NameIdentifier, nameIdentifier)); 25 | } 26 | 27 | public static void AddRoles(this ICollection claims, string[] roles) 28 | { 29 | roles.ToList().ForEach(role => claims.Add(new Claim(ClaimTypes.Role, role))); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Core/Extensions/ClaimsPrincipalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Claims; 5 | using System.Text; 6 | 7 | namespace Core.Extensions 8 | { 9 | public static class ClaimsPrincipalExtensions 10 | { 11 | public static List Claims(this ClaimsPrincipal claimsPrincipal, string claimType) 12 | { 13 | var result = claimsPrincipal?.FindAll(claimType)?.Select(x => x.Value).ToList(); 14 | return result; 15 | } 16 | 17 | public static List ClaimRoles(this ClaimsPrincipal claimsPrincipal) 18 | { 19 | return claimsPrincipal?.Claims(ClaimTypes.Role); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Extensions/ErrorDetails.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation.Results; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Core.Extensions 8 | { 9 | public class ErrorDetails 10 | { 11 | public string Message { get; set; } 12 | public int StatusCode { get; set; } 13 | 14 | 15 | public override string ToString() 16 | { 17 | return JsonConvert.SerializeObject(this); 18 | } 19 | } 20 | 21 | public class ValidationErrorDetails : ErrorDetails 22 | { 23 | public IEnumerable Errors { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Core/Extensions/ExceptionMiddleware.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | using FluentValidation.Results; 3 | using Microsoft.AspNetCore.Http; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Net; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Core.Extensions 11 | { 12 | public class ExceptionMiddleware 13 | { 14 | private RequestDelegate _next; 15 | 16 | public ExceptionMiddleware(RequestDelegate next) 17 | { 18 | _next = next; 19 | } 20 | 21 | public async Task InvokeAsync(HttpContext httpContext) 22 | { 23 | try 24 | { 25 | await _next(httpContext); 26 | } 27 | catch (Exception e) 28 | { 29 | await HandleExceptionAsync(httpContext, e); 30 | } 31 | } 32 | 33 | private Task HandleExceptionAsync(HttpContext httpContext, Exception e) 34 | { 35 | httpContext.Response.ContentType = "application/json"; 36 | httpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; 37 | 38 | string message = "Internal Server Error"; 39 | IEnumerable errors; 40 | if (e.GetType() == typeof(ValidationException)) 41 | { 42 | message = e.Message; 43 | errors = ((ValidationException)e).Errors; 44 | httpContext.Response.StatusCode = 400; 45 | 46 | return httpContext.Response.WriteAsync(new ValidationErrorDetails 47 | { 48 | StatusCode = 400, 49 | Message = message, 50 | Errors = errors 51 | }.ToString()); 52 | 53 | } 54 | 55 | return httpContext.Response.WriteAsync(new ErrorDetails 56 | { 57 | StatusCode = httpContext.Response.StatusCode, 58 | Message = message 59 | }.ToString()); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Core/Extensions/ExceptionMiddlewareExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Extensions 7 | { 8 | public static class ExceptionMiddlewareExtensions 9 | { 10 | public static void ConfigureCustomExceptionMiddleware(this IApplicationBuilder app) 11 | { 12 | app.UseMiddleware(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Core/Extensions/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.IoC; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Core.Extensions 8 | { 9 | public static class ServiceCollectionExtensions 10 | { 11 | public static IServiceCollection AddOpendecyResolvers(this IServiceCollection serviceCollection,ICoreModule[] modules) 12 | { 13 | foreach (var module in modules) 14 | { 15 | module.Load(serviceCollection); 16 | } 17 | 18 | return ServiceTool.Create(serviceCollection); 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Utilities/Helpers/Business/BusinessRules.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Business 7 | { 8 | public class BusinessRules 9 | { 10 | public static IResult Run(params IResult[] logics) 11 | { 12 | foreach (var logic in logics ) 13 | { 14 | if (!logic.Success) 15 | { 16 | return logic; 17 | } 18 | 19 | } 20 | return null; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Core/Utilities/Helpers/FileOperationsHelper.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Microsoft.AspNetCore.Http; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Text; 7 | 8 | namespace Core.Utilities.Helper 9 | { 10 | public class FileHelper 11 | { 12 | private static string _currentDirectory = Environment.CurrentDirectory + "\\wwwroot"; 13 | private static string _folderName = "\\Images\\"; 14 | 15 | public static IResult Upload(IFormFile file) 16 | { 17 | var fileExists = CheckFileExists(file); 18 | if (fileExists.Message != null) 19 | { 20 | return new ErrorResult(fileExists.Message); 21 | } 22 | 23 | var type = Path.GetExtension(file.FileName); 24 | var typeValid = CheckFileTypeValid(type); 25 | var randomName = Guid.NewGuid().ToString(); 26 | 27 | if (typeValid.Message != null) 28 | { 29 | return new ErrorResult(typeValid.Message); 30 | } 31 | 32 | CheckDirectoryExists(_currentDirectory + _folderName); 33 | CreateImageFile(_currentDirectory + _folderName + randomName + type, file); 34 | return new SuccessResult((_folderName + randomName + type).Replace("\\", "/")); 35 | 36 | } 37 | 38 | public static IResult Update(IFormFile file, string imagePath) 39 | { 40 | var fileExists = CheckFileExists(file); 41 | if (fileExists.Message != null) 42 | { 43 | return new ErrorResult(fileExists.Message); 44 | } 45 | 46 | var type = Path.GetExtension(file.FileName); 47 | var typeValid = CheckFileTypeValid(type); 48 | var randomName = Guid.NewGuid().ToString(); 49 | 50 | if (typeValid.Message != null) 51 | { 52 | return new ErrorResult(typeValid.Message); 53 | } 54 | 55 | DeleteOldImageFile((_currentDirectory + imagePath).Replace("/", "\\")); 56 | CheckDirectoryExists(_currentDirectory + _folderName); 57 | CreateImageFile(_currentDirectory + _folderName + randomName + type, file); 58 | return new SuccessResult((_folderName + randomName + type).Replace("\\", "/")); 59 | } 60 | 61 | public static IResult Delete(string path) 62 | { 63 | DeleteOldImageFile((_currentDirectory + path).Replace("/", "\\")); 64 | return new SuccessResult(); 65 | } 66 | 67 | private static IResult CheckFileExists(IFormFile file) 68 | { 69 | if (file != null && file.Length > 0) 70 | { 71 | return new SuccessResult(); 72 | } 73 | return new ErrorResult("Dosya mevcut değil."); 74 | } 75 | 76 | private static IResult CheckFileTypeValid(string type) 77 | { 78 | if (type != ".jpeg" && type != ".png" && type != ".jpg") 79 | { 80 | return new ErrorResult("Yanlış dosya türü."); 81 | } 82 | return new SuccessResult(); 83 | } 84 | 85 | private static void CheckDirectoryExists(string directory) 86 | { 87 | if (!Directory.Exists(directory)) 88 | { 89 | Directory.CreateDirectory(directory); 90 | } 91 | } 92 | private static void CreateImageFile(string directory, IFormFile file) 93 | { 94 | using (FileStream fs = File.Create(directory)) 95 | { 96 | file.CopyTo(fs); 97 | fs.Flush(); 98 | } 99 | } 100 | 101 | private static void DeleteOldImageFile(string directory) 102 | { 103 | if (File.Exists(directory.Replace("/", "\\"))) 104 | { 105 | File.Delete(directory.Replace("/", "\\")); 106 | } 107 | 108 | } 109 | 110 | } 111 | } -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/AspectInterceptorSelector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using Castle.DynamicProxy; 7 | using Core.Aspects.Autofac.Performance; 8 | 9 | namespace Core.Utilities.Interceptors 10 | { 11 | public class AspectInterceptorSelector:IInterceptorSelector 12 | { 13 | public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) 14 | { 15 | var classAttributes = type.GetCustomAttributes 16 | (true).ToList(); 17 | var methodAttributes = type.GetMethod(method.Name) 18 | .GetCustomAttributes(true); 19 | classAttributes.AddRange(methodAttributes); 20 | classAttributes.Add(new PerformanceAspect(60)); 21 | return classAttributes.OrderBy(x => x.Priority).ToArray(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/MethodInterception.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Castle.DynamicProxy; 5 | 6 | namespace Core.Utilities.Interceptors 7 | { 8 | public abstract class MethodInterception:MethodInterceptionBaseAttribute 9 | { 10 | protected virtual void OnBefore(IInvocation invocation) { } 11 | protected virtual void OnAfter(IInvocation invocation) { } 12 | protected virtual void OnException(IInvocation invocation,System.Exception e) { } 13 | protected virtual void OnSuccess(IInvocation invocation) { } 14 | public override void Intercept(IInvocation invocation) 15 | { 16 | var isSuccess = true; 17 | OnBefore(invocation); 18 | try 19 | { 20 | invocation.Proceed(); 21 | } 22 | catch (Exception e) 23 | { 24 | isSuccess = false; 25 | OnException(invocation,e); 26 | throw; 27 | } 28 | finally 29 | { 30 | if (isSuccess) 31 | { 32 | OnSuccess(invocation); 33 | } 34 | } 35 | OnAfter(invocation); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/MethodInterceptionBaseAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Castle.DynamicProxy; 5 | 6 | namespace Core.Utilities.Interceptors 7 | { 8 | [AttributeUsage(AttributeTargets.Class|AttributeTargets.Method,AllowMultiple = true,Inherited = true)] 9 | public abstract class MethodInterceptionBaseAttribute:Attribute,IInterceptor 10 | { 11 | public int Priority { get; set; } 12 | 13 | public virtual void Intercept(IInvocation invocation) 14 | { 15 | 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Core/Utilities/IoC/ICoreModule.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.IoC 7 | { 8 | public interface ICoreModule 9 | { 10 | void Load(IServiceCollection serviceCollection); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Utilities/IoC/ServiceTool.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.IoC 7 | { 8 | public static class ServiceTool 9 | { 10 | public static IServiceProvider ServiceProvider { get; private set; } 11 | 12 | public static IServiceCollection Create(IServiceCollection services) 13 | { 14 | ServiceProvider = services.BuildServiceProvider(); 15 | return services; 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Core/Utilities/Messages/AspectMessages.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.Serialization; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Messages 7 | { 8 | public static class AspectMessages 9 | { 10 | public static string WrongLoggerType = "yanlış log tipi"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Utilities/Results/DataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class DataResult:Result,IDataResult 8 | { 9 | public DataResult(T data, bool success, string message) : base(success, message) 10 | { 11 | Data = data; 12 | } 13 | 14 | public DataResult(T data, bool success) : base(success) 15 | { 16 | Data = data; 17 | } 18 | 19 | 20 | public T Data { get; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Utilities/Results/ErrorDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class ErrorDataResult:DataResult 8 | { 9 | public ErrorDataResult(T data, string message) : base(data, false, message) { } 10 | public ErrorDataResult(T data) : base(data, false) 11 | { 12 | 13 | } 14 | public ErrorDataResult(string message) : base(default, false, message) 15 | { 16 | 17 | } 18 | 19 | public ErrorDataResult() : base(default, false) 20 | { 21 | 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Core/Utilities/Results/ErrorResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class ErrorResult:Result 8 | { 9 | public ErrorResult(string message) : base(false, message) 10 | { 11 | 12 | } 13 | 14 | public ErrorResult() : base(false) 15 | { 16 | 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Core/Utilities/Results/IDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public interface IDataResult:IResult 8 | { 9 | T Data { get; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Core/Utilities/Results/IResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public interface IResult 8 | { 9 | public bool Success { get;} 10 | public string Message { get;} 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Utilities/Results/Result.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class Result : IResult 8 | { 9 | 10 | public Result(bool success,string messages):this(success) 11 | { 12 | Message = messages; 13 | } 14 | 15 | public Result(bool success) 16 | { 17 | Success = success; 18 | } 19 | 20 | public string Message { get; } 21 | public bool Success { get; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Core/Utilities/Results/SuccessDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class SuccessDataResult:DataResult 8 | { 9 | public SuccessDataResult(T data, string message) : base(data, true, message) { } 10 | public SuccessDataResult(T data) : base(data, true) 11 | { 12 | 13 | } 14 | public SuccessDataResult(string message) : base(default, true, message) 15 | { 16 | 17 | } 18 | 19 | public SuccessDataResult() : base(default, true) 20 | { 21 | 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Core/Utilities/Results/SuccessResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class SuccessResult : Result 8 | { 9 | public SuccessResult(string message) : base(true, message) 10 | { 11 | 12 | } 13 | 14 | public SuccessResult() : base(true) 15 | { 16 | 17 | } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Encryption/SecurityKeyHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IdentityModel.Tokens; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Security.Encryption 7 | { 8 | public class SecurityKeyHelper 9 | { 10 | public static SecurityKey CreateSecurityKey(string key) 11 | { 12 | return new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key)); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Encryption/SigningCredentialsHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IdentityModel.Tokens; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Security.Encryption 7 | { 8 | public class SigningCredentialsHelper 9 | { 10 | public static SigningCredentials CreateSigningCredentials(SecurityKey securityKey) 11 | { 12 | return new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha512Signature); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Hashing/HasingHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Security.Hashing 6 | { 7 | public class HasingHelper 8 | { 9 | public static void CreatePasswordHash(string password,out byte[] passwordHash,out byte[] passwordSalt) 10 | { 11 | using (var hmac = new System.Security.Cryptography.HMACSHA512()) 12 | { 13 | passwordSalt = hmac.Key; 14 | passwordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(password)); 15 | } 16 | } 17 | 18 | public static bool VerifyPasswordHash(string password, byte[] passwordHash, byte[] passwordSalt) 19 | { 20 | using (var hmac = new System.Security.Cryptography.HMACSHA512(passwordSalt)) 21 | { 22 | var computedHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(password)); 23 | for (int i = 0; i < computedHash.Length; i++) 24 | { 25 | if (computedHash[i]!=passwordHash[i]) 26 | { 27 | return false; 28 | } 29 | } 30 | return true; 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/AccessToken.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Security.JWT 6 | { 7 | public class AccessToken 8 | { 9 | public string Token { get; set; } 10 | public DateTime Expiration { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/ITokenHelper.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Security.JWT 7 | { 8 | public interface ITokenHelper 9 | { 10 | AccessToken CreateToken(User user, List operationClaims); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/JwtHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IdentityModel.Tokens.Jwt; 4 | using System.Linq; 5 | using System.Security.Claims; 6 | using System.Text; 7 | using Core.Entities.Concrete; 8 | using Core.Extensions; 9 | using Core.Utilities.Security.Encryption; 10 | using Microsoft.Extensions.Configuration; 11 | using Microsoft.IdentityModel.Tokens; 12 | 13 | namespace Core.Utilities.Security.JWT 14 | { 15 | public class JwtHelper : ITokenHelper 16 | { 17 | public IConfiguration Configuration { get; } 18 | private TokenOptions _tokenOptions; 19 | private DateTime _accessTokenExpiration; 20 | public JwtHelper(IConfiguration configuration) 21 | { 22 | Configuration = configuration; 23 | _tokenOptions = Configuration.GetSection("TokenOptions").Get(); 24 | 25 | } 26 | public AccessToken CreateToken(User user, List operationClaims) 27 | { 28 | _accessTokenExpiration = DateTime.Now.AddMinutes(_tokenOptions.AccessTokenExpiration); 29 | var securityKey = SecurityKeyHelper.CreateSecurityKey(_tokenOptions.SecurityKey); 30 | var signingCredentials = SigningCredentialsHelper.CreateSigningCredentials(securityKey); 31 | var jwt = CreateJwtSecurityToken(_tokenOptions, user, signingCredentials, operationClaims); 32 | var jwtSecurityTokenHandler = new JwtSecurityTokenHandler(); 33 | var token = jwtSecurityTokenHandler.WriteToken(jwt); 34 | 35 | return new AccessToken 36 | { 37 | Token = token, 38 | Expiration = _accessTokenExpiration 39 | }; 40 | 41 | } 42 | 43 | public JwtSecurityToken CreateJwtSecurityToken(TokenOptions tokenOptions, User user, 44 | SigningCredentials signingCredentials, List operationClaims) 45 | { 46 | var jwt = new JwtSecurityToken( 47 | issuer: tokenOptions.Issuer, 48 | audience: tokenOptions.Audience, 49 | expires: _accessTokenExpiration, 50 | notBefore: DateTime.Now, 51 | claims: SetClaims(user, operationClaims), 52 | signingCredentials: signingCredentials 53 | ); 54 | return jwt; 55 | } 56 | 57 | private IEnumerable SetClaims(User user, List operationClaims) 58 | { 59 | var claims = new List(); 60 | claims.AddNameIdentifier(user.Id.ToString()); 61 | claims.AddEmail(user.Email); 62 | claims.AddName($"{user.FirstName} {user.LastName}"); 63 | claims.AddRoles(operationClaims.Select(c => c.Name).ToArray()); 64 | 65 | return claims; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/TokenOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Security.JWT 6 | { 7 | public class TokenOptions 8 | { 9 | public string Audience { get; set; } 10 | public string Issuer { get; set; } 11 | public int AccessTokenExpiration { get; set; } 12 | public string SecurityKey { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ColorDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface IColorDal:IEntityRepository 10 | { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IBrandDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface IBrandDal:IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICarDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq.Expressions; 7 | using System.Text; 8 | 9 | namespace DataAccess.Abstract 10 | { 11 | public interface ICarDal : IEntityRepository 12 | { 13 | List GetCarDetails(Expression> filter = null); 14 | CarDetailsDto GetCarDetail(Expression> filter = null); 15 | 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICarImageDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using Entities.Concrete; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface ICarImageDal : IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICustomerCreditCardDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | 4 | namespace DataAccess.Abstract 5 | { 6 | public interface ICustomerCreditCardDal:IEntityRepository 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /DataAccess/Abstract/ICustomerDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using Entities.DTOs; 7 | 8 | namespace DataAccess.Concrete.EntityFramework 9 | { 10 | public interface ICustomerDal:IEntityRepository 11 | { 12 | List GetCustomerDetails(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IPaymentDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | 4 | namespace DataAccess.Abstract 5 | { 6 | public interface IPaymentDal:IEntityRepository 7 | { 8 | 9 | } 10 | } -------------------------------------------------------------------------------- /DataAccess/Abstract/IRentalDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using Entities.Concrete; 6 | using Entities.DTOs; 7 | 8 | namespace DataAccess.Abstract 9 | { 10 | public interface IRentalDal:IEntityRepository 11 | { 12 | List GetAllDetails(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IUsersDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using Core.Entities.Concrete; 7 | namespace DataAccess.Concrete.EntityFramework 8 | { 9 | public interface IUsersDal:IEntityRepository 10 | { 11 | List GetClaims(int id); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfBrandDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFramework 9 | { 10 | public class EfBrandDal:EfEntityRepositoryBase,IBrandDal 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCarDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using Entities.DTOs; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq.Expressions; 8 | using System.Linq; 9 | using System.Text; 10 | 11 | namespace DataAccess.Concrete.EntityFramework 12 | { 13 | public class EfCarDal : EfEntityRepositoryBase, ICarDal 14 | { 15 | 16 | 17 | public List GetCarDetails(Expression> filter = null) 18 | { 19 | using (ReCapContext context = new ReCapContext()) 20 | { 21 | var results = from ca in filter == null ? context.Cars : context.Cars.Where(filter) 22 | 23 | join b in context.Brands on ca.BrandId equals b.BrandId 24 | join c in context.Colors on ca.ColorId equals c.ColorId 25 | select new CarDetailsDto 26 | { 27 | Id=ca.CarId,CarName=ca.CarName, 28 | BrandName=b.BrandName, 29 | ModelYear=ca.ModelYear, 30 | BrandId=b.BrandId, 31 | ColorId=c.ColorId, 32 | Description= ca.Description, 33 | CarId=ca.CarId, 34 | ColorName=c.ColorName, 35 | DailyPrice=ca.DailyPrice, 36 | Images = 37 | (from i in context.CarImages where i.CarId == ca.CarId select i.ImagePath).ToList() 38 | }; 39 | 40 | return results.ToList(); 41 | 42 | 43 | 44 | } 45 | } 46 | 47 | public CarDetailsDto GetCarDetail(Expression> filter = null) 48 | { 49 | using (ReCapContext context = new ReCapContext()) 50 | { 51 | var results = from ca in filter == null ? context.Cars : context.Cars.Where(filter) 52 | 53 | join b in context.Brands on ca.BrandId equals b.BrandId 54 | join c in context.Colors on ca.ColorId equals c.ColorId 55 | select new CarDetailsDto 56 | { 57 | Id = ca.CarId, 58 | CarName = ca.CarName, 59 | BrandName = b.BrandName, 60 | ModelYear = ca.ModelYear, 61 | BrandId = b.BrandId, 62 | ColorId = c.ColorId, 63 | Description = ca.Description, 64 | CarId = ca.CarId, 65 | ColorName = c.ColorName, 66 | DailyPrice = ca.DailyPrice, 67 | Images = 68 | (from i in context.CarImages where i.CarId == ca.CarId select i.ImagePath).ToList() 69 | }; 70 | return results.FirstOrDefault(); 71 | 72 | } 73 | } 74 | 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCarImageDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFramework 9 | { 10 | public class EfCarImageDal:EfEntityRepositoryBase,ICarImageDal 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCardDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | 5 | namespace DataAccess.Concrete.EntityFramework 6 | { 7 | public class EfCardDal:EfEntityRepositoryBase,IPaymentDal 8 | { 9 | 10 | } 11 | } -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfColorDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFramework 9 | { 10 | public class EfColorDal : EfEntityRepositoryBase, IColorDal 11 | { 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCustomerCreditCardDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | 5 | namespace DataAccess.Concrete.EntityFramework 6 | { 7 | public class EfCustomerCreditCardDal:EfEntityRepositoryBase,ICustomerCreditCardDal 8 | { 9 | 10 | } 11 | } -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCustomerDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Core.DataAccess.EntityFramework; 5 | using Core.Entities.Concrete; 6 | using Entities.Concrete; 7 | using Entities.DTOs; 8 | using System.Linq; 9 | 10 | namespace DataAccess.Concrete.EntityFramework 11 | { 12 | public class EfCustomerDal:EfEntityRepositoryBase,ICustomerDal 13 | { 14 | public List GetCustomerDetails() 15 | { 16 | using (ReCapContext context = new ReCapContext()) 17 | { 18 | var result = 19 | from u in context.Users 20 | join c in context.Customers on u.Id equals c.UserId 21 | select new CustomerDetailDto 22 | { 23 | Id = c.Id, 24 | Email = u.Email, 25 | FirstName = u.FirstName, 26 | LastName = u.LastName, 27 | CompanyName = c.CompanyName 28 | 29 | }; 30 | return result.ToList(); 31 | 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfRentalDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Core.DataAccess.EntityFramework; 5 | using DataAccess.Abstract; 6 | using Entities.Concrete; 7 | using Entities.DTOs; 8 | using System.Linq; 9 | 10 | namespace DataAccess.Concrete.EntityFramework 11 | { 12 | public class EfRentalDal : EfEntityRepositoryBase, IRentalDal 13 | { 14 | public List GetAllDetails() 15 | { 16 | using (ReCapContext context = new ReCapContext()) 17 | { 18 | var result = from ren in context.Rentals 19 | join ca in context.Cars on ren.CarId equals ca.CarId 20 | join ba in context.Brands on ca.BrandId equals ba.BrandId 21 | join cl in context.Colors on ca.ColorId equals cl.ColorId 22 | join us in context.Users on ren.CustomerId equals us.Id 23 | 24 | select new RentalsDetailDto 25 | { 26 | Id = ren.Id, 27 | CarId = ca.CarId, 28 | DailyPrice = ca.DailyPrice, 29 | RentDate = ren.RentDate, 30 | ReturnDate = ren.ReturnDate, 31 | UserNameLastName = us.FirstName + us.LastName, 32 | TotalPrice = 0, 33 | CarName = ca.CarName, 34 | BrandName = ba.BrandName 35 | }; 36 | 37 | 38 | 39 | 40 | 41 | return result.ToList(); 42 | 43 | } 44 | 45 | 46 | 47 | 48 | 49 | 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfUserDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using Core.Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using System.Linq; 7 | 8 | namespace DataAccess.Concrete.EntityFramework 9 | { 10 | public class EfUserDal : EfEntityRepositoryBase, IUsersDal 11 | { 12 | public List GetClaims(int userId) 13 | { 14 | using (var context = new ReCapContext()) 15 | { 16 | var result = from operationClaim in context.OperationClaims 17 | join userOperationClaim in context.UserOperationClaims 18 | on operationClaim.Id equals userOperationClaim.OperationClaimId 19 | where userOperationClaim.UserId == userId 20 | select new OperationClaim { Id = operationClaim.Id, Name = operationClaim.Name }; 21 | return result.ToList(); 22 | 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/ReCapContext.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Entities.Concrete; 3 | using Microsoft.EntityFrameworkCore; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Data.Entity.Infrastructure; 7 | using System.Text; 8 | 9 | namespace DataAccess.Concrete.EntityFramework 10 | { 11 | public class ReCapContext:DbContext 12 | { 13 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 14 | { 15 | //((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 180; 16 | optionsBuilder.UseSqlServer(@"Server=(localdb)\MSSQLLocalDB;Database=ReCapProject;Trusted_Connection=True"); 17 | } 18 | public DbSet Colors { get; set; } 19 | public DbSet Cars { get; set; } 20 | public DbSet Brands { get; set; } 21 | public DbSet Users {get; set; } 22 | public DbSet Customers { get; set; } 23 | public DbSet Rentals { get; set; } 24 | public DbSet CarImages { get; set; } 25 | public DbSet OperationClaims { get; set; } 26 | public DbSet UserOperationClaims { get; set; } 27 | public DbSet Payment { get; set; } 28 | public DbSet CustomerCreditCard { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /DataAccess/DataAccess.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Entities/Concrete/Brand.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Brand:IEntity 9 | { 10 | public int BrandId { get; set; } 11 | public string BrandName { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Entities/Concrete/Car.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Car:IEntity 9 | { 10 | public int CarId { get; set; } 11 | public string CarName { get; set; } 12 | public int BrandId { get; set; } 13 | public int ColorId { get; set; } 14 | public int ModelYear { get; set; } 15 | public int DailyPrice { get; set; } 16 | public string Description { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Entities/Concrete/CarImage.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class CarImage:IEntity 9 | { 10 | 11 | 12 | public int Id { get; set; } 13 | public int CarId { get; set; } 14 | public string ImagePath { get; set; } 15 | public DateTime Date_ { get; set; } 16 | 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Entities/Concrete/Color.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Color:IEntity 9 | { 10 | public int ColorId { get; set; } 11 | public string ColorName { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Entities/Concrete/Customer.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Customer:IEntity 9 | { 10 | public int Id { get; set; } 11 | public int UserId { get; set; } 12 | public String CompanyName { get; set; } 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Entities/Concrete/CustomerCreditCard.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Core.Entities; 3 | 4 | namespace Entities.Concrete 5 | { 6 | public class CustomerCreditCard:IEntity 7 | { 8 | public int Id { get; set; } 9 | public int UserId { get; set; } 10 | public int CartId { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /Entities/Concrete/Payment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Core.Entities; 3 | 4 | namespace Entities.Concrete 5 | { 6 | public class Payment:IEntity 7 | { 8 | public int Id { get; set; } 9 | public String NameOnTheCard { get; set; } 10 | public String CardNumber { get; set; } 11 | public String CardCvv { get; set; } 12 | public String ExpirationDate { get; set; } 13 | public int UserId { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /Entities/Concrete/Rental.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Rental:IEntity 9 | { 10 | public int Id{ get; set; } 11 | public int CarId { get; set; } 12 | public int CustomerId { get; set; } 13 | public DateTime RentDate { get; set; } 14 | public DateTime ReturnDate { get; set; } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Entities/DTOs/CarDetailsDto.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class CarDetailsDto 9 | { 10 | public int Id { get; set; } 11 | public string CarName { get; set; } 12 | public int ModelYear { get; set; } 13 | public int CarId { get; set; } 14 | public int BrandId { get; set; } 15 | public int ColorId { get; set; } 16 | public string BrandName { get; set; } 17 | public string ColorName { get; set; } 18 | public int DailyPrice { get; set; } 19 | public string Description { get; set; } 20 | public List Images { get; set; } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Entities/DTOs/CustomerDetailDto.cs: -------------------------------------------------------------------------------- 1 | namespace Entities.DTOs 2 | { 3 | public class CustomerDetailDto 4 | { 5 | public int Id { get; set; } 6 | public string FirstName { get; set; } 7 | public string LastName { get; set; } 8 | public string CompanyName { get; set; } 9 | public string Email { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /Entities/DTOs/RentalsDetailDto.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class RentalsDetailDto:IDto 9 | { 10 | public int Id { get; set; } 11 | public string CarName { get; set; } 12 | public string BrandName { get; set; } 13 | public int DailyPrice { get; set; } 14 | public DateTime RentDate { get; set; } 15 | public DateTime ReturnDate { get; set; } 16 | 17 | public string UserNameLastName { get; set; } 18 | 19 | public int CarId { get; set; } 20 | 21 | public int TotalPrice { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Entities/DTOs/UserForLoginDto.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class UserForLoginDto : IDto 9 | { 10 | public string Email { get; set; } 11 | public string Password { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Entities/DTOs/UserForRegisterDto.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | 3 | namespace Entities.DTOs 4 | { 5 | public class UserForRegisterDto : IDto 6 | { 7 | public string Email { get; set; } 8 | public string Password { get; set; } 9 | public string FirstName { get; set; } 10 | public string LastName { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Entities/DTOs/UserForUpdateDto.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using Core.Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Entities.DTOs 8 | { 9 | public class UserForUpdateDto : IDto 10 | { 11 | public User User { get; set; } 12 | public string Password { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Entities/Entities.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ReCapProject 2 | -------------------------------------------------------------------------------- /ReCapProject.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31205.134 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAccess", "DataAccess\DataAccess.csproj", "{28C152A8-7B6E-410A-B2B8-B19250C04959}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "Entities\Entities.csproj", "{7176CBA7-7DC6-4D6D-B653-FB84C212EEFD}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Business", "Business\Business.csproj", "{DC15AABF-E80E-457D-A12D-A474B93F1C35}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{61D4EAF9-DB62-4D44-95EF-64D547732467}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebAPI", "WebAPI\WebAPI.csproj", "{E42A397A-6A74-488C-A7AE-7CA35CDC5866}" 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Any CPU = Debug|Any CPU 19 | Release|Any CPU = Release|Any CPU 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {28C152A8-7B6E-410A-B2B8-B19250C04959}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {28C152A8-7B6E-410A-B2B8-B19250C04959}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {28C152A8-7B6E-410A-B2B8-B19250C04959}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {28C152A8-7B6E-410A-B2B8-B19250C04959}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {7176CBA7-7DC6-4D6D-B653-FB84C212EEFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {7176CBA7-7DC6-4D6D-B653-FB84C212EEFD}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {7176CBA7-7DC6-4D6D-B653-FB84C212EEFD}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {7176CBA7-7DC6-4D6D-B653-FB84C212EEFD}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {DC15AABF-E80E-457D-A12D-A474B93F1C35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {DC15AABF-E80E-457D-A12D-A474B93F1C35}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {DC15AABF-E80E-457D-A12D-A474B93F1C35}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {DC15AABF-E80E-457D-A12D-A474B93F1C35}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {61D4EAF9-DB62-4D44-95EF-64D547732467}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {61D4EAF9-DB62-4D44-95EF-64D547732467}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {61D4EAF9-DB62-4D44-95EF-64D547732467}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {61D4EAF9-DB62-4D44-95EF-64D547732467}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {E42A397A-6A74-488C-A7AE-7CA35CDC5866}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {E42A397A-6A74-488C-A7AE-7CA35CDC5866}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {E42A397A-6A74-488C-A7AE-7CA35CDC5866}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {E42A397A-6A74-488C-A7AE-7CA35CDC5866}.Release|Any CPU.Build.0 = Release|Any CPU 42 | EndGlobalSection 43 | GlobalSection(SolutionProperties) = preSolution 44 | HideSolutionNode = FALSE 45 | EndGlobalSection 46 | GlobalSection(ExtensibilityGlobals) = postSolution 47 | SolutionGuid = {F07A3877-9499-449E-B416-F8D687530D41} 48 | EndGlobalSection 49 | EndGlobal 50 | -------------------------------------------------------------------------------- /WebAPI/Controllers/AuthController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.DTOs; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class AuthController : ControllerBase 15 | { 16 | private IAuthService _authService; 17 | 18 | public AuthController(IAuthService authService) 19 | { 20 | _authService = authService; 21 | } 22 | 23 | [HttpPost("login")] 24 | public ActionResult Login(UserForLoginDto userForLoginDto) 25 | { 26 | var userToLogin = _authService.Login(userForLoginDto); 27 | if (!userToLogin.Success) 28 | { 29 | return BadRequest(userToLogin.Message); 30 | } 31 | 32 | var result = _authService.CreateAccessToken(userToLogin.Data); 33 | if (result.Success) 34 | { 35 | return Ok(result); 36 | } 37 | 38 | return BadRequest(result); 39 | } 40 | 41 | [HttpPost("register")] 42 | public ActionResult Register(UserForRegisterDto userForRegisterDto) 43 | { 44 | var userExists = _authService.UserExists(userForRegisterDto.Email); 45 | if (!userExists.Success) 46 | { 47 | return BadRequest(userExists); 48 | } 49 | 50 | var registerResult = _authService.Register(userForRegisterDto, userForRegisterDto.Password); 51 | var result = _authService.CreateAccessToken(registerResult.Data); 52 | if (result.Success) 53 | { 54 | return Ok(result); 55 | } 56 | 57 | return BadRequest(result); 58 | } 59 | 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /WebAPI/Controllers/BrandController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using DataAccess.Abstract; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | using Entities.Concrete; 10 | 11 | namespace WebAPI.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | [ApiController] 15 | public class BrandController : ControllerBase 16 | { 17 | IBrandService _brandService; 18 | 19 | public BrandController(IBrandService brandService) 20 | { 21 | _brandService = brandService; 22 | } 23 | 24 | [HttpGet("GetAll")] 25 | public ActionResult GetAll() 26 | { 27 | var result = _brandService.GetAll(); 28 | if (result.Success==true) 29 | { 30 | return Ok(result); 31 | } 32 | return BadRequest(result); 33 | } 34 | 35 | [HttpPost("Add")] 36 | public IActionResult Add(Brand brand) 37 | { 38 | var result = _brandService.Add(brand); 39 | if (result.Success==true) 40 | { 41 | return Ok(result); 42 | } 43 | return BadRequest(result); 44 | } 45 | 46 | 47 | [HttpPost("Delete")] 48 | public IActionResult Delete(Brand brand) 49 | { 50 | var result = _brandService.Delete(brand); 51 | if (result.Success==true) 52 | { 53 | return Ok(result); 54 | } 55 | 56 | return BadRequest(result); 57 | } 58 | 59 | 60 | [HttpPost("Update")] 61 | public IActionResult Update(Brand brand) 62 | { 63 | var result = _brandService.Update(brand); 64 | if (result.Success==true) 65 | { 66 | return Ok(result); 67 | } 68 | 69 | return BadRequest(result); 70 | } 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CarImagesController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class CarImagesController : ControllerBase 15 | { 16 | ICarImageService _carImageService; 17 | public CarImagesController(ICarImageService carImageService) 18 | { 19 | _carImageService = carImageService; 20 | } 21 | 22 | [HttpPost("add")] 23 | public IActionResult Add([FromForm] IFormFile image, [FromForm] CarImage img) 24 | { 25 | var result = _carImageService.Add(image, img); 26 | if (result.Success) 27 | { 28 | return Ok(result); 29 | } 30 | return BadRequest(result); 31 | } 32 | 33 | [HttpPost("delete")] 34 | public IActionResult Delete(CarImage img) 35 | { 36 | var result = _carImageService.Delete(img); 37 | if (result.Success) 38 | { 39 | return Ok(result); 40 | } 41 | return BadRequest(result); 42 | } 43 | 44 | [HttpPost("update")] 45 | public IActionResult Update([FromForm] IFormFile image, [FromForm] CarImage img) 46 | { 47 | var result = _carImageService.Update(image, img); 48 | if (result.Success) 49 | { 50 | return Ok(result); 51 | } 52 | return BadRequest(result); 53 | } 54 | 55 | [HttpGet("getcarlistbycarid")] 56 | public IActionResult GetCarListByCarID(int carId) 57 | { 58 | var result = _carImageService.GetCarListByCarID(carId); 59 | if (result.Success) 60 | { 61 | return Ok(result); 62 | } 63 | return BadRequest(result); 64 | } 65 | 66 | [HttpGet("getall")] 67 | public IActionResult GetAll() 68 | { 69 | var result = _carImageService.GetAll(); 70 | if (result.Success) 71 | { 72 | return Ok(result); 73 | } 74 | return BadRequest(result); 75 | } 76 | 77 | 78 | 79 | 80 | } 81 | } -------------------------------------------------------------------------------- /WebAPI/Controllers/Card.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | namespace WebAPI.Controllers 6 | { 7 | [Route("api/[controller]")] 8 | [ApiController] 9 | public class FakeCardsController : ControllerBase 10 | { 11 | IPaymentService _paymentService; 12 | 13 | public FakeCardsController(IPaymentService paymentService) 14 | { 15 | _paymentService = paymentService; 16 | } 17 | 18 | [HttpPost("add")] 19 | public IActionResult Add(Payment payment) 20 | { 21 | var result = _paymentService.Add(payment); 22 | if (result.Success) 23 | { 24 | return Ok(result); 25 | } 26 | 27 | return BadRequest(result); 28 | } 29 | 30 | [HttpDelete("delete")] 31 | public IActionResult Delete(Payment payment) 32 | { 33 | var result = _paymentService.Delete(payment); 34 | if (result.Success) 35 | { 36 | return Ok(result); 37 | } 38 | 39 | return BadRequest(result); 40 | } 41 | 42 | [HttpPut("update")] 43 | public IActionResult Update(Payment payment) 44 | { 45 | var result = _paymentService.Update(payment); 46 | if (result.Success) 47 | { 48 | return Ok(result); 49 | } 50 | 51 | return BadRequest(result); 52 | } 53 | 54 | [HttpGet("getall")] 55 | public IActionResult GetAll() 56 | { 57 | var result = _paymentService.GetAll(); 58 | if (result.Success) 59 | { 60 | return Ok(result); 61 | } 62 | 63 | return BadRequest(result); 64 | } 65 | 66 | [HttpGet("getbyid")] 67 | public IActionResult GetById(int id) 68 | { 69 | var result = _paymentService.GetById(id); 70 | if (result.Success) 71 | { 72 | return Ok(result); 73 | } 74 | 75 | return BadRequest(result); 76 | } 77 | 78 | [HttpGet("getbycardnumber")] 79 | public IActionResult GetByCardNumber(string cardNumber) 80 | { 81 | var result = _paymentService.GetByCardNumber(cardNumber); 82 | if (result.Success) 83 | { 84 | return Ok(result); 85 | } 86 | 87 | return BadRequest(result); 88 | } 89 | 90 | [HttpPost("iscardexist")] 91 | public IActionResult IsCardExist(Payment payment) 92 | { 93 | var result = _paymentService.IsCardExist(payment); 94 | if (result.Success) 95 | { 96 | return Ok(result); 97 | } 98 | 99 | return Ok(result); 100 | } 101 | } 102 | } -------------------------------------------------------------------------------- /WebAPI/Controllers/CarsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Microsoft.AspNetCore.Http; 3 | using Microsoft.AspNetCore.Mvc; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | using Entities.Concrete; 9 | namespace WebAPI.Controllers 10 | { 11 | [Route("api/[controller]")] 12 | [ApiController] 13 | public class CarsController : ControllerBase 14 | { 15 | ICarService _carservice; 16 | 17 | public CarsController(ICarService carservice) 18 | { 19 | _carservice = carservice; 20 | } 21 | 22 | [HttpGet("GetAll")] 23 | public IActionResult GetAll() 24 | { 25 | var result = _carservice.GetAll(); 26 | if (result.Success==true) 27 | { 28 | return Ok(result); 29 | } 30 | return BadRequest(result); 31 | } 32 | 33 | [HttpGet("GetById")] 34 | public IActionResult GetById(int Id) 35 | { 36 | var result = _carservice.GetById(Id); 37 | if (result.Success==true) 38 | { 39 | return Ok(result); 40 | } 41 | return BadRequest(result); 42 | } 43 | 44 | [HttpGet("GetByColorId")] 45 | public IActionResult GetByColorId(int Id) 46 | { 47 | var result = _carservice.GetByColorId(Id); 48 | if (result.Success==true) 49 | { 50 | return Ok(result); 51 | } 52 | return BadRequest(result); 53 | } 54 | [HttpGet("GetByBrandIdAndColorId")] 55 | public IActionResult GetByBrandIdAndColorId(int brandId,int ColorId) 56 | { 57 | var result = _carservice.GetByBrandIdAndColorId(brandId,ColorId); 58 | if (result.Success == true) 59 | { 60 | return Ok(result); 61 | } 62 | return BadRequest(result); 63 | } 64 | 65 | [HttpPost("Add")] 66 | 67 | public IActionResult Add(Car car) 68 | { 69 | var result = _carservice.Add(car); 70 | if (result.Success==true) 71 | { 72 | return Ok(result); 73 | } 74 | return BadRequest(result); 75 | } 76 | 77 | [HttpGet("GetAllDetails")] 78 | 79 | public IActionResult GetCarDetails() 80 | { 81 | var result = _carservice.GetAllDetails(); 82 | if(result.Success==true) 83 | { 84 | return Ok(result); 85 | } 86 | return BadRequest(result); 87 | } 88 | 89 | [HttpPost("Delete")] 90 | 91 | public IActionResult Delete(Car car) 92 | { 93 | var result = _carservice.Delete(car); 94 | if (result.Success==true) 95 | { 96 | return Ok(result); 97 | } 98 | return BadRequest(car); 99 | } 100 | 101 | [HttpGet("GetByBrandId")] 102 | public IActionResult GetByBrandId(int BrandId) 103 | { 104 | var result = _carservice.GetByBrandId(BrandId); 105 | if (result.Success==true) 106 | { 107 | return Ok(result); 108 | } 109 | return BadRequest(result); 110 | 111 | } 112 | 113 | 114 | [HttpGet("GetCarsDetailByCarId")] 115 | public IActionResult GetCarsByCarId(int Id) 116 | { 117 | var result = _carservice.GetDetailsByCarId(Id); 118 | if (result.Success==true) 119 | { 120 | return Ok(result); 121 | } 122 | return BadRequest(result); 123 | } 124 | 125 | [HttpPost("Update")] 126 | 127 | public IActionResult Update(Car car) 128 | { 129 | var result = _carservice.Update(car); 130 | if (result.Success == true) 131 | { 132 | return Ok(result); 133 | } 134 | return BadRequest(car); 135 | } 136 | 137 | [HttpGet("GetCarByCarId")] 138 | public IActionResult GetCarByCarId(int Id) 139 | { 140 | var result = _carservice.GetCarsByCarId(Id); 141 | if (result.Success==true) 142 | { 143 | return Ok(result); 144 | } 145 | 146 | return BadRequest(result); 147 | } 148 | } 149 | } 150 | 151 | -------------------------------------------------------------------------------- /WebAPI/Controllers/ColorsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class ColorsController : ControllerBase 15 | { 16 | IColorService _colorService; 17 | 18 | public ColorsController(IColorService colorService) 19 | { 20 | _colorService = colorService; 21 | } 22 | 23 | [HttpGet("GetAll")] 24 | public IActionResult GetAll() 25 | { 26 | var result = _colorService.GetAll(); 27 | if (result.Success==true) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result); 32 | } 33 | 34 | [HttpPost("Add")] 35 | public IActionResult Add(Color color) 36 | { 37 | var result = _colorService.Add(color); 38 | if (result.Success==true) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result); 43 | } 44 | 45 | 46 | [HttpPost("Delete")] 47 | public IActionResult Delete(Color color) 48 | { 49 | var result = _colorService.Delete(color); 50 | if (result.Success == true) 51 | { 52 | return Ok(result); 53 | } 54 | return BadRequest(result); 55 | } 56 | 57 | 58 | 59 | [HttpPost("Update")] 60 | public IActionResult Update(Color color) 61 | { 62 | var result = _colorService.Update(color); 63 | if (result.Success == true) 64 | { 65 | return Ok(result); 66 | } 67 | return BadRequest(result); 68 | } 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CustomerCreditCardController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | namespace WebAPI.Controllers 6 | { 7 | [Route("api/[controller]")] 8 | [ApiController] 9 | public class CustomerCreditCardController : ControllerBase 10 | { 11 | private ICustomerCreditCardService _customerCreditCardService; 12 | 13 | public CustomerCreditCardController(ICustomerCreditCardService customerCreditCardService) 14 | { 15 | _customerCreditCardService = customerCreditCardService; 16 | } 17 | 18 | [HttpGet("getall")] 19 | public IActionResult GetAll() 20 | { 21 | var result = _customerCreditCardService.GetAll(); 22 | if (result.Success) 23 | { 24 | return Ok(result); 25 | } 26 | 27 | return BadRequest(result); 28 | } 29 | 30 | [HttpGet("getbycustomerid")] 31 | public IActionResult GetByCustomerId(int customerId) 32 | { 33 | var result = _customerCreditCardService.GetByCustomerId(customerId); 34 | if (result.Success) 35 | { 36 | return Ok(result); 37 | } 38 | 39 | return BadRequest(result); 40 | } 41 | 42 | [HttpGet("add")] 43 | public IActionResult Add(CustomerCreditCard customerCreditCard) 44 | { 45 | var result = _customerCreditCardService.Add(customerCreditCard); 46 | if (result.Success) 47 | { 48 | return Ok(result); 49 | } 50 | 51 | return BadRequest(result); 52 | } 53 | 54 | [HttpGet("delete")] 55 | public IActionResult Delete(CustomerCreditCard customerCreditCard) 56 | { 57 | var result = _customerCreditCardService.Delete(customerCreditCard); 58 | if (result.Success) 59 | { 60 | return Ok(result); 61 | } 62 | 63 | return BadRequest(result); 64 | } 65 | 66 | [HttpGet("update")] 67 | public IActionResult Update(CustomerCreditCard customerCreditCard) 68 | { 69 | var result = _customerCreditCardService.Update(customerCreditCard); 70 | if (result.Success) 71 | { 72 | return Ok(result); 73 | } 74 | 75 | return BadRequest(result); 76 | } 77 | 78 | [HttpPost("pay")] 79 | public IActionResult Pay(CustomerCreditCard customerCreditCard) 80 | { 81 | var result = _customerCreditCardService.Pay(customerCreditCard); 82 | if (result.Success==true) 83 | { 84 | return Ok(result); 85 | } 86 | 87 | return BadRequest(result); 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /WebAPI/Controllers/CustomersController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class CustomersController : ControllerBase 15 | { 16 | private ICustomerService _customerService; 17 | 18 | public CustomersController(ICustomerService customerService) 19 | { 20 | _customerService = customerService; 21 | } 22 | 23 | 24 | [HttpGet("getall")] 25 | public IActionResult GetAll() 26 | { 27 | var result = _customerService.GetAll(); 28 | if (result.Success) 29 | { 30 | return Ok(result); 31 | } 32 | return BadRequest(result); 33 | } 34 | [HttpGet("getbyid")] 35 | public IActionResult GetById(int id) 36 | { 37 | var result = _customerService.GetById(id); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result); 43 | } 44 | [HttpPost("add")] 45 | public IActionResult Add(Customer customer) 46 | { 47 | var result = _customerService.Add(customer); 48 | if (result.Success) 49 | { 50 | return Ok(result); 51 | } 52 | return BadRequest(result); 53 | } 54 | [HttpPost("delete")] 55 | public IActionResult Delete(Customer customer) 56 | { 57 | var result = _customerService.Delete(customer); 58 | if (result.Success) 59 | { 60 | return Ok(result); 61 | } 62 | return BadRequest(result); 63 | } 64 | [HttpPost("update")] 65 | public IActionResult Update(Customer customer) 66 | { 67 | var result = _customerService.Update(customer); 68 | if (result.Success) 69 | { 70 | return Ok(result); 71 | } 72 | return BadRequest(result); 73 | } 74 | [HttpGet("getcustomerdetail")] 75 | public IActionResult GetCustomerDetail() 76 | { 77 | var result = _customerService.GetCustomerDetails(); 78 | if (result.Success) 79 | { 80 | return Ok(result); 81 | } 82 | return BadRequest(result); 83 | } 84 | 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /WebAPI/Controllers/RentalController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Microsoft.AspNetCore.Http; 3 | using Microsoft.AspNetCore.Mvc; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | using Entities.Concrete; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class RentalController : ControllerBase 15 | { 16 | IRentalService _rentalService; 17 | 18 | public RentalController(IRentalService rentalService) 19 | { 20 | _rentalService = rentalService; 21 | } 22 | 23 | [HttpGet("GetAll")] 24 | public IActionResult GetAll() 25 | { 26 | var result = _rentalService.GetAll(); 27 | if (result.Success==true) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result); 32 | } 33 | 34 | [HttpGet("GetAllDetails")] 35 | public IActionResult GetDetails() 36 | { 37 | var result = _rentalService.GetAllDetails(); 38 | 39 | if (result.Success) 40 | { 41 | return Ok(result); 42 | } 43 | return BadRequest(result); 44 | 45 | } 46 | 47 | [HttpPost("Add")] 48 | public IActionResult Add(Rental rental) 49 | { 50 | var result = _rentalService.Add(rental); 51 | if (result.Success==true) 52 | { 53 | return Ok(result); 54 | } 55 | 56 | return BadRequest(result); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /WebAPI/Controllers/UsersController.cs: -------------------------------------------------------------------------------- 1 | using Business.Concrete; 2 | using Microsoft.AspNetCore.Http; 3 | using Microsoft.AspNetCore.Mvc; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | using Core.Entities.Concrete; 9 | using Entities.DTOs; 10 | 11 | namespace WebAPI.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | [ApiController] 15 | public class UsersController : ControllerBase 16 | { 17 | IUserService _userService; 18 | 19 | public UsersController(IUserService userService) 20 | { 21 | _userService = userService; 22 | } 23 | 24 | [HttpGet("GetAll")] 25 | public IActionResult GetAll() 26 | { 27 | 28 | var result = _userService.GetAll(); 29 | if (result.Success==true) 30 | { 31 | return Ok(result); 32 | } 33 | 34 | 35 | return BadRequest(result.Message); 36 | } 37 | 38 | [HttpPost("Delete")] 39 | public IActionResult Delete(User user) 40 | { 41 | var result = _userService.Delete(user); 42 | if (result.Success==true) 43 | { 44 | return Ok(result); 45 | } 46 | return BadRequest("geçersiz istek"); 47 | } 48 | 49 | [HttpPost("Update")] 50 | public IActionResult Update(User user) 51 | { 52 | var result = _userService.Update(user); 53 | if (result.Success==true) 54 | { 55 | return Ok(result); 56 | } 57 | return BadRequest(user); 58 | } 59 | 60 | 61 | [HttpGet("email")] 62 | public IActionResult GetByMail(string email) 63 | { 64 | var result = _userService.GetUserByEmail(email); 65 | if (result.Success) 66 | { 67 | return Ok(result); 68 | } 69 | return BadRequest(result); 70 | } 71 | 72 | [HttpPost("updateprofile")] 73 | public IActionResult ProfileUpdate(UserForUpdateDto userForUpdateDto) 74 | { 75 | var result = _userService.EditProfil(userForUpdateDto.User, userForUpdateDto.Password); 76 | if (result.Success) 77 | { 78 | return Ok(result); 79 | } 80 | return BadRequest(result); 81 | } 82 | 83 | [HttpGet("GetClaims")] 84 | public IActionResult GetClaims(int id) 85 | { 86 | var result = _userService.GetClaims(id); 87 | if (result.Success==true) 88 | { 89 | return Ok(result); 90 | } 91 | return BadRequest(result); 92 | } 93 | 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /WebAPI/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace WebAPI.Controllers 9 | { 10 | [ApiController] 11 | [Route("[controller]")] 12 | public class WeatherForecastController : ControllerBase 13 | { 14 | private static readonly string[] Summaries = new[] 15 | { 16 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 17 | }; 18 | 19 | private readonly ILogger _logger; 20 | 21 | public WeatherForecastController(ILogger logger) 22 | { 23 | _logger = logger; 24 | } 25 | 26 | [HttpGet] 27 | public IEnumerable Get() 28 | { 29 | var rng = new Random(); 30 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 31 | { 32 | Date = DateTime.Now.AddDays(index), 33 | TemperatureC = rng.Next(-20, 55), 34 | Summary = Summaries[rng.Next(Summaries.Length)] 35 | }) 36 | .ToArray(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /WebAPI/Middlewares/AuthorizationMiddleware.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Microsoft.AspNetCore.Http; 3 | using Newtonsoft.Json; 4 | using System; 5 | using System.Threading.Tasks; 6 | 7 | namespace WebAPI.Middlewares 8 | { 9 | public class AuthorizationMiddleware 10 | { 11 | private readonly RequestDelegate _next; 12 | // TİPS = readonly amaç sadece değer atama 13 | 14 | public AuthorizationMiddleware( 15 | RequestDelegate next) 16 | { 17 | _next = next; 18 | } 19 | 20 | public async Task InvokeAsync(HttpContext httpContext) 21 | { 22 | if (httpContext.Request.Path.HasValue) 23 | { 24 | var path = httpContext.Request.Path.Value; 25 | // /api/Brand/GetAll 26 | 27 | if (path.StartsWith("/api/auth/", StringComparison.InvariantCultureIgnoreCase)) 28 | { 29 | await _next(httpContext); 30 | return; 31 | } 32 | 33 | if (httpContext.User.Identity.IsAuthenticated && httpContext.User.IsInRole(path)) 34 | { 35 | await _next(httpContext); 36 | return; 37 | } 38 | } 39 | httpContext.Response.StatusCode = 403; 40 | 41 | httpContext.Response.ContentType = "application/json"; 42 | await httpContext.Response.WriteAsync(JsonConvert.SerializeObject(new ErrorResult("Erişim Engellendi"))); 43 | 44 | //httpContext.Response.ContentType = "text/html"; 45 | //await httpContext.Response.WriteAsync("erişim engellendi"); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /WebAPI/Middlewares/AuthorizationMiddlewareExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace WebAPI.Middlewares 8 | { 9 | public static class AuthorizationMiddlewareExtensions 10 | { 11 | public static void ConfigreAuthorization(this IApplicationBuilder app) 12 | { 13 | app.UseMiddleware(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /WebAPI/Program.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Extensions.DependencyInjection; 3 | using Business.DependencyResolvers.Autofac; 4 | using Microsoft.AspNetCore.Hosting; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.Extensions.Hosting; 7 | using Microsoft.Extensions.Logging; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | using System.Threading.Tasks; 12 | 13 | namespace WebAPI 14 | { 15 | public class Program 16 | { 17 | public static void Main(string[] args) 18 | { 19 | CreateHostBuilder(args).Build().Run(); 20 | } 21 | 22 | public static IHostBuilder CreateHostBuilder(string[] args) => 23 | Host.CreateDefaultBuilder(args) 24 | .UseServiceProviderFactory(new AutofacServiceProviderFactory()) 25 | .ConfigureContainer(builder => 26 | { 27 | builder.RegisterModule(new AutofacBusinessModule()); 28 | }) 29 | .ConfigureWebHostDefaults(webBuilder => 30 | { 31 | webBuilder.UseStartup(); 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /WebAPI/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:30864", 8 | "sslPort": 44345 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | 18 | "ASPNETCORE_ENVIRONMENT": "Development" 19 | } 20 | }, 21 | "WebAPI": { 22 | "commandName": "Project", 23 | "dotnetRunMessages": "true", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 27 | "environmentVariables": { 28 | "ASPNETCORE_ENVIRONMENT": "Development" 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /WebAPI/Startup.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Concrete; 3 | using Core.DependencyResolvers; 4 | using Core.Extensions; 5 | using Core.Utilities.IoC; 6 | using Core.Utilities.Security.Encryption; 7 | using Core.Utilities.Security.JWT; 8 | using DataAccess.Abstract; 9 | using DataAccess.Concrete.EntityFramework; 10 | using Microsoft.AspNetCore.Authentication.JwtBearer; 11 | using Microsoft.AspNetCore.Authorization; 12 | using Microsoft.AspNetCore.Builder; 13 | using Microsoft.AspNetCore.Hosting; 14 | using Microsoft.AspNetCore.Http; 15 | using Microsoft.AspNetCore.HttpsPolicy; 16 | using Microsoft.AspNetCore.Mvc; 17 | using Microsoft.Extensions.Configuration; 18 | using Microsoft.Extensions.DependencyInjection; 19 | using Microsoft.Extensions.DependencyInjection.Extensions; 20 | using Microsoft.Extensions.Hosting; 21 | using Microsoft.Extensions.Logging; 22 | using Microsoft.IdentityModel.Tokens; 23 | using Microsoft.OpenApi.Models; 24 | using System; 25 | using System.Collections.Generic; 26 | using System.Linq; 27 | using System.Threading.Tasks; 28 | using WebAPI.Middlewares; 29 | 30 | namespace WebAPI 31 | { 32 | public class Startup 33 | { 34 | public Startup(IConfiguration configuration) 35 | { 36 | Configuration = configuration; 37 | } 38 | 39 | public IConfiguration Configuration { get; } 40 | 41 | // This method gets called by the runtime. Use this method to add services to the container. 42 | public void ConfigureServices(IServiceCollection services) 43 | { 44 | 45 | services.AddControllers(); 46 | services.AddSwaggerGen(c => 47 | { 48 | c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebAPI", Version = "v1" }); 49 | }); 50 | services.AddCors(); 51 | 52 | var tokenOptions = Configuration.GetSection("TokenOptions").Get(); 53 | 54 | services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) 55 | .AddJwtBearer(options => 56 | { 57 | options.TokenValidationParameters = new TokenValidationParameters 58 | { 59 | ValidateIssuer = true, 60 | ValidateAudience = true, 61 | ValidateLifetime = true, 62 | ValidIssuer = tokenOptions.Issuer, 63 | ValidAudience = tokenOptions.Audience, 64 | ValidateIssuerSigningKey = true, 65 | IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) 66 | }; 67 | }); 68 | services.AddOpendecyResolvers(new ICoreModule[] { 69 | new CoreModule() 70 | }); 71 | } 72 | 73 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 74 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 75 | { 76 | if (env.IsDevelopment()) 77 | { 78 | app.UseDeveloperExceptionPage(); 79 | app.UseSwagger(); 80 | app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebAPI v1")); 81 | } 82 | app.ConfigureCustomExceptionMiddleware(); 83 | 84 | 85 | app.UseCors(builder => builder.WithOrigins("http://localhost:4200/").AllowAnyHeader().AllowAnyOrigin()); 86 | app.UseStaticFiles(); 87 | app.UseHttpsRedirection(); 88 | 89 | app.UseRouting(); 90 | //deneme 91 | app.UseAuthentication(); 92 | //deneme 93 | 94 | app.UseAuthorization(); 95 | app.ConfigreAuthorization(); 96 | 97 | app.UseEndpoints(endpoints => 98 | { 99 | endpoints.MapControllers(); 100 | }); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /WebAPI/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebAPI 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WebAPI/WebAPI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /WebAPI/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /WebAPI/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "TokenOptions": { 3 | "Audience": "umit@umit.com", 4 | "Issuer": "umit@umit.com", 5 | "AccessTokenExpiration": 5000, 6 | "SecurityKey": "mysupersecretkeymysupersecretkey" 7 | }, 8 | "Logging": { 9 | "LogLevel": { 10 | "Default": "Information", 11 | "Microsoft": "Warning", 12 | "Microsoft.Hosting.Lifetime": "Information" 13 | } 14 | }, 15 | "AllowedHosts": "*" 16 | } 17 | -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/330f6c7f-4e58-462b-bdd7-adf91fceb72f.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/umitdogan33/ReCapProject/9e5d5e9fb019d9e6a970df1ca99f3f5803714909/WebAPI/wwwroot/Images/330f6c7f-4e58-462b-bdd7-adf91fceb72f.png -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/3fe22022-24ee-4b19-a6d5-6153d52754c4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/umitdogan33/ReCapProject/9e5d5e9fb019d9e6a970df1ca99f3f5803714909/WebAPI/wwwroot/Images/3fe22022-24ee-4b19-a6d5-6153d52754c4.jpg --------------------------------------------------------------------------------