├── .gitattributes ├── .gitignore ├── Business ├── Abstract │ ├── IAuthService.cs │ ├── IBrandService.cs │ ├── ICarImageService.cs │ ├── ICarService.cs │ ├── IColorService.cs │ ├── ICreditCardService.cs │ ├── ICustomerService.cs │ ├── IFakeFindexService.cs │ ├── IPaymentService.cs │ ├── IRentalService.cs │ └── IUserService.cs ├── Business.csproj ├── BusinessAspect │ └── Autofac │ │ └── SecuredOperation.cs ├── Concrete │ ├── AuthManager.cs │ ├── BrandManager.cs │ ├── CarImageManager.cs │ ├── CarManager.cs │ ├── ColorManager.cs │ ├── CreditCardManager.cs │ ├── CustomerManager.cs │ ├── FakeFindexManager.cs │ ├── PaymentManager.cs │ ├── RentalManager.cs │ └── UserManager.cs ├── Constant │ └── Messages.cs ├── DependencyResolvers │ └── Autofac │ │ └── AutofacBusinessModule.cs └── ValidationRules │ └── FluentValidation │ ├── BrandValidator.cs │ ├── CarImageValidator.cs │ ├── CarValidator.cs │ ├── ColorValidator.cs │ ├── CustomerValidator.cs │ ├── RentalValidator.cs │ └── UserValidator.cs ├── ConsoleUI ├── ConsoleUI.csproj └── Program.cs ├── Core ├── Aspect │ └── Autofac │ │ ├── Caching │ │ ├── CacheAspect.cs │ │ └── CacheRemoveAspect.cs │ │ ├── Performance │ │ └── PerformanceAspect.cs │ │ ├── Transaction │ │ └── TransactionScopeAspect.cs │ │ └── Validation │ │ └── ValidationAspect.cs ├── Core.csproj ├── CrossCuttingConcerns │ ├── Caching │ │ ├── ICacheManager.cs │ │ └── Microsoft │ │ │ └── MemoryCacheManager.cs │ └── Validation │ │ └── ValidationTool.cs ├── DataAccess │ ├── EntityFramework │ │ └── EfEntityRepositoryBase.cs │ └── IEntityRepository.cs ├── DependencyResolvers │ └── CoreModule.cs ├── Entities │ ├── Concrete │ │ ├── OperationClaim.cs │ │ ├── User.cs │ │ └── UserOperationClaim.cs │ ├── IDto.cs │ └── IEntity.cs ├── Extensions │ ├── ClaimExtensions.cs │ ├── ClaimsPrincipalExtensions.cs │ ├── ErrorDetails.cs │ ├── ExceptionMiddleware.cs │ ├── ExceptionMiddlewareExtensions.cs │ └── ServiceCollectionExtensions.cs └── Utilities │ ├── Business │ └── BusinessRules.cs │ ├── Helpers │ └── FileHelper.cs │ ├── Interceptors │ ├── AspectInterceptorSelector.cs │ ├── MethodInterception.cs │ └── MethodInterceptionBaseAttribute.cs │ ├── IoC │ ├── ICoreModule.cs │ └── ServiceTool.cs │ ├── Results │ ├── DataResult.cs │ ├── ErrorDataResult.cs │ ├── ErrorResult.cs │ ├── IDataResult.cs │ ├── IResult.cs │ ├── Result.cs │ ├── SuccessDataResult.cs │ └── SuccessResult.cs │ └── Security │ ├── Encryption │ ├── SecurityKeyHelper.cs │ └── SigningCredentialsHelper.cs │ ├── Hashing │ └── HashingHelper.cs │ └── Jwt │ ├── AccessToken.cs │ ├── ITokenHelper.cs │ ├── JwtHelper.cs │ └── TokenOptions.cs ├── DataAccess ├── Abstract │ ├── IBrandDal.cs │ ├── ICarDal.cs │ ├── ICarImageDal.cs │ ├── IColorDal.cs │ ├── ICreditCardDal.cs │ ├── ICustomerDal.cs │ ├── IRentalDal.cs │ └── IUserDal.cs ├── Concrete │ ├── EntityFramework │ │ ├── EFUserDal.cs │ │ ├── EfBrandDal.cs │ │ ├── EfCarDal.cs │ │ ├── EfCarImageDal.cs │ │ ├── EfColorDal.cs │ │ ├── EfCreditCard.cs │ │ ├── EfCustomerDal.cs │ │ ├── EfRentalDal.cs │ │ └── ReCapContext.cs │ └── InMemory │ │ └── InMemoryCarDal.cs └── DataAccess.csproj ├── Entities ├── Concrete │ ├── Brand.cs │ ├── Car.cs │ ├── CarImage.cs │ ├── Color.cs │ ├── CreditCard.cs │ ├── Customer.cs │ └── Rental.cs ├── DTOs │ ├── CarDetailsDto.cs │ ├── RentalDetailsDto.cs │ ├── UserEditedDto.cs │ ├── UserForLoginDto.cs │ └── UserForRegisterDto.cs └── Entities.csproj ├── ReCapProject.sln └── WebAPI ├── Controllers ├── AuthController.cs ├── BrandsController.cs ├── CarImagesController.cs ├── CarsController.cs ├── ColorsController.cs ├── CreditCardsController.cs ├── CustomersController.cs ├── PaymentController.cs ├── RentalsController.cs ├── UsersController.cs └── WeatherForecastController.cs ├── Program.cs ├── Properties └── launchSettings.json ├── Startup.cs ├── WeatherForecast.cs ├── WebAPI.csproj ├── appsettings.Development.json ├── appsettings.json ├── libman.json └── wwwroot └── CarImages ├── 0ebac2f9-8b50-48ba-b817-d576495dbf3e.webp ├── 0fbef1e4-4dbd-4176-b943-d5bbe695f42c.webp ├── 17fe3c1c-f757-4eda-839f-aff9c1fbfc7a.png ├── 18c07ed5-98da-4139-9f1d-957f8bbef56e.jpg ├── 1d2ed58c-ff94-44e5-a3ae-0627fa7078c3.jpg ├── 40ac70c9-586b-4d64-b64e-612895fe1225.jpg ├── 492e85af-e9bc-48c2-bb4b-e13d2a0b34cc.jpg ├── 518dcefa-3e80-4fc5-912b-9fc94290948e.jpg ├── 5928dc1d-41dd-4869-b679-9afe95bedad1.jpg ├── 5c5710fe-34ca-4d0c-ae62-da0988bb1f31.jpg ├── 641c8643-4e04-4be4-95a2-062dda3632c5.jpeg ├── b07161a2-4a2f-4595-b95c-855f081b02ed.jpg ├── b2b83108-0e5f-4c3d-8158-d7e18c68f5de.jpg ├── be025d20-de97-477e-866d-1e8c3e87ddec.jpg ├── c5a9de4f-2d3c-4d77-be3a-f88ff2000421.jpg ├── cb7ad995-8f8d-4a15-bb0b-fc4e0f964055.jpg ├── d3a66c74-7ec2-4249-84ce-ece8bb1faf25.jpg ├── d4d46fe1-7eac-4744-ac5a-d8671768b6fe.jpg ├── e67a40cd-92fd-4dfc-a059-29ce018e0f82.jpg ├── eb0ea112-a333-4c9a-8e8c-671cd20bceaf.jpg ├── f8454b08-0ba4-440c-bf78-b6d20ea916be.jpg ├── fd320c24-c3b4-46cd-ab82-42cd628cd67a.jpg └── simge.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 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /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 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace Business.Abstract 10 | { 11 | public interface IAuthService 12 | { 13 | IDataResult Register(UserForRegisterDto userForRegisterDto); 14 | IDataResult Login(UserForLoginDto userForLoginDto); 15 | IResult UserExists(string email); 16 | IDataResult CreateAccessToken(User user); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Business/Abstract/IBrandService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface IBrandService 10 | { 11 | IResult Add(Brand brand); 12 | IResult Delete(Brand brand); 13 | IResult Update(Brand brand); 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int id); //idye gore marka getirme 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Business/Abstract/ICarImageService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace Business.Abstract 9 | { 10 | public interface ICarImageService 11 | { 12 | IResult Add(IFormFile file,CarImage carImage); 13 | IResult Delete(CarImage carImage); 14 | IResult Update(IFormFile file, CarImage carImage); 15 | IDataResult> GetAll(); 16 | IDataResult GetById(int id); 17 | IDataResult> GetPhotosByCarId(int carId); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Business/Abstract/ICarService.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 ICarService 11 | { 12 | IResult Add(Car car); 13 | IResult Delete(Car car); 14 | IResult Update(Car car); 15 | IDataResult> GetAll(); 16 | IDataResult GetById(int id); //idye gore arac getirme 17 | IDataResult> GetCarsByBrandId(int brandId); //brandIdye gore aracları getirme 18 | IDataResult> GetCarsByColorId(int colorId); //colorIdye gore aracları getirme 19 | IDataResult> GetCarsDetails(); 20 | IDataResult> GetCarsDetailByBrandId(int brandId); 21 | IDataResult> GetCarsDetailByColorId(int colorId); 22 | IDataResult GetCarDetailsById(int carId); 23 | IDataResult> GetCarsDetailByColorIdAndBrandId(int colorId, int brandId); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Business/Abstract/IColorService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface IColorService 10 | { 11 | IResult Add(Color color); 12 | IResult Delete(Color color); 13 | IResult Update(Color color); 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int id); //idye gore renk getirme 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Business/Abstract/ICreditCardService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface ICreditCardService 10 | { 11 | IResult Add(CreditCard creditCard); 12 | IResult Delete(CreditCard creditCard); 13 | IResult Update(CreditCard creditCard); 14 | IDataResult GetByCustomerId(int customerId); 15 | IDataResult GetByNumber(string cardNumber); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /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 | 7 | namespace Business.Abstract 8 | { 9 | public interface ICustomerService 10 | { 11 | IResult Add(Customer customer); 12 | IResult Delete(Customer customer); 13 | IResult Update(Customer customer); 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int id); 16 | IDataResult GetByUserId(int id); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Business/Abstract/IFakeFindexService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Business.Abstract 6 | { 7 | public interface IFakeFindexService 8 | { 9 | bool CheckFindex(int carMinFindex, int customerFindexScore); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Business/Abstract/IPaymentService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface IPaymentService 10 | { 11 | IResult Payment(CreditCard creditCard); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /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 | IResult Add(Rental rental); 13 | IResult Delete(Rental rental); 14 | IResult Update(Rental rental); 15 | IDataResult> GetAll(); 16 | IDataResult> GetRentalDetails(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Business/Abstract/IUserService.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Core.Utilities.Results; 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 IUserService 11 | { 12 | IResult Add(User user); 13 | IResult Delete(User user); 14 | IResult Update(User user); 15 | IResult EditProfile(UserEditedDto user); 16 | IDataResult> GetAll(); 17 | IDataResult> GetClaims(User user); 18 | IDataResult GetUserByEmail(string email); 19 | IDataResult GetUserDtoByEmail(string email); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Business/Business.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Business/BusinessAspect/Autofac/SecuredOperation.cs: -------------------------------------------------------------------------------- 1 | using Business.Constant; 2 | using Castle.DynamicProxy; 3 | using Core.Extensions; 4 | using Core.Utilities.Interceptors; 5 | using Core.Utilities.IoC; 6 | using Microsoft.AspNetCore.Http; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Text; 11 | 12 | namespace Business.BusinessAspect.Autofac 13 | { 14 | public class SecuredOperation : MethodInterception 15 | { 16 | string[] _roles; 17 | IHttpContextAccessor _httpContextAccessor; 18 | 19 | public SecuredOperation(string roles) 20 | { 21 | _roles = roles.Split(','); 22 | _httpContextAccessor = ServiceTool.ServiceProvider.GetService(); 23 | } 24 | 25 | protected override void OnBefore(IInvocation invocation) 26 | { 27 | var roleClaims = _httpContextAccessor.HttpContext.User.ClaimRoles(); 28 | foreach (var role in _roles) 29 | { 30 | if (roleClaims.Contains(role)) 31 | { 32 | return; 33 | } 34 | } 35 | throw new Exception(Messages.NotBeAuth); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Business/Concrete/AuthManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constant; 3 | using Core.Entities.Concrete; 4 | using Core.Utilities.Results; 5 | using Core.Utilities.Security.Hashing; 6 | using Core.Utilities.Security.Jwt; 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 | IUserService _userService; 17 | ITokenHelper _tokenHelper; 18 | public AuthManager(IUserService userService, ITokenHelper tokenHelper) 19 | { 20 | _userService = userService; 21 | _tokenHelper = tokenHelper; 22 | } 23 | 24 | public IResult UserExists(string email) 25 | { 26 | var result = _userService.GetUserByEmail(email).Data; 27 | if (result != null) 28 | { 29 | return new ErrorResult(Messages.UserExists); 30 | } 31 | return new SuccessResult(); 32 | } 33 | 34 | public IDataResult CreateAccessToken(User user) 35 | { 36 | var claims = _userService.GetClaims(user).Data; 37 | var token = _tokenHelper.CreateToken(user,claims); 38 | 39 | return new SuccessDataResult(token); 40 | 41 | } 42 | 43 | public IDataResult Login(UserForLoginDto userForLoginDto) 44 | { 45 | var user = _userService.GetUserByEmail(userForLoginDto.Email).Data; 46 | if (user==null) 47 | { 48 | return new ErrorDataResult(Messages.UserNotFound); 49 | } 50 | if (!HashingHelper.VerifyPassword(userForLoginDto.Password,user.PasswordHash,user.PasswordSalt)) 51 | { 52 | return new ErrorDataResult(Messages.BadPassword); 53 | } 54 | return new SuccessDataResult(user); 55 | } 56 | 57 | public IDataResult Register(UserForRegisterDto userForRegisterDto) 58 | { 59 | byte[] passwordHash; 60 | byte[] passwordSalt; 61 | 62 | HashingHelper.CreatePasswordHash(userForRegisterDto.Password, out passwordHash, out passwordSalt); 63 | 64 | var user = new User() 65 | { 66 | FirstName = userForRegisterDto.FirstName, 67 | LastName = userForRegisterDto.LastName, 68 | Email = userForRegisterDto.Email, 69 | PasswordHash = passwordHash, 70 | PasswordSalt = passwordSalt, 71 | Status = true 72 | }; 73 | _userService.Add(user); 74 | return new SuccessDataResult(user); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Business/Concrete/BrandManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.BusinessAspect.Autofac; 3 | using Business.Constant; 4 | using Business.ValidationRules.FluentValidation; 5 | using Core.Aspect.Autofac.Caching; 6 | using Core.Aspect.Autofac.Validation; 7 | using Core.Aspects.Autofac.Caching; 8 | using Core.Utilities.Results; 9 | using DataAccess.Abstract; 10 | using Entities.Concrete; 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Text; 14 | 15 | namespace Business.Concrete 16 | { 17 | public class BrandManager : IBrandService 18 | { 19 | IBrandDal _brandDal; 20 | public BrandManager(IBrandDal brandDal) 21 | { 22 | _brandDal = brandDal; 23 | } 24 | 25 | [SecuredOperation("admin,brand.add")] 26 | [CacheRemoveAspect("IBrandService.Get")] 27 | [ValidationAspect(typeof(BrandValidator))] 28 | public IResult Add(Brand brand) 29 | { 30 | _brandDal.Add(brand); 31 | return new SuccessResult(Messages.BrandAdded); 32 | } 33 | 34 | [CacheRemoveAspect("IBrandService.Get")] 35 | public IResult Delete(Brand brand) 36 | { 37 | _brandDal.Delete(brand); 38 | return new SuccessResult(Messages.BrandDeleted); 39 | } 40 | 41 | [CacheAspect] 42 | public IDataResult> GetAll() 43 | { 44 | return new SuccessDataResult>(_brandDal.GetAll(),Messages.BrandListed); 45 | } 46 | 47 | public IDataResult GetById(int id) 48 | { 49 | return new SuccessDataResult(_brandDal.Get(b => b.BrandId == id),Messages.BrandById); 50 | } 51 | 52 | [CacheRemoveAspect("IBrandService.Get")] 53 | public IResult Update(Brand brand) 54 | { 55 | _brandDal.Update(brand); 56 | return new SuccessResult(Messages.BrandUpdated); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Business/Concrete/CarImageManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.BusinessAspect.Autofac; 3 | using Business.ValidationRules.FluentValidation; 4 | using Core.Aspect.Autofac.Caching; 5 | using Core.Aspect.Autofac.Validation; 6 | using Core.Aspects.Autofac.Caching; 7 | using Core.Utilities.Business; 8 | using Core.Utilities.Helpers; 9 | using Core.Utilities.Results; 10 | using DataAccess.Abstract; 11 | using Entities.Concrete; 12 | using Microsoft.AspNetCore.Http; 13 | using System; 14 | using System.Collections.Generic; 15 | using System.IO; 16 | using System.Linq; 17 | using System.Text; 18 | 19 | namespace Business.Concrete 20 | { 21 | public class CarImageManager : ICarImageService 22 | { 23 | ICarImageDal _carImageDal; 24 | public CarImageManager(ICarImageDal carImageDal) 25 | { 26 | _carImageDal = carImageDal; 27 | } 28 | [CacheRemoveAspect("ICarImageService.Get")] 29 | //[SecuredOperation("admin,carimage.add")] 30 | [ValidationAspect(typeof(CarImageValidator))] 31 | public IResult Add(IFormFile file, CarImage carImage) 32 | { 33 | var result = BusinessRules.Run(CheckIfMaxPhotoLimit(carImage.CarId)); 34 | if (result !=null) 35 | { 36 | return result; 37 | } 38 | carImage.ImagePath = FileHelper.Add(file); 39 | carImage.Date = DateTime.Now; 40 | _carImageDal.Add(carImage); 41 | return new SuccessResult(); 42 | } 43 | 44 | [CacheRemoveAspect("ICarImageService.Get")] 45 | public IResult Delete(CarImage carImage) 46 | { 47 | FileHelper.Delete(carImage.ImagePath); 48 | _carImageDal.Delete(carImage); 49 | return new SuccessResult(); 50 | } 51 | 52 | public IDataResult GetById(int id) 53 | { 54 | return new SuccessDataResult(_carImageDal.Get(c => c.Id == id)); 55 | } 56 | 57 | [CacheAspect] 58 | public IDataResult> GetAll() 59 | { 60 | return new SuccessDataResult>(_carImageDal.GetAll()); 61 | } 62 | 63 | [CacheRemoveAspect("ICarImageService.Get")] 64 | [ValidationAspect(typeof(CarImageValidator))] 65 | public IResult Update(IFormFile file, CarImage carImage) 66 | { 67 | var result = BusinessRules.Run(CheckIfMaxPhotoLimit(carImage.CarId)); 68 | if (result != null) 69 | { 70 | return result; 71 | } 72 | 73 | carImage.ImagePath = FileHelper.Update(carImage.ImagePath, file); 74 | carImage.Date = DateTime.Now; 75 | _carImageDal.Update(carImage); 76 | return new SuccessResult(); 77 | } 78 | [CacheAspect] 79 | public IDataResult> GetPhotosByCarId(int carId) 80 | { 81 | return new SuccessDataResult>(CheckIfCarPhotoIsNull(carId)); 82 | } 83 | 84 | private IResult CheckIfMaxPhotoLimit(int carId) 85 | { 86 | var result = _carImageDal.GetAll(c => c.CarId == carId); 87 | 88 | if (result.Count<5) 89 | { 90 | return new SuccessResult(); 91 | } 92 | return new ErrorResult(); 93 | } 94 | private List CheckIfCarPhotoIsNull(int carId) 95 | { 96 | var defaultPath = @"simge.jpg"; 97 | var result = _carImageDal.GetAll(c => c.CarId == carId); 98 | if (!result.Any()) 99 | { 100 | return new List { new CarImage() { CarId = carId, Date = DateTime.Now, ImagePath = defaultPath } }; 101 | } 102 | return result; 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Business/Concrete/CarManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | using System.Linq; 8 | using System.Linq.Expressions; 9 | using Entities.DTOs; 10 | using Core.Utilities.Results; 11 | using Business.Constant; 12 | using Core.CrossCuttingConcerns.Validation; 13 | using Business.ValidationRules.FluentValidation; 14 | using Core.Aspect.Autofac.Validation; 15 | using Business.BusinessAspect.Autofac; 16 | using Core.Aspect.Autofac.Caching; 17 | using Core.Aspects.Autofac.Caching; 18 | using Core.Utilities.Business; 19 | 20 | namespace Business.Concrete 21 | { 22 | public class CarManager : ICarService 23 | { 24 | ICarDal _carDal; 25 | 26 | public CarManager(ICarDal carDal) 27 | { 28 | _carDal = carDal; 29 | } 30 | 31 | [ValidationAspect(typeof(CarValidator))] 32 | [SecuredOperation("admin,car.add")] 33 | [CacheRemoveAspect("ICarService.Get")] 34 | public IResult Add(Car car) 35 | { 36 | var result = BusinessRules.Run(CheckCountOfSameCarBrand(car.BrandId)); 37 | if (result != null) 38 | { 39 | return result; 40 | } 41 | _carDal.Add(car); 42 | return new SuccessResult(Messages.CarAdded); 43 | } 44 | 45 | [SecuredOperation("admin,car.delete")] 46 | [CacheRemoveAspect("ICarService.Get")] 47 | public IResult Delete(Car car) 48 | { 49 | _carDal.Delete(car); 50 | return new SuccessResult(Messages.CarDeleted); 51 | } 52 | 53 | [CacheAspect] 54 | [SecuredOperation("admin,car.getall")] 55 | public IDataResult> GetAll() 56 | { 57 | return new SuccessDataResult>(_carDal.GetAll(),Messages.CarListed); 58 | } 59 | 60 | public IDataResult GetById(int id) 61 | { 62 | return new SuccessDataResult(_carDal.Get(c=>c.CarId == id),Messages.CarById); 63 | } 64 | 65 | public IDataResult> GetCarsByBrandId(int brandId) 66 | { 67 | return new SuccessDataResult>(_carDal.GetAll(b => b.BrandId ==brandId));//brandIdsi gonderilen idye eşit olan araclar 68 | } 69 | 70 | public IDataResult> GetCarsByColorId(int colorId) 71 | { 72 | return new SuccessDataResult>(_carDal.GetAll(c => c.ColorId == colorId));//colorIdsi gonderilen idye eşit olan araclar 73 | } 74 | 75 | [CacheAspect] 76 | public IDataResult> GetCarsDetails() //dto olarak olusturdugumuz joinden arabanın marka adı ve renk adı da gelecek. 77 | { 78 | return new SuccessDataResult>(_carDal.GetCarsDetails()); 79 | } 80 | 81 | public IDataResult> GetCarsDetailByBrandId(int brandId) 82 | { 83 | return new SuccessDataResult>(_carDal.GetCarsDetailByBrandId(brandId)); 84 | } 85 | 86 | public IDataResult> GetCarsDetailByColorId(int colorId) 87 | { 88 | return new SuccessDataResult>(_carDal.GetCarsDetailByColorId(colorId)); 89 | } 90 | 91 | [ValidationAspect(typeof(CarValidator))] 92 | [SecuredOperation("admin,car.update")] 93 | [CacheRemoveAspect("ICarService.Get")] 94 | public IResult Update(Car car) 95 | { 96 | _carDal.Update(car); 97 | return new SuccessResult(Messages.CarUpdated); 98 | } 99 | public IDataResult GetCarDetailsById(int carId) 100 | { 101 | return new SuccessDataResult(_carDal.GetCarDetailsById(carId)); 102 | } 103 | 104 | public IDataResult> GetCarsDetailByColorIdAndBrandId(int colorId, int brandId) 105 | { 106 | return new SuccessDataResult>(_carDal.GetCarsDetailByColorIdAndBrandId(colorId, brandId)); 107 | } 108 | 109 | private IResult CheckCountOfSameCarBrand(int brandId) 110 | { 111 | var result = _carDal.GetAll(c => c.BrandId == brandId).Count; 112 | if (result>10) 113 | { 114 | return new ErrorResult(Messages.SameBrandCarsCountExceeded); 115 | } 116 | return new SuccessResult(); 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /Business/Concrete/ColorManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.BusinessAspect.Autofac; 3 | using Business.Constant; 4 | using Business.ValidationRules.FluentValidation; 5 | using Core.Aspect.Autofac.Caching; 6 | using Core.Aspect.Autofac.Validation; 7 | using Core.Aspects.Autofac.Caching; 8 | using Core.Utilities.Results; 9 | using DataAccess.Abstract; 10 | using Entities.Concrete; 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Text; 14 | 15 | namespace Business.Concrete 16 | { 17 | //SuccessDataResult> 18 | public class ColorManager : IColorService 19 | { 20 | IColorDal _colorDal; 21 | 22 | public ColorManager(IColorDal colorDal) 23 | { 24 | _colorDal = colorDal; 25 | } 26 | 27 | [SecuredOperation("admin,color.add")] 28 | [CacheRemoveAspect("IColorService.Get")] 29 | [ValidationAspect(typeof(ColorValidator))] 30 | public IResult Add(Color color) 31 | { 32 | _colorDal.Add(color); 33 | return new SuccessResult(Messages.ColorAdded); 34 | } 35 | 36 | [CacheRemoveAspect("IColorService.Get")] 37 | public IResult Delete(Color color) 38 | { 39 | _colorDal.Delete(color); 40 | return new SuccessResult(Messages.ColorDeleted); 41 | } 42 | 43 | [CacheAspect] 44 | public IDataResult> GetAll() 45 | { 46 | return new SuccessDataResult>(_colorDal.GetAll(),Messages.ColorListed); 47 | } 48 | 49 | public IDataResult GetById(int id) 50 | { 51 | return new SuccessDataResult(_colorDal.Get(c => c.ColorId == id),Messages.ColorById); 52 | } 53 | 54 | [CacheRemoveAspect("IColorService.Get")] 55 | [ValidationAspect(typeof(ColorValidator))] 56 | public IResult Update(Color color) 57 | { 58 | _colorDal.Update(color); 59 | return new SuccessResult(Messages.ColorUpdated); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Business/Concrete/CreditCardManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constant; 3 | using Core.Utilities.Business; 4 | using Core.Utilities.Results; 5 | using DataAccess.Abstract; 6 | using Entities.Concrete; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | 11 | namespace Business.Concrete 12 | { 13 | public class CreditCardManager:ICreditCardService 14 | { 15 | ICreditCardDal _creditCardDal; 16 | public CreditCardManager(ICreditCardDal creditCardDal) 17 | { 18 | _creditCardDal = creditCardDal; 19 | } 20 | 21 | public IResult Add(CreditCard creditCard) 22 | { 23 | var result = BusinessRules.Run(CheckCreditCardExist(creditCard)); 24 | if (result != null) 25 | { 26 | return result; 27 | } 28 | 29 | creditCard.Amount = 1000; 30 | _creditCardDal.Add(creditCard); 31 | return new SuccessResult(Messages.CreditCardAdded); 32 | } 33 | 34 | public IResult Delete(CreditCard creditCard) 35 | { 36 | _creditCardDal.Delete(creditCard); 37 | return new SuccessResult(Messages.CreditCarDeleted); 38 | } 39 | 40 | public IDataResult GetByCustomerId(int customerId) 41 | { 42 | return new SuccessDataResult(_creditCardDal.Get(c => c.CustomerId == customerId)); 43 | } 44 | 45 | public IDataResult GetByNumber(string cardNumber) 46 | { 47 | return new SuccessDataResult(_creditCardDal.Get(c => c.CardNumber == cardNumber)); 48 | } 49 | 50 | private IResult CheckCreditCardExist(CreditCard creditCard) 51 | { 52 | var result = _creditCardDal.Get( 53 | c => c.CardNumber == creditCard.CardNumber && 54 | c.CVV == creditCard.CVV && 55 | c.ExpirationDate == creditCard.ExpirationDate && 56 | c.FullName == creditCard.FullName); 57 | 58 | if (result == null) 59 | { 60 | return new SuccessResult(); 61 | } 62 | return new ErrorResult(); 63 | } 64 | 65 | public IResult Update(CreditCard creditCard) 66 | { 67 | _creditCardDal.Update(creditCard); 68 | return new SuccessResult(Messages.CreditCardUpdated); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Business/Concrete/CustomerManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Core.Utilities.Results; 3 | using DataAccess.Abstract; 4 | using Entities.Concrete; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace Business.Concrete 10 | { 11 | public class CustomerManager : ICustomerService 12 | { 13 | ICustomerDal _customerDal; 14 | public CustomerManager(ICustomerDal customerDal) 15 | { 16 | _customerDal = customerDal; 17 | } 18 | public IResult Add(Customer customer) 19 | { 20 | _customerDal.Add(customer); 21 | return new SuccessResult(); 22 | } 23 | 24 | public IResult Delete(Customer customer) 25 | { 26 | _customerDal.Delete(customer); 27 | return new SuccessResult(); 28 | } 29 | 30 | public IDataResult> GetAll() 31 | { 32 | return new SuccessDataResult>(_customerDal.GetAll()); 33 | } 34 | 35 | public IDataResult GetById(int id) 36 | { 37 | return new SuccessDataResult(_customerDal.Get(c=>c.Id==id)); 38 | } 39 | 40 | public IDataResult GetByUserId(int id) 41 | { 42 | return new SuccessDataResult(_customerDal.Get(c => c.UserId == id)); 43 | } 44 | 45 | public IResult Update(Customer customer) 46 | { 47 | _customerDal.Update(customer); 48 | return new SuccessResult(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Business/Concrete/FakeFindexManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Business.Concrete 7 | { 8 | public class FakeFindexManager : IFakeFindexService 9 | { 10 | public bool CheckFindex(int carMinFindex, int customerFindexScore) 11 | { 12 | return carMinFindex <= customerFindexScore ? true : false; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Business/Concrete/PaymentManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 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 class PaymentManager : IPaymentService 11 | { 12 | ICreditCardService _creditCardService; 13 | public PaymentManager(ICreditCardService creditCardService) 14 | { 15 | _creditCardService = creditCardService; 16 | } 17 | 18 | public IResult Payment(CreditCard creditCard) 19 | { 20 | var _creditCard = _creditCardService.GetByNumber(creditCard.CardNumber).Data; 21 | var amount = _creditCard.Amount; 22 | 23 | if(amount < creditCard.Amount) 24 | { 25 | return new ErrorResult(); 26 | } 27 | else 28 | { 29 | _creditCard.Amount = amount - creditCard.Amount; 30 | _creditCardService.Update(_creditCard); 31 | return new SuccessResult(); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Business/Concrete/RentalManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.BusinessAspect.Autofac; 3 | using Business.Constant; 4 | using Business.ValidationRules.FluentValidation; 5 | using Core.Aspect.Autofac.Validation; 6 | using Core.Utilities.Business; 7 | using Core.Utilities.Results; 8 | using DataAccess.Abstract; 9 | using Entities.Concrete; 10 | using Entities.DTOs; 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Linq; 14 | using System.Text; 15 | 16 | namespace Business.Concrete 17 | { 18 | public class RentalManager : IRentalService 19 | { 20 | IRentalDal _rentalDal; 21 | ICustomerService _customerService; 22 | ICarService _carService; 23 | IFakeFindexService _fakeFindexService; 24 | 25 | public RentalManager(IRentalDal rentalDal, ICustomerService customerService, ICarService carService, IFakeFindexService fakeFindexService) 26 | { 27 | _rentalDal = rentalDal; 28 | 29 | _customerService = customerService; 30 | _carService = carService; 31 | _fakeFindexService = fakeFindexService; 32 | } 33 | 34 | [SecuredOperation("admin,rental.add")] 35 | [ValidationAspect(typeof(RentalValidator))] 36 | public IResult Add(Rental rental) 37 | { 38 | var result = BusinessRules.Run(RentControl(rental.RentDate, rental.ReturnDate), RentedCarBeenReturned(rental.CarId,rental.RentDate,rental.ReturnDate), FindexControl(rental.CarId, rental.CustomerId)); 39 | 40 | if (result != null) 41 | { 42 | return result; 43 | } 44 | _rentalDal.Add(rental); 45 | return new SuccessResult(Messages.RentalAdded); 46 | } 47 | 48 | public IResult Delete(Rental rental) 49 | { 50 | _rentalDal.Delete(rental); 51 | return new SuccessResult(Messages.RentalDeleted); 52 | } 53 | 54 | public IDataResult> GetAll() 55 | { 56 | return new SuccessDataResult>(_rentalDal.GetAll(),Messages.RentalListed); 57 | } 58 | 59 | public IResult Update(Rental rental) 60 | { 61 | _rentalDal.Update(rental); 62 | return new SuccessResult(Messages.RentalUpdated); 63 | } 64 | 65 | public IDataResult> GetRentalDetails() 66 | { 67 | return new SuccessDataResult>(_rentalDal.GetRentalDetails()); 68 | } 69 | 70 | private IResult FindexControl(int carId, int customerId) 71 | { 72 | var result = _fakeFindexService.CheckFindex(_carService.GetById(carId).Data.MinFindex, _customerService.GetById(customerId).Data.FindexScore); 73 | if (result) 74 | { 75 | return new ErrorResult(); 76 | } 77 | return new SuccessResult(); 78 | } 79 | 80 | private IResult RentControl(DateTime rentDate, DateTime? returnDate) 81 | { 82 | var result = _rentalDal.GetAll(r => r.RentDate == rentDate && r.ReturnDate == returnDate).Any(); 83 | if (result) 84 | { 85 | return new ErrorResult(); 86 | } 87 | return new SuccessResult(); 88 | } 89 | private IResult RentedCarBeenReturned(int carId, DateTime rentDate, DateTime? returnDate) 90 | { 91 | var rentedCar = _rentalDal.GetAll(r => r.CarId == carId).Any(); 92 | if (rentedCar) 93 | { 94 | var rentedCars = _rentalDal.GetAll(r => r.CarId == carId); 95 | foreach (var car in rentedCars) 96 | { 97 | int rangeReturnToRent = DateTime.Compare((DateTime)car.ReturnDate, rentDate); 98 | int rangeRentToReturn = DateTime.Compare(car.RentDate, (DateTime)returnDate); 99 | 100 | if (car.ReturnDate == null || rangeReturnToRent > 0 || rangeRentToReturn > 0) 101 | { 102 | return new ErrorResult(Messages.InvalidRental); 103 | } 104 | } 105 | // <0 result.ReturnDate daha önce rentDateden 106 | } 107 | return new SuccessResult(); 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /Business/Concrete/UserManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constant; 3 | using Core.Entities.Concrete; 4 | using Core.Utilities.Results; 5 | using Core.Utilities.Security.Hashing; 6 | using DataAccess.Abstract; 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 UserManager : IUserService 15 | { 16 | IUserDal _userDal; 17 | 18 | public UserManager(IUserDal userDal) 19 | { 20 | _userDal = userDal; 21 | } 22 | public IResult Add(User user) 23 | { 24 | _userDal.Add(user); 25 | return new SuccessResult(Messages.UserAdded); 26 | } 27 | 28 | public IResult Delete(User user) 29 | { 30 | _userDal.Delete(user); 31 | return new SuccessResult(Messages.UserDeleted); 32 | } 33 | 34 | public IResult EditProfile(UserEditedDto user) 35 | { 36 | byte[] passwordHash; 37 | byte[] passwordSalt; 38 | 39 | HashingHelper.CreatePasswordHash(user.Password, out passwordHash, out passwordSalt); 40 | 41 | User editedUser = new User { 42 | 43 | Id = user.Id, 44 | FirstName = user.FirstName, 45 | LastName = user.LastName, 46 | Email = user.Email, 47 | PasswordHash = passwordHash, 48 | PasswordSalt = passwordSalt, 49 | Status = true 50 | 51 | }; 52 | 53 | _userDal.Update(editedUser); 54 | return new SuccessResult(Messages.UserUpdated); 55 | } 56 | 57 | public IDataResult> GetAll() 58 | { 59 | return new SuccessDataResult>(_userDal.GetAll(),Messages.UserListed); 60 | } 61 | 62 | public IDataResult> GetClaims(User user) 63 | { 64 | return new SuccessDataResult>(_userDal.GetClaims(user)); 65 | } 66 | 67 | public IDataResult GetUserByEmail(string email) 68 | { 69 | return new SuccessDataResult(_userDal.Get(u => u.Email == email)); 70 | } 71 | 72 | public IDataResult GetUserDtoByEmail(string email) 73 | { 74 | return new SuccessDataResult(_userDal.GetUserDtoByEmail(email)); 75 | } 76 | 77 | public IResult Update(User user) 78 | { 79 | _userDal.Update(user); 80 | return new SuccessResult(Messages.UserUpdated); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Business/Constant/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.Constant 8 | { 9 | public class Messages 10 | { 11 | public static string CarAdded = "Successfully added car "; 12 | public static string InvalidCarAdded = "Sorry, cannot add car "; 13 | public static string CarDeleted = "Successfully deleted car "; 14 | public static string CarUpdated = "Successfully updated car "; 15 | public static string CarListed = "Cars are listed"; 16 | public static string CarById = "Car is here"; 17 | 18 | public static string ColorAdded = "Successfully added color "; 19 | public static string ColorDeleted = "Successfully deleted color "; 20 | public static string ColorUpdated = "Successfully updated color "; 21 | public static string ColorListed = "Colors are listed"; 22 | public static string ColorById = "Color is here"; 23 | 24 | public static string BrandAdded = "Successfully added brand "; 25 | public static string BrandDeleted = "Successfully deleted brand "; 26 | public static string BrandUpdated = "Successfully updated brand "; 27 | public static string BrandListed = "Brands are listed"; 28 | public static string BrandById = "Brand is here"; 29 | 30 | public static string UserAdded = "Successfully added user "; 31 | public static string UserDeleted = "Successfully deleted user "; 32 | public static string UserUpdated = "Successfully updated user "; 33 | public static string UserListed = "Users are listed"; 34 | 35 | public static string CustomerAdded = "Successfully added customer "; 36 | public static string CustomerDeleted = "Successfully deleted customer "; 37 | public static string CustomerUpdated = "Successfully updated customer "; 38 | public static string CustomerList = "Customers are listed"; 39 | 40 | public static string RentalDeleted = "Successfully deleted rental "; 41 | public static string RentalUpdated = "Successfully updated rental "; 42 | public static string InvalidRental = "This car is not currently available"; 43 | public static string RentalAdded = "This car is available now. Car rental successful"; 44 | public static string RentalListed = "Rentals are listed"; 45 | 46 | public static string UserExists = "User already exists to system"; 47 | public static string UserNotFound = "User not found to system"; 48 | public static string BadPassword = "Entered the not correct password"; 49 | public static string NotBeAuth = "You are not authorized"; 50 | 51 | public static string SameBrandCarsCountExceeded = "The number of car with the same brand is too many, you cannot add car of this brand"; 52 | 53 | public static string CreditCardAdded = "Successfully added credit card "; 54 | public static string CreditCarDeleted = "Successfully deleted credit card "; 55 | public static string CreditCardUpdated = "Successfully updated credit card "; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /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 System; 11 | using System.Collections.Generic; 12 | using System.Text; 13 | 14 | namespace Business.DependencyResolvers.Autofac 15 | { 16 | public class AutofacBusinessModule : Module 17 | { 18 | protected override void Load(ContainerBuilder builder) 19 | { 20 | builder.RegisterType().As().SingleInstance(); //addsingleton 21 | builder.RegisterType().As().SingleInstance(); 22 | 23 | builder.RegisterType().As().SingleInstance(); 24 | builder.RegisterType().As().SingleInstance(); 25 | 26 | builder.RegisterType().As().SingleInstance(); 27 | builder.RegisterType().As().SingleInstance(); 28 | 29 | builder.RegisterType().As().SingleInstance(); 30 | builder.RegisterType().As().SingleInstance(); 31 | 32 | builder.RegisterType().As().SingleInstance(); 33 | builder.RegisterType().As().SingleInstance(); 34 | 35 | builder.RegisterType().As().SingleInstance(); 36 | builder.RegisterType().As().SingleInstance(); 37 | 38 | builder.RegisterType().As().SingleInstance(); 39 | builder.RegisterType().As().SingleInstance(); 40 | 41 | builder.RegisterType().As().SingleInstance(); 42 | builder.RegisterType().As().SingleInstance(); 43 | 44 | builder.RegisterType().As(); 45 | builder.RegisterType().As(); 46 | 47 | builder.RegisterType().As(); 48 | 49 | 50 | var assembly = System.Reflection.Assembly.GetExecutingAssembly(); 51 | 52 | builder.RegisterAssemblyTypes(assembly).AsImplementedInterfaces() 53 | .EnableInterfaceInterceptors(new ProxyGenerationOptions() 54 | { 55 | Selector = new AspectInterceptorSelector() 56 | }).SingleInstance(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /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(b => b.BrandName).NotEmpty(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/CarImageValidator.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 CarImageValidator : AbstractValidator 10 | { 11 | public CarImageValidator() 12 | { 13 | RuleFor(c => c.CarId).NotEmpty(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /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(c => c.Description).NotEmpty(); 14 | RuleFor(c => c.ModelYear).NotEmpty(); 15 | RuleFor(c => c.DailyPrice).GreaterThan(0); 16 | RuleFor(c => c.Description).MinimumLength(2); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /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 | RuleFor(c => c.ColorName).NotEmpty(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/CustomerValidator.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 CustomerValidator : AbstractValidator 10 | { 11 | public CustomerValidator() 12 | { 13 | RuleFor(c => c.CompanyName).NotEmpty(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /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(r => r.RentDate).NotEmpty(); 14 | RuleFor(r => r.CustomerId).NotEmpty(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/UserValidator.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Entities.Concrete; 3 | using FluentValidation; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace Business.ValidationRules.FluentValidation 9 | { 10 | public class UserValidator : AbstractValidator 11 | { 12 | public UserValidator() 13 | { 14 | RuleFor(u => u.FirstName).NotEmpty(); 15 | RuleFor(u => u.LastName).NotEmpty(); 16 | RuleFor(u => u.Email).NotEmpty(); 17 | RuleFor(u => u.Email).EmailAddress(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ConsoleUI/ConsoleUI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ConsoleUI/Program.cs: -------------------------------------------------------------------------------- 1 | using Business.Concrete; 2 | using DataAccess.Concrete.EntityFramework; 3 | using DataAccess.Concrete.InMemory; 4 | using Entities.Concrete; 5 | using System; 6 | using System.Collections.Generic; 7 | 8 | namespace ConsoleUI 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | CarManager carManager = new CarManager(new EfCarDal()); 15 | ColorManager colorManager = new ColorManager(new EfColorDal()); 16 | BrandManager brandManager = new BrandManager(new EfBrandDal()); 17 | 18 | UserManager userManager = new UserManager(new EFUserDal()); 19 | CustomerManager customerManager = new CustomerManager(new EfCustomerDal()); 20 | RentalManager rentalManager = new RentalManager(new EfRentalDal()); 21 | 22 | 23 | 24 | //RentalAddTest(rentalManager); //--> daha sonra iyileştireceğim 25 | //UserAddTest(userManager); 26 | //CustomerAddTest(customerManager); 27 | 28 | 29 | 30 | 31 | //CarCrudTest(carManager); 32 | //ColorCrudTest(colorManager); 33 | //BrandCrudTest(brandManager); 34 | //CarDetailsTest(carManager); 35 | 36 | //Test(carManager); 37 | //InMemorydeCalisma(); 38 | //AddTest(carManager, car1); 39 | //DeleteTest(carManager, car1); 40 | //UpdateTest(carManager); 41 | ////GetByIdTest(carManager); 42 | } 43 | 44 | private static void RentalAddTest(RentalManager rentalManager) 45 | { 46 | var result = rentalManager.Add(new Rental() 47 | { 48 | CarId = 10, 49 | CustomerId = 2, 50 | RentDate = DateTime.Now 51 | }); 52 | Console.WriteLine(result.Message); 53 | } 54 | 55 | private static void CustomerAddTest(CustomerManager customerManager) 56 | { 57 | customerManager.Add(new Customer() 58 | { 59 | CompanyName = "TulinsCompany", 60 | UserId = 1 61 | }); 62 | customerManager.Add(new Customer() 63 | { 64 | CompanyName = "TugcesCompany", 65 | UserId = 2 66 | }); 67 | } 68 | 69 | private static void CarDetailsTest(CarManager carManager) 70 | { 71 | foreach (var car in carManager.GetCarsDetails().Data) 72 | { 73 | Console.WriteLine("{0}/{1}/{2}/{3}", car.BrandName, car.ColorName, car.CarName, car.DailyPrice); 74 | } 75 | } 76 | 77 | /* private static void UserAddTest(UserManager userManager) 78 | { 79 | userManager.Add(new User() 80 | { 81 | FirstName = "Tuğçe", 82 | LastName = "Aktaş", 83 | Email = "tugceaktas@hotmail.com", 84 | Password = "1234567" 85 | }); 86 | } 87 | */ 88 | private static void BrandCrudTest(BrandManager brandManager) 89 | { 90 | Brand brand1 = new Brand() { BrandName = "deneme" }; 91 | 92 | brandManager.Add(brand1); 93 | foreach (var brand in brandManager.GetAll().Data) 94 | { 95 | Console.WriteLine(brand.BrandName); 96 | } 97 | brandManager.Update(new Brand() { BrandId = 1002, BrandName = "deneme degisti" }); 98 | foreach (var brand in brandManager.GetAll().Data) 99 | { 100 | Console.WriteLine(brand.BrandName); 101 | } 102 | brandManager.Delete(new Brand() { BrandId = 1002 }); 103 | foreach (var brand in brandManager.GetAll().Data) 104 | { 105 | Console.WriteLine(brand.BrandName); 106 | } 107 | } 108 | 109 | private static void ColorCrudTest(ColorManager colorManager) 110 | { 111 | Console.WriteLine(colorManager.GetById(5)); 112 | Color color1 = new Color() 113 | { 114 | ColorName = "Dark Green" 115 | }; 116 | Console.WriteLine("Renk ekleme"); 117 | colorManager.Add(color1); 118 | foreach (var color in colorManager.GetAll().Data) 119 | { 120 | Console.WriteLine(color.ColorName); 121 | } 122 | Console.WriteLine("Renk guncelleme islemi"); 123 | colorManager.Update(new Color { ColorId = 1002, ColorName = "deneme" }); 124 | foreach (var color in colorManager.GetAll().Data) 125 | { 126 | Console.WriteLine(color.ColorName); 127 | } 128 | Console.WriteLine("Renk silme islemi"); 129 | colorManager.Delete(new Color { ColorId = 1002 }); 130 | foreach (var color in colorManager.GetAll().Data) 131 | { 132 | Console.WriteLine(color.ColorName); 133 | } 134 | } 135 | 136 | private static void CarCrudTest(CarManager carManager) 137 | { 138 | Console.WriteLine(carManager.GetById(6).Data.Description); 139 | 140 | Car car1 = new Car() 141 | { 142 | BrandId = 3, 143 | ColorId = 9, 144 | DailyPrice = 120, 145 | Description = "Fiat marka gri araba", 146 | ModelYear = "2021" 147 | }; 148 | Console.WriteLine("Araba ekleme islemi"); 149 | carManager.Add(car1); 150 | foreach (var car in carManager.GetAll().Data) 151 | { 152 | Console.WriteLine(car.Description); 153 | } 154 | Console.WriteLine("Araba guncelleme islemi"); 155 | carManager.Update(new Car { CarId = 16, BrandId = 2, ColorId = 1, DailyPrice = 130, Description = "deneme", ModelYear = "2016" }); 156 | foreach (var car in carManager.GetAll().Data) 157 | { 158 | Console.WriteLine(car.Description); 159 | } 160 | Console.WriteLine("Araba silme islemi"); 161 | carManager.Delete(new Car { CarId = 16 }); 162 | foreach (var car in carManager.GetAll().Data) 163 | { 164 | Console.WriteLine(car.Description); 165 | } 166 | } 167 | 168 | private static void Test(CarManager carManager) 169 | { 170 | List cars = carManager.GetAll().Data; 171 | foreach (var car in cars) 172 | { 173 | Console.WriteLine(car.Description); 174 | } 175 | 176 | List sameBrandCars = carManager.GetCarsByBrandId(8).Data; 177 | foreach (var car in sameBrandCars) 178 | { 179 | Console.WriteLine(car.Description); 180 | } 181 | 182 | carManager.Add(new Car() // hata veriyor 183 | { 184 | BrandId = 1, 185 | ColorId = 9, 186 | DailyPrice = 0, 187 | Description = "BMW marka gri araba", 188 | ModelYear = "2013" 189 | }); 190 | } 191 | 192 | private static void InMemorydeCalisma() 193 | { 194 | 195 | Car car1 = new Car() 196 | { 197 | CarId = 7, 198 | BrandId = 3, 199 | ColorId = 4, 200 | DailyPrice = 300000, 201 | Description = "Volkswagen Araba", 202 | ModelYear = "2018" 203 | }; 204 | } 205 | 206 | private static void UpdateTest(CarManager carManager) 207 | { 208 | carManager.Update(new Car() { CarId = 7, BrandId = 4, ColorId = 4, DailyPrice = 350000, Description = "Volkswagen Araba(modifiye)", ModelYear = "2018" }); 209 | 210 | var c = carManager.GetAll().Data; 211 | foreach (var car in c) 212 | { 213 | Console.WriteLine(car.Description); 214 | } 215 | } 216 | 217 | private static void GetByIdTest(CarManager carManager) 218 | { 219 | var car = carManager.GetById(2); 220 | Console.WriteLine(car.Data.Description); 221 | } 222 | 223 | private static void DeleteTest(CarManager carManager, Car car1) 224 | { 225 | carManager.Delete(car1); 226 | List c = carManager.GetAll().Data; 227 | foreach (var car in c) 228 | { 229 | Console.WriteLine(car.Description); 230 | } 231 | } 232 | 233 | private static void AddTest(CarManager carManager, Car car1) 234 | { 235 | carManager.Add(car1); 236 | List cars = carManager.GetAll().Data; 237 | foreach (var car in cars) 238 | { 239 | Console.WriteLine(car.Description); 240 | } 241 | } 242 | } 243 | } 244 | -------------------------------------------------------------------------------- /Core/Aspect/Autofac/Caching/CacheAspect.cs: -------------------------------------------------------------------------------- 1 | using Core.CrossCuttingConcerns.Caching; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using Core.Utilities.Interceptors; 4 | using Core.Utilities.IoC; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | using Castle.DynamicProxy; 9 | using System.Linq; 10 | 11 | namespace Core.Aspect.Autofac.Caching 12 | { 13 | public class CacheAspect : MethodInterception 14 | { 15 | public int _duration; 16 | ICacheManager _cacheManager; 17 | public CacheAspect(int duration = 60) 18 | { 19 | _duration = duration; 20 | _cacheManager = ServiceTool.ServiceProvider.GetService(); 21 | } 22 | 23 | public override void Intercept(IInvocation invocation) 24 | { 25 | var methodName = string.Format($"{invocation.Method.ReflectedType.FullName}.{invocation.Method.Name}"); 26 | var arguments = invocation.Arguments.ToList(); 27 | var key = $"{methodName}({string.Join(",", arguments.Select(x => x?.ToString() ?? ""))})"; 28 | if (_cacheManager.IsAdd(key)) 29 | { 30 | invocation.ReturnValue = _cacheManager.Get(key); 31 | return; 32 | } 33 | invocation.Proceed(); 34 | _cacheManager.Add(key, invocation.ReturnValue, _duration); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Core/Aspect/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 | 10 | namespace Core.Aspects.Autofac.Caching 11 | { 12 | public class CacheRemoveAspect : MethodInterception 13 | { 14 | private string _pattern; 15 | private ICacheManager _cacheManager; 16 | 17 | public CacheRemoveAspect(string pattern) 18 | { 19 | _pattern = pattern; 20 | _cacheManager = ServiceTool.ServiceProvider.GetService(); 21 | } 22 | 23 | protected override void OnSuccess(IInvocation invocation) 24 | { 25 | _cacheManager.RemoveByPattern(_pattern); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Core/Aspect/Autofac/Performance/PerformanceAspect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Text; 5 | using Castle.DynamicProxy; 6 | using Core.Utilities.Interceptors; 7 | using Core.Utilities.IoC; 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 | } -------------------------------------------------------------------------------- /Core/Aspect/Autofac/Transaction/TransactionScopeAspect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Transactions; 5 | using Castle.DynamicProxy; 6 | using Core.Utilities.Interceptors; 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 | } -------------------------------------------------------------------------------- /Core/Aspect/Autofac/Validation/ValidationAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.CrossCuttingConcerns.Validation; 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.Aspect.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 Exception("invalid type"); 20 | } 21 | 22 | _validatorType = validatorType; 23 | } 24 | protected override void OnBefore(IInvocation invocation) 25 | { 26 | var validator = (IValidator)Activator.CreateInstance(_validatorType); //new validator object 27 | var entityType = _validatorType.BaseType.GetGenericArguments()[0]; //0. elemanın objesi 28 | var entities = invocation.Arguments.Where(e => e.GetType().Equals(entityType)); 29 | 30 | foreach (var entity in entities) 31 | { 32 | ValidationTool.Validate(validator, entity); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Core/Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /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 | void Add(string key, object value, int duration); 10 | void Remove(string key); 11 | void RemoveByPattern(string pattern); //patterne gore silme 12 | T Get(string key); 13 | object Get(string key); 14 | bool IsAdd(string key); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Caching/Microsoft/MemoryCacheManager.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.IoC; 2 | using Microsoft.Extensions.Caching.Memory; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Text.RegularExpressions; 9 | 10 | namespace Core.CrossCuttingConcerns.Caching.Microsoft 11 | { 12 | public class MemoryCacheManager : ICacheManager 13 | { 14 | IMemoryCache _memoryCache; 15 | public MemoryCacheManager() 16 | { 17 | _memoryCache = ServiceTool.ServiceProvider.GetService(); 18 | } 19 | public void Add(string key, object value, int duration) 20 | { 21 | _memoryCache.Set(key, value, TimeSpan.FromMinutes(duration)); 22 | } 23 | 24 | public T Get(string key) 25 | { 26 | return _memoryCache.Get(key); 27 | } 28 | 29 | public object Get(string key) 30 | { 31 | return _memoryCache.Get(key); 32 | } 33 | 34 | public bool IsAdd(string key) 35 | { 36 | return _memoryCache.TryGetValue(key, out _); 37 | } 38 | 39 | public void Remove(string key) 40 | { 41 | _memoryCache.Remove(key); 42 | } 43 | 44 | public void RemoveByPattern(string pattern) 45 | { 46 | var cacheEntriesCollectionDefition = typeof(MemoryCache) 47 | .GetProperty("EntriesCollection", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); 48 | var cacheEntriesCollection = cacheEntriesCollectionDefition.GetValue(_memoryCache) as dynamic; 49 | 50 | List cacheCollectionValues = new List(); 51 | foreach (var cacheItem in cacheEntriesCollection) 52 | { 53 | ICacheEntry cacheItemValue = cacheItem.GetType().GetProperty("Value").GetValue(cacheItem, null); 54 | cacheCollectionValues.Add(cacheItemValue); 55 | } 56 | 57 | var regex = new Regex(pattern, RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase); 58 | var keysToRemove = cacheCollectionValues.Where(d => regex.IsMatch(d.Key.ToString())).Select(d => d.Key).ToList(); 59 | foreach (var key in keysToRemove) 60 | { 61 | _memoryCache.Remove(key); 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Validation/ValidationTool.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.CrossCuttingConcerns.Validation 7 | { 8 | public static class ValidationTool 9 | { 10 | public static void Validate(IValidator validator, object entity) 11 | { 12 | var context = new ValidationContext(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/DataAccess/EntityFramework/EfEntityRepositoryBase.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using Microsoft.EntityFrameworkCore; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Linq.Expressions; 7 | using System.Text; 8 | 9 | namespace Core.DataAccess.EntityFramework 10 | { 11 | public class EfEntityRepositoryBase : IEntityRepository //entity framework base sınıfı 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 addedBrand = context.Entry(entity); 20 | addedBrand.State = EntityState.Added; 21 | context.SaveChanges(); 22 | 23 | } 24 | } 25 | 26 | public void Delete(TEntity entity) 27 | { 28 | using (TContext context = new TContext()) 29 | { 30 | var deletedBrand = context.Entry(entity); 31 | deletedBrand.State = EntityState.Deleted; 32 | context.SaveChanges(); 33 | } 34 | } 35 | 36 | public TEntity Get(Expression> filter) 37 | { 38 | using (TContext context = new TContext()) 39 | { 40 | return context.Set().SingleOrDefault(filter); 41 | } 42 | } 43 | 44 | public List GetAll(Expression> filter = null) 45 | { 46 | using (TContext context = new TContext()) 47 | { 48 | return filter == null ? context.Set().ToList() : 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 updatedBrand = context.Entry(entity); 58 | updatedBrand.State = EntityState.Modified; 59 | context.SaveChanges(); 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Core/DataAccess/IEntityRepository.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq.Expressions; 5 | using System.Text; 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 | -------------------------------------------------------------------------------- /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.AddSingleton(); 18 | serviceCollection.AddSingleton(); 19 | serviceCollection.AddMemoryCache(); 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 | 5 | namespace Core.Entities.Concrete 6 | { 7 | public class OperationClaim : IEntity 8 | { 9 | public int Id { get; set; } 10 | public string Name { get; set; } 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities.Concrete 6 | { 7 | public class User : IEntity 8 | { 9 | public int Id { get; set; } 10 | public string FirstName { get; set; } 11 | public string LastName { get; set; } 12 | public string Email { get; set; } 13 | public byte[] PasswordHash { get; set; } 14 | public byte[] PasswordSalt { get; set; } 15 | public bool Status { get; set; } 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /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 | } 12 | -------------------------------------------------------------------------------- /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 AddNameIdentifier(this ICollection claims, string id) 18 | { 19 | claims.Add(new Claim(ClaimTypes.NameIdentifier, id)); 20 | } 21 | 22 | public static void AddName(this ICollection claims, string name) 23 | { 24 | claims.Add(new Claim(ClaimTypes.Name, name)); 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.Collections.Generic; 2 | using System.Linq; 3 | using System.Security.Claims; 4 | 5 | namespace Core.Extensions 6 | { 7 | public static class ClaimsPrincipalExtensions 8 | { 9 | public static List Claims(this ClaimsPrincipal claimsPrincipal, string claimType) 10 | { 11 | var result = claimsPrincipal?.FindAll(claimType)?.Select(x => x.Value).ToList(); 12 | return result; 13 | } 14 | 15 | public static List ClaimRoles(this ClaimsPrincipal claimsPrincipal) 16 | { 17 | return claimsPrincipal?.Claims(ClaimTypes.Role); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Core/Extensions/ErrorDetails.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using FluentValidation.Results; 5 | using Newtonsoft.Json; 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 | public override string ToString() 15 | { 16 | return JsonConvert.SerializeObject(this); 17 | } 18 | } 19 | 20 | public class ValidationErrorDetails : ErrorDetails 21 | { 22 | public IEnumerable ValidationErrors { get; set; } 23 | } 24 | } -------------------------------------------------------------------------------- /Core/Extensions/ExceptionMiddleware.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using FluentValidation; 7 | using FluentValidation.Results; 8 | using Microsoft.AspNetCore.Http; 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 = httpContext.Response.StatusCode, 49 | Message = message, 50 | ValidationErrors = errors 51 | }.ToString()); 52 | } 53 | 54 | return httpContext.Response.WriteAsync(new ErrorDetails 55 | { 56 | StatusCode = httpContext.Response.StatusCode, 57 | Message = message 58 | }.ToString()); 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /Core/Extensions/ExceptionMiddlewareExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.AspNetCore.Builder; 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 | } -------------------------------------------------------------------------------- /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 AddDependencyResolvers 12 | (this IServiceCollection serviceCollection, ICoreModule[] modules) 13 | { 14 | foreach (var module in modules) 15 | { 16 | module.Load(serviceCollection); 17 | } 18 | return ServiceTool.Create(serviceCollection); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Core/Utilities/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 static 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 | return null; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Utilities/Helpers/FileHelper.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.Helpers 9 | { 10 | public static class FileHelper 11 | { 12 | public static string Add(IFormFile file) 13 | { 14 | var tempPath = Path.GetTempFileName(); 15 | if (file.Length>0) 16 | { 17 | using (FileStream fileStream = new FileStream(tempPath,FileMode.Create)) 18 | { 19 | file.CopyTo(fileStream); 20 | } 21 | } 22 | var fileNewPath = newPath(file); 23 | File.Move(tempPath, fileNewPath.path2); 24 | return fileNewPath.path; 25 | } 26 | public static IResult Delete(string path) 27 | { 28 | try 29 | { 30 | File.Delete(Environment.CurrentDirectory + @"\wwwroot\CarImages\" + path); 31 | } 32 | catch (Exception) 33 | { 34 | return new ErrorResult(); 35 | } 36 | 37 | return new SuccessResult(); 38 | } 39 | public static string Update(string updatedPath, IFormFile file) 40 | { 41 | File.Delete(Environment.CurrentDirectory + @"\wwwroot\CarImages\" + updatedPath); 42 | var result = Add(file); 43 | return result; 44 | } 45 | 46 | public static (string path,string path2) newPath(IFormFile file) 47 | { 48 | FileInfo fileInfo = new FileInfo(file.FileName); 49 | var fileExtension = fileInfo.Extension; 50 | 51 | var currentLocation = Environment.CurrentDirectory + @"\wwwroot\CarImages\"; 52 | var path = Guid.NewGuid().ToString() + fileExtension; 53 | var path2 = currentLocation + path; 54 | return (path,path2); 55 | } 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/AspectInterceptorSelector.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | 8 | namespace Core.Utilities.Interceptors 9 | { 10 | public class AspectInterceptorSelector : IInterceptorSelector 11 | { 12 | public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) 13 | { 14 | var classAttributes = type.GetCustomAttributes 15 | (true).ToList(); 16 | var methodAttributes = type.GetMethod(method.Name) 17 | .GetCustomAttributes(true); 18 | classAttributes.AddRange(methodAttributes); 19 | // classAttributes.Add(new ExceptionLogAspect(typeof(FileLogger))); 20 | 21 | return classAttributes.OrderBy(x => x.Priority).ToArray(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/MethodInterception.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | 4 | namespace Core.Utilities.Interceptors 5 | { 6 | public abstract class MethodInterception : MethodInterceptionBaseAttribute 7 | { 8 | //invocation : business methods 9 | protected virtual void OnBefore(IInvocation invocation) { } 10 | protected virtual void OnAfter(IInvocation invocation) { } 11 | protected virtual void OnException(IInvocation invocation, System.Exception e) { } 12 | protected virtual void OnSuccess(IInvocation invocation) { } 13 | public override void Intercept(IInvocation invocation) 14 | { 15 | var isSuccess = true; 16 | OnBefore(invocation); 17 | try 18 | { 19 | invocation.Proceed(); 20 | } 21 | catch (Exception e) 22 | { 23 | isSuccess = false; 24 | OnException(invocation, e); 25 | throw; 26 | } 27 | finally 28 | { 29 | if (isSuccess) 30 | { 31 | OnSuccess(invocation); 32 | } 33 | } 34 | OnAfter(invocation); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/MethodInterceptionBaseAttribute.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | 4 | namespace Core.Utilities.Interceptors 5 | { 6 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] 7 | public abstract class MethodInterceptionBaseAttribute : Attribute, Castle.DynamicProxy.IInterceptor 8 | { 9 | public int Priority { get; set; } 10 | 11 | public virtual void Intercept(IInvocation invocation) 12 | { 13 | 14 | } 15 | 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Core/Utilities/IoC/ICoreModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.Extensions.DependencyInjection; 5 | 6 | namespace Core.Utilities.IoC 7 | { 8 | public interface ICoreModule 9 | { 10 | void Load(IServiceCollection serviceCollection); 11 | } 12 | } -------------------------------------------------------------------------------- /Core/Utilities/IoC/ServiceTool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.Extensions.DependencyInjection; 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 | } -------------------------------------------------------------------------------- /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 | public DataResult(T data, bool success):base(success) 14 | { 15 | Data = data; 16 | } 17 | 18 | public T Data { get; } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /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) //butun veriler istenebilir 10 | { 11 | 12 | } 13 | public ErrorDataResult(T data) : base(data, false) // sadece data ve error bilgisi istenebilir 14 | { 15 | 16 | } 17 | public ErrorDataResult(string message) : base(default,false,message) //data istenmeyebilir(o halde data default verilir) 18 | { 19 | 20 | } 21 | public ErrorDataResult() :base(default,false) //sadece error bilgisi istenebilir 22 | { 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /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 | public ErrorResult() : base(false) 14 | { 15 | 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /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 | bool Success { get; } 10 | 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 | //ctor icinde getterları set edebiliyoruz! 10 | public Result(bool success, string message) : this(success) // success'i diger ctora yolladık 11 | { 12 | Message = message; 13 | } 14 | //method overloading 15 | public Result(bool success) 16 | { 17 | Success = success; 18 | } 19 | public bool Success { get; } 20 | 21 | public string Message { 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) //butun veriler istenebilir 10 | { 11 | 12 | } 13 | public SuccessDataResult(T data) : base(data, true) // sadece data ve success bilgisi istenebilir 14 | { 15 | 16 | } 17 | public SuccessDataResult(string message) : base(default, true, message) //data istenmeyebilir(o halde data default verilir) 18 | { 19 | 20 | } 21 | public SuccessDataResult() : base(default, true) //sadece success bilgisi istenebilir 22 | { 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /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 | public SuccessResult():base(true) 14 | { 15 | 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /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 static class SecurityKeyHelper 9 | { 10 | public static SecurityKey CreateSecurityKey(string securityKey) 11 | { 12 | return new SymmetricSecurityKey(Encoding.UTF8.GetBytes(securityKey)); 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 static 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/HashingHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Security.Hashing 6 | { 7 | public static class HashingHelper 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 VerifyPassword(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].Equals(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 Core.Entities.Concrete; 2 | using Core.Extensions; 3 | using Core.Utilities.Security.Encryption; 4 | using Microsoft.Extensions.Configuration; 5 | using Microsoft.IdentityModel.Tokens; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.IdentityModel.Tokens.Jwt; 9 | using System.Linq; 10 | using System.Security.Claims; 11 | using System.Text; 12 | 13 | namespace Core.Utilities.Security.Jwt 14 | { 15 | public class JwtHelper : ITokenHelper 16 | { 17 | IConfiguration Configuration; 18 | TokenOptions _tokenOptions; 19 | DateTime _accessTokenExpiration; 20 | public JwtHelper(IConfiguration configuration) 21 | { 22 | Configuration = configuration; 23 | _tokenOptions = Configuration.GetSection("TokenOptions").Get(); 24 | } 25 | public AccessToken CreateToken(User user, List operationClaims) 26 | { 27 | _accessTokenExpiration = DateTime.Now.AddMinutes(_tokenOptions.AccessTokenExpiration); 28 | var securityKey = SecurityKeyHelper.CreateSecurityKey(_tokenOptions.SecurityKey); 29 | var signingCredentials = SigningCredentialsHelper.CreateSigningCredentials(securityKey); 30 | var jwt = CreateJwtToken(_tokenOptions, user, operationClaims, signingCredentials); 31 | 32 | var jwtTokenHandler = new JwtSecurityTokenHandler(); 33 | var token = jwtTokenHandler.WriteToken(jwt); 34 | 35 | return new AccessToken 36 | { 37 | Token = token, 38 | Expiration = _accessTokenExpiration 39 | }; 40 | } 41 | 42 | private JwtSecurityToken CreateJwtToken(TokenOptions tokenOptions, User user, List operationClaims, SigningCredentials signingCredentials) 43 | { 44 | JwtSecurityToken jwtSecurityToken = new JwtSecurityToken( 45 | audience: _tokenOptions.Audience, 46 | issuer: _tokenOptions.Issuer, 47 | expires: _accessTokenExpiration, 48 | notBefore: DateTime.UtcNow, 49 | signingCredentials: signingCredentials, 50 | claims: GetClaims(user,operationClaims) 51 | ); 52 | return jwtSecurityToken; 53 | } 54 | 55 | private IEnumerable GetClaims(User user, List operationClaims) 56 | { 57 | var claims = new List(); 58 | claims.AddName($"{user.FirstName} {user.LastName}"); 59 | claims.AddEmail(user.Email); 60 | claims.AddNameIdentifier(user.Id.ToString()); 61 | claims.AddRoles(operationClaims.Select(o => o.Name).ToArray()); 62 | 63 | return claims; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /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/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.Text; 7 | 8 | namespace DataAccess.Abstract 9 | { 10 | public interface ICarDal : IEntityRepository 11 | { 12 | List GetCarsDetailByBrandId(int brandId); 13 | List GetCarsDetailByColorId(int colorId); 14 | List GetCarsDetails(); 15 | CarDetailsDto GetCarDetailsById(int carId); 16 | List GetCarsDetailByColorIdAndBrandId(int colorId, int brandId); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICarImageDal.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 ICarImageDal : IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IColorDal.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 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICreditCardDal.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 ICreditCardDal :IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /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 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface ICustomerDal :IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IRentalDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Abstract 9 | { 10 | public interface IRentalDal : IEntityRepository 11 | { 12 | List GetRentalDetails(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IUserDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Core.Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Abstract 9 | { 10 | public interface IUserDal : IEntityRepository 11 | { 12 | List GetClaims(User user); 13 | UserEditedDto GetUserDtoByEmail(string email); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EFUserDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using Core.Entities.Concrete; 3 | using DataAccess.Abstract; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | using System.Linq; 8 | using Entities.DTOs; 9 | 10 | namespace DataAccess.Concrete.EntityFramework 11 | { 12 | public class EFUserDal : EfEntityRepositoryBase, IUserDal 13 | { 14 | public List GetClaims(User user) 15 | { 16 | using (ReCapContext context = new ReCapContext()) 17 | { 18 | var result = from operationClaim in context.OperationClaims 19 | join userOperationClaim in context.UserOperationClaims 20 | on operationClaim.Id equals userOperationClaim.OperationClaimId 21 | where userOperationClaim.UserId == user.Id 22 | select new OperationClaim { Id = operationClaim.Id, Name = operationClaim.Name }; 23 | return result.ToList(); 24 | } 25 | } 26 | 27 | public UserEditedDto GetUserDtoByEmail(string email) 28 | { 29 | using (ReCapContext context = new ReCapContext()) 30 | { 31 | var result = from user in context.Users 32 | where user.Email == email 33 | select new UserEditedDto 34 | { 35 | Id = user.Id, 36 | FirstName = user.FirstName, 37 | LastName = user.LastName, 38 | Email = user.Email 39 | }; 40 | 41 | return result.SingleOrDefault(); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfBrandDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using Microsoft.EntityFrameworkCore; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Linq.Expressions; 9 | using System.Text; 10 | 11 | namespace DataAccess.Concrete.EntityFramework 12 | { 13 | public class EfBrandDal : EfEntityRepositoryBase, IBrandDal 14 | { 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCarDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using Entities.DTOs; 5 | using Microsoft.EntityFrameworkCore; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Linq.Expressions; 10 | using System.Text; 11 | 12 | namespace DataAccess.Concrete.EntityFramework 13 | { 14 | public class EfCarDal : EfEntityRepositoryBase, ICarDal 15 | { 16 | public List GetCarsDetails() 17 | { 18 | using (ReCapContext context = new ReCapContext()) 19 | { 20 | var result = from car in context.Cars 21 | join color in context.Colors on car.ColorId equals color.ColorId 22 | join brand in context.Brands on car.BrandId equals brand.BrandId 23 | select new CarDetailsDto 24 | { 25 | Id =car.CarId, 26 | CarName = car.Description, 27 | BrandName = brand.BrandName, 28 | ColorName = color.ColorName, 29 | ModelYear = car.ModelYear, 30 | DailyPrice = car.DailyPrice, 31 | ImagePath = context.CarImages.Where(c => c.CarId == car.CarId).FirstOrDefault().ImagePath 32 | }; 33 | 34 | return result.ToList(); 35 | } 36 | } 37 | public List GetCarsDetailByColorId(int colorId) 38 | { 39 | using (ReCapContext context = new ReCapContext()) 40 | { 41 | var result = from car in context.Cars 42 | join color in context.Colors on car.ColorId equals color.ColorId 43 | join brand in context.Brands on car.BrandId equals brand.BrandId 44 | where color.ColorId == colorId 45 | select new CarDetailsDto 46 | { 47 | Id = car.CarId, 48 | CarName = car.Description, 49 | BrandName = brand.BrandName, 50 | ColorName = color.ColorName, 51 | ModelYear = car.ModelYear, 52 | DailyPrice = car.DailyPrice, 53 | ImagePath = context.CarImages.Where(c => c.CarId == car.CarId).FirstOrDefault().ImagePath 54 | }; 55 | 56 | return result.ToList(); 57 | } 58 | } 59 | 60 | public List GetCarsDetailByBrandId(int brandId) 61 | { 62 | using (ReCapContext context = new ReCapContext()) 63 | { 64 | var result = from car in context.Cars 65 | join color in context.Colors on car.ColorId equals color.ColorId 66 | join brand in context.Brands on car.BrandId equals brand.BrandId 67 | where brand.BrandId == brandId 68 | select new CarDetailsDto 69 | { 70 | Id = car.CarId, 71 | CarName = car.Description, 72 | BrandName = brand.BrandName, 73 | ColorName = color.ColorName, 74 | ModelYear = car.ModelYear, 75 | DailyPrice = car.DailyPrice, 76 | ImagePath = context.CarImages.Where(c => c.CarId == car.CarId).FirstOrDefault().ImagePath 77 | }; 78 | 79 | return result.ToList(); 80 | } 81 | } 82 | 83 | 84 | public CarDetailsDto GetCarDetailsById(int carId) 85 | { 86 | using (ReCapContext context = new ReCapContext()) 87 | { 88 | var result = from car in context.Cars 89 | join color in context.Colors on car.ColorId equals color.ColorId 90 | join brand in context.Brands on car.BrandId equals brand.BrandId 91 | where car.CarId == carId 92 | select new CarDetailsDto 93 | { 94 | Id = car.CarId, 95 | CarName = car.Description, 96 | BrandName = brand.BrandName, 97 | ColorName = color.ColorName, 98 | ModelYear = car.ModelYear, 99 | DailyPrice = car.DailyPrice, 100 | ImagePath = context.CarImages.Where(c => c.CarId == car.CarId).FirstOrDefault().ImagePath 101 | }; 102 | 103 | return result.SingleOrDefault(); 104 | } 105 | } 106 | 107 | public List GetCarsDetailByColorIdAndBrandId(int colorId, int brandId) 108 | { 109 | using (ReCapContext context = new ReCapContext()) 110 | { 111 | var result = from car in context.Cars 112 | join color in context.Colors on car.ColorId equals color.ColorId 113 | join brand in context.Brands on car.BrandId equals brand.BrandId 114 | where brand.BrandId == brandId && color.ColorId == colorId 115 | select new CarDetailsDto 116 | { 117 | Id = car.CarId, 118 | CarName = car.Description, 119 | BrandName = brand.BrandName, 120 | ColorName = color.ColorName, 121 | ModelYear = car.ModelYear, 122 | DailyPrice = car.DailyPrice, 123 | ImagePath = context.CarImages.Where(c => c.CarId == car.CarId).FirstOrDefault().ImagePath 124 | }; 125 | 126 | return result.ToList(); 127 | } 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /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.Linq.Expressions; 7 | using System.Text; 8 | 9 | namespace DataAccess.Concrete.EntityFramework 10 | { 11 | public class EfCarImageDal :EfEntityRepositoryBase, ICarImageDal 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfColorDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using Microsoft.EntityFrameworkCore; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Linq.Expressions; 9 | using System.Text; 10 | 11 | namespace DataAccess.Concrete.EntityFramework 12 | { 13 | public class EfColorDal : EfEntityRepositoryBase,IColorDal 14 | { 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCreditCard.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 EfCreditCard: EfEntityRepositoryBase, ICreditCardDal 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCustomerDal.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 EfCustomerDal : EfEntityRepositoryBase, ICustomerDal 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfRentalDal.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; 8 | using System.Text; 9 | 10 | namespace DataAccess.Concrete.EntityFramework 11 | { 12 | public class EfRentalDal : EfEntityRepositoryBase , IRentalDal 13 | { 14 | public List GetRentalDetails() 15 | { 16 | using (ReCapContext context = new ReCapContext()) 17 | { 18 | var result = from rental in context.Rentals 19 | join car in context.Cars on rental.CarId equals car.CarId 20 | join brand in context.Brands on car.BrandId equals brand.BrandId 21 | join customer in context.Customers on rental.CustomerId equals customer.Id 22 | join user in context.Users on customer.UserId equals user.Id 23 | select new RentalDetailsDto() 24 | { 25 | BrandName = brand.BrandName, 26 | FullName = user.FirstName + " " + user.LastName, 27 | RentDate = rental.RentDate, 28 | ReturnDate = rental.ReturnDate 29 | }; 30 | return result.ToList(); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /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.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFramework 9 | { 10 | public class ReCapContext : DbContext 11 | { 12 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 13 | { 14 | optionsBuilder.UseSqlServer(@"Server=(localdb)\MSSQLLocalDB; Database=ReCapDatabase; Trusted_Connection=true"); 15 | } 16 | public DbSet Cars { get; set; } 17 | public DbSet Brands { get; set; } 18 | public DbSet Colors { get; set; } 19 | public DbSet Customers { get; set; } 20 | public DbSet Rentals { get; set; } 21 | public DbSet CarImages { get; set; } 22 | public DbSet OperationClaims { get; set; } 23 | public DbSet UserOperationClaims{ get; set; } 24 | public DbSet Users { get; set; } 25 | public DbSet CreditCards { get; set; } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /DataAccess/Concrete/InMemory/InMemoryCarDal.cs: -------------------------------------------------------------------------------- 1 | using DataAccess.Abstract; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Linq.Expressions; 8 | using System.Text; 9 | 10 | namespace DataAccess.Concrete.InMemory 11 | { 12 | public class InMemoryCarDal : ICarDal 13 | { 14 | //datalari aliyoruz 15 | //simülasyon 16 | List _cars; 17 | public InMemoryCarDal() 18 | { 19 | _cars = new List 20 | { 21 | new Car(){CarId = 1, BrandId =1, ColorId = 1, DailyPrice = 590000, Description = "AUDI Araba", ModelYear="2017" }, 22 | new Car(){CarId = 2, BrandId =1, ColorId = 2, DailyPrice = 150000, Description = "AUDI Araba", ModelYear="2004" }, 23 | new Car(){CarId = 3, BrandId =1, ColorId = 1, DailyPrice = 100000, Description = "AUDI Araba", ModelYear="2001" }, 24 | new Car(){CarId = 4, BrandId =2, ColorId = 3, DailyPrice = 125000, Description = "Ford Araba", ModelYear="2014" }, 25 | new Car(){CarId = 5, BrandId =2, ColorId = 4, DailyPrice = 250000, Description = "Ford Araba", ModelYear="2018" }, 26 | new Car(){CarId = 6, BrandId =3, ColorId = 3, DailyPrice = 102000, Description = "Volkswagen Araba", ModelYear="2009" } 27 | }; 28 | } 29 | 30 | public void Add(Car car) 31 | { 32 | _cars.Add(car); 33 | } 34 | 35 | public void Delete(Car car) 36 | { 37 | Car carToDelete = null; 38 | var result =_cars.SingleOrDefault(c => car.CarId == c.CarId); 39 | carToDelete = result; 40 | _cars.Remove(carToDelete); 41 | } 42 | 43 | public Car Get(Expression> filter) 44 | { 45 | throw new NotImplementedException(); 46 | } 47 | 48 | public List GetAll() 49 | { 50 | return _cars; 51 | } 52 | 53 | public List GetAll(Expression> filter = null) 54 | { 55 | throw new NotImplementedException(); 56 | } 57 | 58 | public Car GetById(int id) 59 | { 60 | return _cars.SingleOrDefault(c => c.CarId == id); 61 | //return (Car)_cars.Where(c => c.Id == id); 62 | } 63 | 64 | public CarDetailsDto GetCarDetailsById(int carId) 65 | { 66 | throw new NotImplementedException(); 67 | } 68 | 69 | public List GetCarsDetailByBrandId(int brandId) 70 | { 71 | throw new NotImplementedException(); 72 | } 73 | 74 | public List GetCarsDetailByColorId(int colorId) 75 | { 76 | throw new NotImplementedException(); 77 | } 78 | 79 | public List GetCarsDetailByColorIdAndBrandId(int colorId, int brandId) 80 | { 81 | throw new NotImplementedException(); 82 | } 83 | 84 | public List GetCarsDetails() 85 | { 86 | throw new NotImplementedException(); 87 | } 88 | 89 | public void Update(Car car) 90 | { 91 | Car carToUpdate = null; 92 | var result = _cars.SingleOrDefault(c => car.CarId == c.CarId); 93 | carToUpdate = result; 94 | 95 | carToUpdate.CarId = car.CarId; 96 | carToUpdate.BrandId = car.BrandId; 97 | carToUpdate.ColorId = car.ColorId; 98 | carToUpdate.DailyPrice = car.DailyPrice; 99 | carToUpdate.Description = car.Description; 100 | carToUpdate.ModelYear = car.ModelYear; 101 | 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /DataAccess/DataAccess.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /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 int BrandId { get; set; } 12 | public int ColorId { get; set; } 13 | public string ModelYear { get; set; } 14 | public decimal DailyPrice { get; set; } 15 | public string Description { get; set; } 16 | public int MinFindex { get; set; } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /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 | public int Id { get; set; } 11 | public int CarId { get; set; } 12 | public string ImagePath { get; set; } 13 | public DateTime Date { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /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 | } 15 | -------------------------------------------------------------------------------- /Entities/Concrete/CreditCard.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 CreditCard:IEntity 9 | { 10 | public int Id { get; set; } 11 | public int CustomerId { get; set; } 12 | public string FullName { get; set; } 13 | public string CardNumber { get; set; } 14 | public string ExpirationDate { get; set; } 15 | public string CVV { get; set; } 16 | public decimal? Amount { get; set; } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Entities/Concrete/Customer.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Text; 6 | 7 | namespace Entities.Concrete 8 | { 9 | public class Customer :IEntity 10 | { 11 | public int Id { get; set; } 12 | [Key] 13 | public int UserId { get; set; } 14 | public string CompanyName { get; set; } 15 | public int FindexScore { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /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; } // kiralama 14 | public DateTime? ReturnDate { get; set; } // geri getirme 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Entities/DTOs/CarDetailsDto.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 CarDetailsDto : IDto 9 | { 10 | public int Id { get; set; } 11 | public string CarName { get; set; } 12 | public string BrandName { get; set; } 13 | public string ColorName { get; set; } 14 | public string ModelYear { get; set; } 15 | public decimal DailyPrice { get; set; } 16 | public string ImagePath { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Entities/DTOs/RentalDetailsDto.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 RentalDetailsDto :IDto 9 | { 10 | public string BrandName { get; set; } 11 | public string FullName { get; set; } 12 | public DateTime RentDate { get; set; } 13 | public DateTime? ReturnDate { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Entities/DTOs/UserEditedDto.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 UserEditedDto : IDto 9 | { 10 | public int Id { get; set; } 11 | public string FirstName { get; set; } 12 | public string LastName { get; set; } 13 | public string Email { get; set; } 14 | public string Password { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /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 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class UserForRegisterDto : IDto 9 | { 10 | public string FirstName { get; set; } 11 | public string LastName { get; set; } 12 | public string Email { get; set; } 13 | public string Password { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Entities/Entities.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /ReCapProject.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30907.101 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Business", "Business\Business.csproj", "{98AF19FC-77CE-4C4A-8EA0-1A67BBA2751B}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAccess", "DataAccess\DataAccess.csproj", "{6B26ECAE-E2ED-4A0A-88FF-0E300CF30B36}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "Entities\Entities.csproj", "{5E419E4F-99D1-47D6-B99D-A55B83B1CA47}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleUI", "ConsoleUI\ConsoleUI.csproj", "{5B1C290A-951A-4E16-B320-37B3939686C1}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{0749DD5E-80F8-4EE2-AA9A-1F8E0EE92BD9}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPI", "WebAPI\WebAPI.csproj", "{A1637A09-256A-47E8-8881-D68BA23A1170}" 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 20 | Debug|Any CPU = Debug|Any CPU 21 | Release|Any CPU = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 24 | {98AF19FC-77CE-4C4A-8EA0-1A67BBA2751B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {98AF19FC-77CE-4C4A-8EA0-1A67BBA2751B}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {98AF19FC-77CE-4C4A-8EA0-1A67BBA2751B}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {98AF19FC-77CE-4C4A-8EA0-1A67BBA2751B}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {6B26ECAE-E2ED-4A0A-88FF-0E300CF30B36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {6B26ECAE-E2ED-4A0A-88FF-0E300CF30B36}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {6B26ECAE-E2ED-4A0A-88FF-0E300CF30B36}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {6B26ECAE-E2ED-4A0A-88FF-0E300CF30B36}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {5E419E4F-99D1-47D6-B99D-A55B83B1CA47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {5E419E4F-99D1-47D6-B99D-A55B83B1CA47}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {5E419E4F-99D1-47D6-B99D-A55B83B1CA47}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {5E419E4F-99D1-47D6-B99D-A55B83B1CA47}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {5B1C290A-951A-4E16-B320-37B3939686C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {5B1C290A-951A-4E16-B320-37B3939686C1}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {5B1C290A-951A-4E16-B320-37B3939686C1}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {5B1C290A-951A-4E16-B320-37B3939686C1}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {0749DD5E-80F8-4EE2-AA9A-1F8E0EE92BD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {0749DD5E-80F8-4EE2-AA9A-1F8E0EE92BD9}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {0749DD5E-80F8-4EE2-AA9A-1F8E0EE92BD9}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {0749DD5E-80F8-4EE2-AA9A-1F8E0EE92BD9}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {A1637A09-256A-47E8-8881-D68BA23A1170}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {A1637A09-256A-47E8-8881-D68BA23A1170}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {A1637A09-256A-47E8-8881-D68BA23A1170}.Release|Any CPU.ActiveCfg = Release|Any CPU 47 | {A1637A09-256A-47E8-8881-D68BA23A1170}.Release|Any CPU.Build.0 = Release|Any CPU 48 | EndGlobalSection 49 | GlobalSection(SolutionProperties) = preSolution 50 | HideSolutionNode = FALSE 51 | EndGlobalSection 52 | GlobalSection(ExtensibilityGlobals) = postSolution 53 | SolutionGuid = {E31F0F37-C076-4A9A-83C5-EF7CC5C0F53A} 54 | EndGlobalSection 55 | EndGlobal 56 | -------------------------------------------------------------------------------- /WebAPI/Controllers/AuthController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.DTOs; 3 | using Microsoft.AspNetCore.Mvc; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | 9 | namespace WebAPI.Controllers 10 | { 11 | [Route("api/[controller]")] 12 | [ApiController] 13 | public class AuthController : Controller 14 | { 15 | IAuthService _authService; 16 | public AuthController(IAuthService authService) 17 | { 18 | _authService = authService; 19 | } 20 | 21 | [HttpPost("login")] 22 | public IActionResult Login(UserForLoginDto userForLoginDto) 23 | { 24 | var userCheckToLogin = _authService.Login(userForLoginDto); 25 | if (!userCheckToLogin.Success) 26 | { 27 | return BadRequest(userCheckToLogin.Message); 28 | } 29 | var result = _authService.CreateAccessToken(userCheckToLogin.Data); 30 | if (!result.Success) 31 | { 32 | return BadRequest(result.Message); 33 | } 34 | return Ok(result); 35 | } 36 | 37 | [HttpPost("register")] 38 | public IActionResult Register(UserForRegisterDto userForRegisterDto) 39 | { 40 | var userExistsCheck = _authService.UserExists(userForRegisterDto.Email); 41 | if (!userExistsCheck.Success) 42 | { 43 | return BadRequest(userExistsCheck.Message); 44 | } 45 | var userToRegister = _authService.Register(userForRegisterDto).Data; 46 | var result = _authService.CreateAccessToken(userToRegister); 47 | if (!result.Success) 48 | { 49 | return BadRequest(result.Message); 50 | } 51 | return Ok(result); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /WebAPI/Controllers/BrandsController.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 BrandsController : ControllerBase 15 | { 16 | //manager kullanırsak dependency chain olusur -- brandmanager ve efbranddal -- o yuzden ibrandservice 17 | IBrandService _brandService; 18 | public BrandsController(IBrandService brandService) 19 | { 20 | _brandService = brandService; 21 | } 22 | 23 | [HttpGet("getall")] //attribute 24 | public IActionResult GetAll() 25 | { 26 | var result = _brandService.GetAll(); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result); 32 | } 33 | 34 | [HttpGet("getbyid")] 35 | public IActionResult GetById(int id) 36 | { 37 | var result = _brandService.GetById(id); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result); 43 | } 44 | 45 | [HttpPost("add")] 46 | public IActionResult Add(Brand brand) 47 | { 48 | var result = _brandService.Add(brand); 49 | if (result.Success) 50 | { 51 | return Ok(result); 52 | } 53 | return BadRequest(result); 54 | } 55 | 56 | [HttpPost("delete")] 57 | public IActionResult Delete(Brand brand) 58 | { 59 | var result = _brandService.Delete(brand); 60 | if (result.Success) 61 | { 62 | return Ok(result); 63 | } 64 | return BadRequest(result); 65 | } 66 | 67 | [HttpPost("update")] 68 | public IActionResult Update(Brand brand) 69 | { 70 | var result = _brandService.Update(brand); 71 | if (result.Success) 72 | { 73 | return Ok(result); 74 | } 75 | return BadRequest(result); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /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 : Controller 15 | { 16 | ICarImageService _carImageService; 17 | public CarImagesController(ICarImageService carImageService) 18 | { 19 | _carImageService = carImageService; 20 | } 21 | 22 | [HttpPost("add")] 23 | public IActionResult Add([FromForm(Name = ("Image"))] IFormFile file, [FromForm] CarImage carImage) //form-data icin 24 | { 25 | var result = _carImageService.Add(file, carImage); 26 | if (result.Success) 27 | { 28 | return Ok(); 29 | } 30 | return BadRequest(); 31 | } 32 | [HttpPost("delete")] 33 | public IActionResult Delete([FromForm(Name = ("Id"))] int id) 34 | { 35 | var carImage = _carImageService.GetById(id).Data; 36 | var result = _carImageService.Delete(carImage); 37 | if (result.Success) 38 | { 39 | return Ok(); 40 | } 41 | return BadRequest(); 42 | } 43 | [HttpPost("update")] 44 | public IActionResult Update([FromForm(Name = ("Image"))] IFormFile file, [FromForm(Name = ("Id"))] int id) 45 | { 46 | var carImage = _carImageService.GetById(id).Data; 47 | var result = _carImageService.Update(file, carImage); 48 | if (result.Success) 49 | { 50 | return Ok(); 51 | } 52 | return BadRequest(); 53 | } 54 | [HttpGet("getbyid")] 55 | public IActionResult GetById(int id) 56 | { 57 | var result = _carImageService.GetById(id); 58 | if (result.Success) 59 | { 60 | return Ok(result); 61 | } 62 | return BadRequest(); 63 | } 64 | [HttpGet("getall")] 65 | public IActionResult GetAll() 66 | { 67 | var result = _carImageService.GetAll(); 68 | if (result.Success) 69 | { 70 | return Ok(result); 71 | } 72 | return BadRequest(); 73 | } 74 | [HttpGet("getphotosbycarid")] 75 | public IActionResult GetPhotosByCarId(int carId) 76 | { 77 | var result = _carImageService.GetPhotosByCarId(carId); 78 | if (result.Success) 79 | { 80 | return Ok(result); 81 | } 82 | return BadRequest(); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CarsController.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; 9 | using System.Threading.Tasks; 10 | 11 | namespace WebAPI.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | [ApiController] 15 | public class CarsController : ControllerBase 16 | { 17 | ICarService _carService; 18 | public CarsController(ICarService carService) 19 | { 20 | _carService = carService; 21 | } 22 | 23 | [HttpGet("getall")] 24 | public IActionResult GetAll() 25 | { 26 | var result = _carService.GetAll(); 27 | if (result.Success) // eğer success true ise 28 | { 29 | return Ok(result); //200 30 | } 31 | return BadRequest(result); //400 32 | } 33 | 34 | [HttpGet("getbyid")] 35 | public IActionResult GetById(int id) 36 | { 37 | var result = _carService.GetById(id); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result); 43 | } 44 | 45 | [HttpGet("getcarsbybrandid")] 46 | public IActionResult GetCarsByBrandId(int brandId) 47 | { 48 | var result = _carService.GetCarsByBrandId(brandId); 49 | if (result.Success) 50 | { 51 | return Ok(result); 52 | } 53 | return BadRequest(result); 54 | } 55 | 56 | [HttpGet("getcarsbycolorid")] 57 | public IActionResult GetCarsByColorId(int colorId) 58 | { 59 | var result = _carService.GetCarsDetailByColorId(colorId); 60 | if (result.Success) 61 | { 62 | return Ok(result); 63 | } 64 | return BadRequest(result); 65 | } 66 | 67 | [HttpGet("getcarsdetails")] 68 | public IActionResult GetCarsDetails() 69 | { 70 | var result = _carService.GetCarsDetails(); 71 | if (result.Success) 72 | { 73 | return Ok(result); 74 | } 75 | return BadRequest(result); 76 | } 77 | 78 | [HttpGet("getcarsdetailbybrandid")] 79 | public IActionResult GetCarsDetailByBrandId(int brandId) 80 | { 81 | var result = _carService.GetCarsDetailByBrandId(brandId); 82 | if (result.Success) 83 | { 84 | return Ok(result); 85 | } 86 | return BadRequest(result); 87 | } 88 | 89 | [HttpGet("getcarsdetailbycolorid")] 90 | public IActionResult GetCarsDetailByColorId(int colorId) 91 | { 92 | var result = _carService.GetCarsDetailByColorId(colorId); 93 | if (result.Success) 94 | { 95 | return Ok(result); 96 | } 97 | return BadRequest(result); 98 | } 99 | 100 | [HttpGet("getcarsdetailbycoloridandbrandid")] 101 | public IActionResult GetCarsDetailByColorIdAndBrandId(int colorId,int brandId) 102 | { 103 | var result = _carService.GetCarsDetailByColorIdAndBrandId(colorId,brandId); 104 | if (result.Success) 105 | { 106 | return Ok(result); 107 | } 108 | return BadRequest(result); 109 | } 110 | 111 | [HttpGet("getcardetailsbyid")] 112 | public IActionResult GetCarDetailById(int carId) 113 | { 114 | var result = _carService.GetCarDetailsById(carId); 115 | if (result.Success) 116 | { 117 | return Ok(result); 118 | } 119 | return BadRequest(result); 120 | } 121 | 122 | [HttpPost("add")] 123 | public IActionResult Add(Car car) 124 | { 125 | var result = _carService.Add(car); 126 | if (result.Success) 127 | { 128 | return Ok(result); 129 | } 130 | return BadRequest(result); 131 | } 132 | 133 | [HttpPost("delete")] 134 | public IActionResult Delete(Car car) 135 | { 136 | var result = _carService.Delete(car); 137 | if (result.Success) 138 | { 139 | return Ok(result); 140 | } 141 | return BadRequest(result); 142 | } 143 | 144 | [HttpPost("update")] 145 | public IActionResult Update(Car car) 146 | { 147 | var result = _carService.Update(car); 148 | if (result.Success) 149 | { 150 | return Ok(result); 151 | } 152 | return BadRequest(result); 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /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 | public ColorsController(IColorService colorService) 18 | { 19 | _colorService = colorService; 20 | } 21 | 22 | [HttpGet("getall")] 23 | public IActionResult GetAll() 24 | { 25 | var result = _colorService.GetAll(); 26 | if (result.Success) 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 = _colorService.GetById(id); 37 | if (result.Success) 38 | { 39 | return Ok(result); 40 | } 41 | return BadRequest(result); 42 | } 43 | 44 | [HttpPost("add")] 45 | public IActionResult Add(Color color) 46 | { 47 | var result = _colorService.Add(color); 48 | if (result.Success) 49 | { 50 | return Ok(result); 51 | } 52 | return BadRequest(result); 53 | } 54 | 55 | [HttpPost("delete")] 56 | public IActionResult Delete(Color color) 57 | { 58 | var result = _colorService.Delete(color); 59 | if (result.Success) 60 | { 61 | return Ok(result); 62 | } 63 | return BadRequest(result); 64 | } 65 | 66 | [HttpPost("update")] 67 | public IActionResult Update(Color color) 68 | { 69 | var result = _colorService.Update(color); 70 | if (result.Success) 71 | { 72 | return Ok(result); 73 | } 74 | return BadRequest(result); 75 | } 76 | 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CreditCardsController.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 CreditCardsController : ControllerBase 15 | { 16 | ICreditCardService _creditCardService; 17 | public CreditCardsController(ICreditCardService creditCardService) 18 | { 19 | _creditCardService = creditCardService; 20 | } 21 | 22 | [HttpPost("add")] 23 | public IActionResult Add(CreditCard creditCard) 24 | { 25 | var result = _creditCardService.Add(creditCard); 26 | if (result.Success) 27 | { 28 | return Ok(result); 29 | } 30 | return BadRequest(result); 31 | } 32 | [HttpPost("delete")] 33 | public IActionResult Delete(CreditCard creditCard) 34 | { 35 | var result = _creditCardService.Delete(creditCard); 36 | if (result.Success) 37 | { 38 | return Ok(result); 39 | } 40 | return BadRequest(result); 41 | } 42 | [HttpPost("update")] 43 | public IActionResult Update(CreditCard creditCard) 44 | { 45 | var result = _creditCardService.Update(creditCard); 46 | if (result.Success) 47 | { 48 | return Ok(result); 49 | } 50 | return BadRequest(result); 51 | } 52 | [HttpGet("getbycustomerid")] 53 | public IActionResult GetByCustomerId(int id) 54 | { 55 | var result = _creditCardService.GetByCustomerId(id); 56 | if (result.Success) 57 | { 58 | return Ok(result); 59 | } 60 | return BadRequest(result); 61 | } 62 | 63 | [HttpPost("getbynumber")] 64 | public IActionResult GetByNumber(string number) 65 | { 66 | var result = _creditCardService.GetByNumber(number); 67 | if (result.Success) 68 | { 69 | return Ok(result); 70 | } 71 | return BadRequest(result); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /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 | ICustomerService _customerService; 17 | public CustomersController(ICustomerService customerService) 18 | { 19 | _customerService = customerService; 20 | } 21 | 22 | [HttpGet("getall")] 23 | public IActionResult GetAll() 24 | { 25 | var result = _customerService.GetAll(); 26 | if (result.Success) 27 | { 28 | return Ok(result); 29 | } 30 | return BadRequest(result); 31 | } 32 | 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 | 45 | [HttpGet("getbyuserid")] 46 | public IActionResult GetByUserId(int id) 47 | { 48 | var result = _customerService.GetByUserId(id); 49 | if (result.Success) 50 | { 51 | return Ok(result); 52 | } 53 | return BadRequest(result); 54 | } 55 | 56 | [HttpPost("add")] 57 | public IActionResult Add(Customer customer) 58 | { 59 | var result = _customerService.Add(customer); 60 | if (result.Success) 61 | { 62 | return Ok(result); 63 | } 64 | return BadRequest(result); 65 | } 66 | 67 | [HttpPost("delete")] 68 | public IActionResult Delete(Customer customer) 69 | { 70 | var result = _customerService.Delete(customer); 71 | if (result.Success) 72 | { 73 | return Ok(result); 74 | } 75 | return BadRequest(result); 76 | } 77 | 78 | [HttpPost("update")] 79 | public IActionResult Update(Customer customer) 80 | { 81 | var result = _customerService.Update(customer); 82 | if (result.Success) 83 | { 84 | return Ok(result); 85 | } 86 | return BadRequest(result); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /WebAPI/Controllers/PaymentController.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 PaymentController : ControllerBase 15 | { 16 | IPaymentService _paymentService; 17 | 18 | public PaymentController(IPaymentService paymentService) 19 | { 20 | _paymentService = paymentService; 21 | } 22 | 23 | [HttpPost("payment")] 24 | public IActionResult Payment(CreditCard creditCard) 25 | { 26 | var result = _paymentService.Payment(creditCard); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /WebAPI/Controllers/RentalsController.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 RentalsController : ControllerBase 15 | { 16 | IRentalService _rentalService; 17 | public RentalsController(IRentalService rentalService) 18 | { 19 | _rentalService = rentalService; 20 | } 21 | 22 | [HttpGet("getall")] 23 | public IActionResult GetAll() 24 | { 25 | var result = _rentalService.GetAll(); 26 | if (result.Success) 27 | { 28 | return Ok(result); 29 | } 30 | return BadRequest(result); 31 | } 32 | 33 | [HttpPost("add")] 34 | public IActionResult Add(Rental rental) 35 | { 36 | var result = _rentalService.Add(rental); 37 | if (result.Success) 38 | { 39 | return Ok(result); 40 | } 41 | return BadRequest(result); 42 | } 43 | 44 | [HttpPost("delete")] 45 | public IActionResult Delete(Rental rental) 46 | { 47 | var result = _rentalService.Delete(rental); 48 | if (result.Success) 49 | { 50 | return Ok(result); 51 | } 52 | return BadRequest(result); 53 | } 54 | 55 | [HttpPost("update")] 56 | public IActionResult Update(Rental rental) 57 | { 58 | var result = _rentalService.Update(rental); 59 | if (result.Success) 60 | { 61 | return Ok(result); 62 | } 63 | return BadRequest(result); 64 | } 65 | 66 | 67 | [HttpGet("getrentaldetails")] 68 | public IActionResult GetRentalDetails() 69 | { 70 | var result = _rentalService.GetRentalDetails(); 71 | if (result.Success) 72 | { 73 | return Ok(result); 74 | } 75 | return BadRequest(result); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /WebAPI/Controllers/UsersController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Core.Entities.Concrete; 3 | using Entities.Concrete; 4 | using Entities.DTOs; 5 | using Microsoft.AspNetCore.Http; 6 | using Microsoft.AspNetCore.Mvc; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using System.Threading.Tasks; 11 | 12 | namespace WebAPI.Controllers 13 | { 14 | [Route("api/[controller]")] 15 | [ApiController] 16 | public class UsersController : ControllerBase 17 | { 18 | IUserService _userService; 19 | public UsersController(IUserService userService) 20 | { 21 | _userService = userService; 22 | } 23 | 24 | [HttpGet("getbyemail")] 25 | public IActionResult GetByEmail(string email) 26 | { 27 | var result = _userService.GetUserByEmail(email); 28 | if (result.Success) 29 | { 30 | return Ok(result); 31 | } 32 | return BadRequest(result); 33 | } 34 | 35 | [HttpGet("getuserbyemail")] 36 | public IActionResult GetUserByEmail(string email) 37 | { 38 | var result = _userService.GetUserDtoByEmail(email); 39 | if (result.Success) 40 | { 41 | return Ok(result); 42 | } 43 | return BadRequest(result); 44 | } 45 | 46 | 47 | [HttpGet("getall")] 48 | public IActionResult GetAll() 49 | { 50 | var result = _userService.GetAll(); 51 | if (result.Success) 52 | { 53 | return Ok(result); 54 | } 55 | return BadRequest(result); 56 | } 57 | 58 | [HttpPost("add")] 59 | public IActionResult Add(User user) 60 | { 61 | var result = _userService.Add(user); 62 | if (result.Success) 63 | { 64 | return Ok(result); 65 | } 66 | return BadRequest(result); 67 | } 68 | 69 | [HttpPost("delete")] 70 | public IActionResult Delete(User user) 71 | { 72 | var result = _userService.Delete(user); 73 | if (result.Success) 74 | { 75 | return Ok(result); 76 | } 77 | return BadRequest(result); 78 | } 79 | 80 | [HttpPost("edit")] 81 | public IActionResult EditProfile(UserEditedDto user) 82 | { 83 | var result = _userService.EditProfile(user); 84 | if (result.Success) 85 | { 86 | return Ok(result); 87 | } 88 | return BadRequest(result); 89 | } 90 | 91 | [HttpPost("update")] 92 | public IActionResult Update(User user) 93 | { 94 | var result = _userService.Update(user); 95 | if (result.Success) 96 | { 97 | return Ok(result); 98 | } 99 | return BadRequest(result); 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /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/Program.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/Program.cs -------------------------------------------------------------------------------- /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:51978", 8 | "sslPort": 44340 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "weatherforecast", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "WebAPI": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "weatherforecast", 24 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /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.Builder; 12 | using Microsoft.AspNetCore.Hosting; 13 | using Microsoft.AspNetCore.HttpsPolicy; 14 | using Microsoft.AspNetCore.Mvc; 15 | using Microsoft.Extensions.Configuration; 16 | using Microsoft.Extensions.DependencyInjection; 17 | using Microsoft.Extensions.Hosting; 18 | using Microsoft.Extensions.Logging; 19 | using Microsoft.IdentityModel.Tokens; 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Linq; 23 | using System.Threading.Tasks; 24 | 25 | namespace WebAPI 26 | { 27 | public class Startup 28 | { 29 | public Startup(IConfiguration configuration) 30 | { 31 | Configuration = configuration; 32 | } 33 | 34 | public IConfiguration Configuration { get; } 35 | 36 | // This method gets called by the runtime. Use this method to add services to the container. 37 | public void ConfigureServices(IServiceCollection services) 38 | { 39 | services.AddControllers(); 40 | 41 | services.AddCors(); 42 | 43 | var tokenOptions = Configuration.GetSection("TokenOptions").Get(); 44 | 45 | services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) 46 | .AddJwtBearer(options => 47 | { 48 | options.TokenValidationParameters = new TokenValidationParameters 49 | { 50 | ValidateIssuer = true, 51 | ValidateAudience = true, 52 | ValidateLifetime = true, 53 | ValidIssuer = tokenOptions.Issuer, 54 | ValidAudience = tokenOptions.Audience, 55 | ValidateIssuerSigningKey = true, 56 | IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) 57 | }; 58 | }); 59 | services.AddDependencyResolvers(new ICoreModule[] 60 | { 61 | new CoreModule() 62 | }); 63 | } 64 | 65 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 66 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 67 | { 68 | if (env.IsDevelopment()) 69 | { 70 | app.UseDeveloperExceptionPage(); 71 | } 72 | 73 | app.ConfigureCustomExceptionMiddleware(); 74 | 75 | app.UseCors(builder => builder.WithOrigins("http://localhost:4200").AllowAnyHeader()); 76 | 77 | app.UseHttpsRedirection(); 78 | 79 | app.UseRouting(); 80 | 81 | app.UseStaticFiles(); 82 | 83 | app.UseAuthentication(); 84 | 85 | app.UseAuthorization(); 86 | 87 | app.UseEndpoints(endpoints => 88 | { 89 | endpoints.MapControllers(); 90 | }); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /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 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /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": "tulin@tulin.com", 4 | "Issuer": "tulin@tulin.com", 5 | "AccesTokenExpiration": 10, 6 | "SecurityKey": "mysupersecretkeymysupersecretkey" 7 | }, 8 | 9 | "Logging": { 10 | "LogLevel": { 11 | "Default": "Information", 12 | "Microsoft": "Warning", 13 | "Microsoft.Hosting.Lifetime": "Information" 14 | } 15 | }, 16 | "AllowedHosts": "*" 17 | } 18 | -------------------------------------------------------------------------------- /WebAPI/libman.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "defaultProvider": "filesystem", 4 | "libraries": [ 5 | { 6 | "library": "CarImages/", 7 | "destination": "wwwroot/CarImages" 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/0ebac2f9-8b50-48ba-b817-d576495dbf3e.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/0ebac2f9-8b50-48ba-b817-d576495dbf3e.webp -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/0fbef1e4-4dbd-4176-b943-d5bbe695f42c.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/0fbef1e4-4dbd-4176-b943-d5bbe695f42c.webp -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/17fe3c1c-f757-4eda-839f-aff9c1fbfc7a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/17fe3c1c-f757-4eda-839f-aff9c1fbfc7a.png -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/18c07ed5-98da-4139-9f1d-957f8bbef56e.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/18c07ed5-98da-4139-9f1d-957f8bbef56e.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/1d2ed58c-ff94-44e5-a3ae-0627fa7078c3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/1d2ed58c-ff94-44e5-a3ae-0627fa7078c3.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/40ac70c9-586b-4d64-b64e-612895fe1225.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/40ac70c9-586b-4d64-b64e-612895fe1225.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/492e85af-e9bc-48c2-bb4b-e13d2a0b34cc.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/492e85af-e9bc-48c2-bb4b-e13d2a0b34cc.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/518dcefa-3e80-4fc5-912b-9fc94290948e.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/518dcefa-3e80-4fc5-912b-9fc94290948e.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/5928dc1d-41dd-4869-b679-9afe95bedad1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/5928dc1d-41dd-4869-b679-9afe95bedad1.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/5c5710fe-34ca-4d0c-ae62-da0988bb1f31.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/5c5710fe-34ca-4d0c-ae62-da0988bb1f31.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/641c8643-4e04-4be4-95a2-062dda3632c5.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/641c8643-4e04-4be4-95a2-062dda3632c5.jpeg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/b07161a2-4a2f-4595-b95c-855f081b02ed.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/b07161a2-4a2f-4595-b95c-855f081b02ed.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/b2b83108-0e5f-4c3d-8158-d7e18c68f5de.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/b2b83108-0e5f-4c3d-8158-d7e18c68f5de.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/be025d20-de97-477e-866d-1e8c3e87ddec.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/be025d20-de97-477e-866d-1e8c3e87ddec.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/c5a9de4f-2d3c-4d77-be3a-f88ff2000421.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/c5a9de4f-2d3c-4d77-be3a-f88ff2000421.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/cb7ad995-8f8d-4a15-bb0b-fc4e0f964055.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/cb7ad995-8f8d-4a15-bb0b-fc4e0f964055.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/d3a66c74-7ec2-4249-84ce-ece8bb1faf25.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/d3a66c74-7ec2-4249-84ce-ece8bb1faf25.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/d4d46fe1-7eac-4744-ac5a-d8671768b6fe.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/d4d46fe1-7eac-4744-ac5a-d8671768b6fe.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/e67a40cd-92fd-4dfc-a059-29ce018e0f82.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/e67a40cd-92fd-4dfc-a059-29ce018e0f82.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/eb0ea112-a333-4c9a-8e8c-671cd20bceaf.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/eb0ea112-a333-4c9a-8e8c-671cd20bceaf.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/f8454b08-0ba4-440c-bf78-b6d20ea916be.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/f8454b08-0ba4-440c-bf78-b6d20ea916be.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/fd320c24-c3b4-46cd-ab82-42cd628cd67a.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/fd320c24-c3b4-46cd-ab82-42cd628cd67a.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/CarImages/simge.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulinaktas/ReCapProject/a66c97892d26cf3d8dfff41995616bb78e0da969/WebAPI/wwwroot/CarImages/simge.jpg --------------------------------------------------------------------------------