├── .gitattributes ├── .gitignore ├── README.md ├── ReCapProject.Business ├── Abstract │ ├── IAuthService.cs │ ├── IBrandService.cs │ ├── ICarImageService.cs │ ├── ICarService.cs │ ├── IColorService.cs │ ├── ICustomerService.cs │ ├── IFakeCardService.cs │ ├── IRentalService.cs │ └── IUserService.cs ├── BusinessAspects │ └── Autofac │ │ └── SecuredOperation.cs ├── Concrete │ ├── AuthManager.cs │ ├── BrandManager.cs │ ├── CarImageManager.cs │ ├── CarManager.cs │ ├── ColorManager.cs │ ├── CustomerManager.cs │ ├── FakeCardManager.cs │ ├── RentalManager.cs │ └── UserManager.cs ├── Constants │ └── Messages.cs ├── DependencyResolvers │ └── Autofac │ │ └── AutofacBusinessModule.cs ├── ReCapProject.Business.csproj └── ValidationRules │ └── FluentValidation │ ├── BrandValidator.cs │ ├── CarImageValidator.cs │ ├── CarValidator.cs │ ├── ColorValidator.cs │ ├── CustomerValidator.cs │ ├── RentalValidator.cs │ └── UserValidator.cs ├── ReCapProject.Console ├── Program.cs └── ReCapProject.Console.csproj ├── ReCapProject.Core ├── Aspects │ ├── Caching │ │ ├── CacheAspect.cs │ │ └── CacheRemoveAspect.cs │ ├── Performance │ │ └── PerformanceAspect.cs │ ├── Transaction │ │ └── TransactionScopeAspect.cs │ └── Validation │ │ └── ValidationAspect.cs ├── CrossCuttingConcerns │ ├── Caching │ │ ├── ICacheManager.cs │ │ └── Microsoft │ │ │ └── MemoryCacheManager.cs │ └── Validation │ │ └── ValidationTool.cs ├── DataAccess │ ├── EntityFramework │ │ └── EfEntityRepositoryBase.cs │ └── IEntityRepository.cs ├── DependencyResolvers │ └── CoreModule.cs ├── Entities │ ├── Concrete │ │ ├── OperationClaim.cs │ │ ├── User.cs │ │ └── UserOperationClaim.cs │ ├── IDto.cs │ └── IEntity.cs ├── Extensions │ ├── ClaimExtensions.cs │ ├── ClaimsPrincipalExtensions.cs │ ├── ErrorDetails.cs │ ├── ExceptionMiddleware.cs │ ├── ExceptionMiddlewareExtensions.cs │ └── ServiceCollectionExtensions.cs ├── ReCapProject.Core.csproj └── Utilities │ ├── Business │ └── BusinessRules.cs │ ├── FileHelper │ └── FileHelper.cs │ ├── IoC │ ├── ICoreModule.cs │ └── ServiceTool.cs │ ├── Results │ ├── DataResult.cs │ ├── ErrorDataResult.cs │ ├── ErrorResult.cs │ ├── IDataResult.cs │ ├── IResult.cs │ ├── Result.cs │ ├── SuccessDataResult.cs │ └── SuccessResult.cs │ ├── Security │ ├── Encryption │ │ ├── SecurityKeyHelper.cs │ │ └── SigningCredentialsHelper.cs │ ├── Hashing │ │ └── HashingHelper.cs │ └── JWT │ │ ├── AccessToken.cs │ │ ├── ITokenHelper.cs │ │ ├── JwtHelper.cs │ │ └── TokenOptions.cs │ └── İnterceptors │ ├── AspectInterceptorSelector.cs │ ├── MethodInterception.cs │ └── MethodInterceptionBaseAttribute.cs ├── ReCapProject.DataAccess ├── Abstract │ ├── IBrandDal.cs │ ├── ICarDal.cs │ ├── ICarImageDal.cs │ ├── IColorDal.cs │ ├── ICustomerDal.cs │ ├── IFakeCardDal.cs │ ├── IRentalDal.cs │ └── IUserDal.cs ├── Concrete │ ├── EntityFramework │ │ ├── EfBrandDal.cs │ │ ├── EfCarDal.cs │ │ ├── EfCarImageDal.cs │ │ ├── EfColorDal.cs │ │ ├── EfCustomerDal.cs │ │ ├── EfFakeCardDal.cs │ │ ├── EfRentalDal.cs │ │ ├── EfUserDal.cs │ │ └── NorthwindContext.cs │ └── InMemory │ │ └── IMCarDal.cs └── ReCapProject.DataAccess.csproj ├── ReCapProject.Entities ├── Concrete │ ├── Brand.cs │ ├── Car.cs │ ├── CarImage.cs │ ├── Color.cs │ ├── Customer.cs │ ├── FakeCard.cs │ └── Rental.cs ├── DTOs │ ├── CarDetailDto.cs │ ├── CarImageDto.cs │ ├── CustomerDetailDto.cs │ ├── RentalDetailDto.cs │ ├── UserForLoginDto.cs │ └── UserForRegisterDto.cs └── ReCapProject.Entities.csproj ├── ReCapProject.sln └── WebAPI ├── Controllers ├── AuthController.cs ├── BrandsController.cs ├── CarImagesController.cs ├── CarsController.cs ├── ColorsController.cs ├── CustomersController.cs ├── FakeCardsController.cs ├── RentalsController.cs ├── UsersController.cs └── WeatherForecastController.cs ├── Program.cs ├── Properties └── launchSettings.json ├── Startup.cs ├── WeatherForecast.cs ├── WebAPI.csproj ├── appsettings.Development.json ├── appsettings.json └── wwwroot └── Images ├── 07f8041a153345ecac7dcb88090f6857.JPG ├── 083bdc5ad5b94464b21bcb7a20323658-3-8-2021.JPG ├── 3dd65d62c8e142fa95eaa4601e4128ad.JPG ├── cc53d921a7e04be6915308bff157acc0.JPG ├── d3e1d3b0a7cc4afaa43401a361316225-2-28-2021.JPG ├── d4f7916a8b444381a531f2f5ecbda9ae.JPG └── default.PNG /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ReCapProject (Rent A Car Back-end) 2 | 3 | 4 | ## Introduction 5 | While developing this project, 6 | I learned new techniques and patterns and I developed myself very well. If you need detailed information, you can contact me. 7 | 8 | ## Technologies Used 9 | - .NET 10 | - ASP.NET for Restful api 11 | - EntityFramework Core 12 | - Autofac 13 | - FluentValidation 14 | - MsSql 15 | 16 | ## Techniques 17 | - Layered Architecture Design Pattern 18 | - OOP 19 | - AOP 20 | - JWT 21 | - Autofac dependency resolver 22 | - IOC 23 | 24 | ## FluentValidation 25 | If you want to check content of entity when add, update etc. operations you can create validation for related entity. 26 | 27 | ## Aspects 28 | - ValidationAspect 29 | - CacheAspect 30 | - CacheRemoveAspect 31 | - PerformanceAspect 32 | - SecuredOperationAspect 33 | - TransactionAsepct
34 | You can understand better if you examine the classes in the concrete folder in the business layer. 35 | 36 | ## Database objects 37 | - Brand 38 | - Car 39 | - CarImage 40 | - Color 41 | - Customer 42 | - FakeCard 43 | - Rental 44 | - OperationClaim(In the core layer) 45 | - UserOperationClaim(In the core layer) 46 | - User(In the core layer) 47 | 48 | ## Nuget Packages and Their Versions 49 | - Autofac - Version = v6.1.0 50 | - Autofac.Extensions.DependencyInjection - Version = v7.1.0 51 | - Autofac.Extras.DynamicProxy - Version = v6.0.0 52 | - FluentValidation - Version = v9.5.1 53 | - Microsoft.AspNetCore.Authentication.JwtBearer - Version = v3.1.12 54 | - Microsoft.AspNetCore.Http - Version = v2.2.2 55 | - Microsoft.AspNetCore.Http.Abstractions - Version = v2.2.0 56 | - Microsoft.AspNetCore.Http.Features - Version = v5.0.3 57 | - Microsoft.EntityFrameworkCore.SqlServer - Version = v3.1.12 58 | - Microsoft.IdentityModel.Tokens - Version = v6.8.0 59 | - Newtonsoft.Json - Version = v13.0.1 60 | - System.IdentityModel.Tokens.Jwt - Version = v6.8.0 61 | 62 | 63 | -------------------------------------------------------------------------------- /ReCapProject.Business/Abstract/IAuthService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Entities.Concrete; 5 | using ReCapProject.Core.Utilities.Results; 6 | using ReCapProject.Core.Utilities.Security.JWT; 7 | using ReCapProject.Entities.DTOs; 8 | 9 | namespace ReCapProject.Business.Abstract 10 | { 11 | public interface IAuthService 12 | { 13 | IDataResult Register(UserForRegisterDto userForRegisterDto, string password); 14 | IDataResult Update(UserForRegisterDto userForRegisterDto, string password); 15 | IDataResult Login(UserForLoginDto userForLoginDto); 16 | IResult UserExists(string email); 17 | IDataResult CreateAccessToken(User user); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ReCapProject.Business/Abstract/IBrandService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Utilities.Results; 5 | using ReCapProject.Entities.Concrete; 6 | 7 | namespace ReCapProject.Business.Abstract 8 | { 9 | public interface IBrandService 10 | { 11 | IDataResult> GetAll(); 12 | IDataResult> GetBrandsByBrandId(int brandId); 13 | IDataResult> GetBrandsByName(string brandName); 14 | IResult Add(Brand brand); 15 | IResult Update(Brand brand); 16 | IResult Delete(Brand brand); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ReCapProject.Business/Abstract/ICarImageService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.AspNetCore.Http; 3 | using ReCapProject.Core.Utilities.Results; 4 | using ReCapProject.Entities.Concrete; 5 | 6 | namespace ReCapProject.Business.Abstract 7 | { 8 | public interface ICarImageService 9 | { 10 | IResult Add(CarImage carImage, IFormFile file); 11 | IResult Delete(CarImage carImage); 12 | IResult Update(CarImage carImage, IFormFile file); 13 | IDataResult> GetAll(); 14 | IDataResult> GetAllByCarId(int carId); 15 | IDataResult GetById(int id); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ReCapProject.Business/Abstract/ICarService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Utilities.Results; 5 | using ReCapProject.Entities.Concrete; 6 | using ReCapProject.Entities.DTOs; 7 | 8 | namespace ReCapProject.Business.Abstract 9 | { 10 | public interface ICarService 11 | { 12 | IDataResult> GetAll(); 13 | IDataResult> GetCarsByCarId(int carId); 14 | IDataResult> GetCarsByBrandId(int brandId); 15 | IDataResult> GetCarsByColorId(int colorId); 16 | IDataResult> GetCarDetailsByCarsId(int carId); 17 | IDataResult> GetCarsDetailsByBrandId(int brandId); 18 | IDataResult> GetCarsDetailsByColorId(int colorId); 19 | IDataResult> GetCarsDetailsByBrandIdAndColorId(int brandId, int colorId); 20 | IDataResult> GetCarDetails(); 21 | IResult Add(Car car); 22 | IResult Update(Car car); 23 | IResult Delete(int carId); 24 | IResult TransactionalOperation(Car car); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ReCapProject.Business/Abstract/IColorService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Utilities.Results; 5 | using ReCapProject.Entities.Concrete; 6 | 7 | namespace ReCapProject.Business.Abstract 8 | { 9 | public interface IColorService 10 | { 11 | IDataResult> GetAll(); 12 | IDataResult> GetColorsByColorId(int colorId); 13 | IResult Add(Color color); 14 | IResult Update(Color color); 15 | IResult Delete(Color color); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ReCapProject.Business/Abstract/ICustomerService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Utilities.Results; 5 | using ReCapProject.Entities.Concrete; 6 | using ReCapProject.Entities.DTOs; 7 | 8 | namespace ReCapProject.Business.Abstract 9 | { 10 | public interface ICustomerService 11 | { 12 | IDataResult> GetAll(); 13 | IDataResult> GetCustomerDetails(); 14 | IDataResult> GetCustomersByCustomerId(int customerId); 15 | IResult Add(Customer customer); 16 | IResult Update(Customer customer); 17 | IResult Delete(Customer customer); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /ReCapProject.Business/Abstract/IFakeCardService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Utilities.Results; 5 | using ReCapProject.Entities.Concrete; 6 | 7 | namespace ReCapProject.Business.Abstract 8 | { 9 | public interface IFakeCardService 10 | { 11 | IResult Add(FakeCard fakeCard); 12 | IResult Update(FakeCard fakeCard); 13 | IResult Delete(FakeCard fakeCard); 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int id); 16 | IDataResult> GetByCardNumber(string cardNumber); 17 | IResult IsCardExist(FakeCard fakeCard); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ReCapProject.Business/Abstract/IRentalService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Utilities.Results; 5 | using ReCapProject.Entities.Concrete; 6 | using ReCapProject.Entities.DTOs; 7 | 8 | namespace ReCapProject.Business.Abstract 9 | { 10 | public interface IRentalService 11 | { 12 | IDataResult> GetAll(); 13 | IDataResult> GetRentalsByRentalId(int rentalId); 14 | IDataResult> GetRentalDetails(); 15 | IDataResult> GetAllByCarId(int carId); 16 | IDataResult> GetAllByCustomerId(int customerId); 17 | IResult Add(Rental rental); 18 | IResult Update(Rental rental); 19 | IResult Delete(Rental rental); 20 | IResult IsDelivered(Rental rental); 21 | IResult IsRentable(Rental rental); 22 | Boolean Rentable(Rental rental); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ReCapProject.Business/Abstract/IUserService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Entities.Concrete; 5 | using ReCapProject.Core.Utilities.Results; 6 | using ReCapProject.Entities.Concrete; 7 | 8 | namespace ReCapProject.Business.Abstract 9 | { 10 | public interface IUserService 11 | { 12 | IDataResult> GetAll(); 13 | IDataResult> GetUsersByUserId(int userId); 14 | IDataResult> GetByEmail(string email); 15 | IDataResult> GetByName(string name); 16 | IResult Add(User user); 17 | IResult Update(User user); 18 | IResult Delete(User user); 19 | List GetClaims(User user); 20 | User GetByMail(string email); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ReCapProject.Business/BusinessAspects/Autofac/SecuredOperation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Castle.DynamicProxy; 5 | using Microsoft.AspNetCore.Http; 6 | using Microsoft.Extensions.DependencyInjection; 7 | using ReCapProject.Business.Constants; 8 | using ReCapProject.Core.Extensions; 9 | using ReCapProject.Core.Utilities.İnterceptors; 10 | using ReCapProject.Core.Utilities.IoC; 11 | 12 | namespace ReCapProject.Business.BusinessAspects.Autofac 13 | { 14 | public class SecuredOperation : MethodInterception 15 | { 16 | private string[] _roles; 17 | private IHttpContextAccessor _httpContextAccessor; 18 | 19 | public SecuredOperation(string roles) 20 | { 21 | _roles = roles.Split(','); 22 | _httpContextAccessor = ServiceTool.ServiceProvider.GetService(); 23 | 24 | } 25 | 26 | protected override void OnBefore(IInvocation invocation) 27 | { 28 | var roleClaims = _httpContextAccessor.HttpContext.User.ClaimRoles(); 29 | foreach (var role in _roles) 30 | { 31 | if (roleClaims.Contains(role)) 32 | { 33 | return; 34 | } 35 | } 36 | throw new Exception(Messages.AuthorizationDenied); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ReCapProject.Business/Concrete/AuthManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Business.Abstract; 5 | using ReCapProject.Business.Constants; 6 | using ReCapProject.Core.Entities.Concrete; 7 | using ReCapProject.Core.Utilities.Results; 8 | using ReCapProject.Core.Utilities.Security.Hashing; 9 | using ReCapProject.Core.Utilities.Security.JWT; 10 | using ReCapProject.Entities.DTOs; 11 | 12 | namespace ReCapProject.Business.Concrete 13 | { 14 | public class AuthManager : IAuthService 15 | { 16 | private IUserService _userService; 17 | private ITokenHelper _tokenHelper; 18 | 19 | public AuthManager(IUserService userService, ITokenHelper tokenHelper) 20 | { 21 | _userService = userService; 22 | _tokenHelper = tokenHelper; 23 | } 24 | 25 | public IDataResult Register(UserForRegisterDto userForRegisterDto, string password) 26 | { 27 | byte[] passwordHash, passwordSalt; 28 | HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt); 29 | var user = new User 30 | { 31 | Email = userForRegisterDto.Email, 32 | FirstName = userForRegisterDto.FirstName, 33 | LastName = userForRegisterDto.LastName, 34 | PasswordHash = passwordHash, 35 | PasswordSalt = passwordSalt, 36 | Status = true 37 | }; 38 | _userService.Add(user); 39 | return new SuccessDataResult(user, Messages.UserRegistered); 40 | } 41 | 42 | public IDataResult Update(UserForRegisterDto userForRegisterDto, string password) 43 | { 44 | byte[] passwordHash, passwordSalt; 45 | HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt); 46 | var user = new User 47 | { 48 | UserId = userForRegisterDto.Id, 49 | FirstName = userForRegisterDto.FirstName, 50 | LastName = userForRegisterDto.LastName, 51 | Email = userForRegisterDto.Email, 52 | PasswordSalt = passwordSalt, 53 | PasswordHash = passwordHash, 54 | Status = true 55 | }; 56 | _userService.Update(user); 57 | return new SuccessDataResult(user, Messages.Updated); 58 | } 59 | 60 | public IDataResult Login(UserForLoginDto userForLoginDto) 61 | { 62 | var userToCheck = _userService.GetByMail(userForLoginDto.Email); 63 | if (userToCheck == null) 64 | { 65 | return new ErrorDataResult(Messages.UserNotFound); 66 | } 67 | 68 | if (!HashingHelper.VerifyPasswordHash(userForLoginDto.Password, userToCheck.PasswordHash, userToCheck.PasswordSalt)) 69 | { 70 | return new ErrorDataResult(Messages.PasswordError); 71 | } 72 | 73 | return new SuccessDataResult(userToCheck, Messages.SuccessfulLogin); 74 | } 75 | 76 | public IResult UserExists(string email) 77 | { 78 | if (_userService.GetByMail(email) != null) 79 | { 80 | return new ErrorResult(Messages.UserAlreadyExists); 81 | } 82 | return new SuccessResult(); 83 | } 84 | 85 | public IDataResult CreateAccessToken(User user) 86 | { 87 | var claims = _userService.GetClaims(user); 88 | var accessToken = _tokenHelper.CreateToken(user, claims); 89 | return new SuccessDataResult(accessToken, Messages.AccessTokenCreated); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /ReCapProject.Business/Concrete/BrandManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Business.Abstract; 5 | using ReCapProject.Business.Constants; 6 | using ReCapProject.Business.ValidationRules.FluentValidation; 7 | using ReCapProject.Core.Aspects.Validation; 8 | using ReCapProject.Core.Utilities.Results; 9 | using ReCapProject.DataAccess.Abstract; 10 | using ReCapProject.Entities.Concrete; 11 | 12 | namespace ReCapProject.Business.Concrete 13 | { 14 | public class BrandManager:IBrandService 15 | { 16 | private IBrandDal _brandDal; 17 | 18 | public BrandManager(IBrandDal brandDal) 19 | { 20 | _brandDal = brandDal; 21 | } 22 | 23 | public IDataResult> GetAll() 24 | { 25 | return new SuccessDataResult>(_brandDal.GetAll(),Messages.Listed); 26 | } 27 | 28 | public IDataResult> GetBrandsByBrandId(int brandId) 29 | { 30 | return new SuccessDataResult>(_brandDal.GetAll(b=>b.BrandId==brandId)); 31 | } 32 | 33 | public IDataResult> GetBrandsByName(string brandName) 34 | { 35 | return new SuccessDataResult>(_brandDal.GetAll(b=>b.BrandName==brandName),Messages.Successful); 36 | } 37 | 38 | [ValidationAspect(typeof(BrandValidator))] 39 | public IResult Add(Brand brand) 40 | { 41 | _brandDal.Add(brand); 42 | return new SuccessResult(Messages.Added); 43 | } 44 | 45 | public IResult Update(Brand brand) 46 | { 47 | _brandDal.Update(brand); 48 | return new SuccessResult(Messages.Updated); 49 | } 50 | 51 | public IResult Delete(Brand brand) 52 | { 53 | _brandDal.Delete(brand); 54 | return new SuccessResult(Messages.Deleted); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ReCapProject.Business/Concrete/CarImageManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using Microsoft.AspNetCore.Http; 6 | using ReCapProject.Business.Abstract; 7 | using ReCapProject.Business.Constants; 8 | using ReCapProject.Business.ValidationRules.FluentValidation; 9 | using ReCapProject.Core.Aspects.Validation; 10 | using ReCapProject.Core.Utilities.Business; 11 | using ReCapProject.Core.Utilities.FileHelper; 12 | using ReCapProject.Core.Utilities.Results; 13 | using ReCapProject.DataAccess.Abstract; 14 | using ReCapProject.Entities.Concrete; 15 | 16 | namespace ReCapProject.Business.Concrete 17 | { 18 | public class CarImageManager : ICarImageService 19 | { 20 | ICarImageDal _carImageDal; 21 | 22 | public CarImageManager(ICarImageDal carImageDal) 23 | { 24 | _carImageDal = carImageDal; 25 | } 26 | 27 | [ValidationAspect(typeof(CarImageValidator))] 28 | public IResult Add(CarImage carImage, IFormFile file) 29 | { 30 | IResult result = BusinessRules.Run( 31 | CheckIfImageLimitExpired(carImage.CarId), 32 | CheckIfImageExtensionValid(file) 33 | ); 34 | 35 | if (result != null) 36 | { 37 | return result; 38 | } 39 | 40 | carImage.ImagePath = FileHelper.Add(file); 41 | carImage.Date = DateTime.Now; 42 | _carImageDal.Add(carImage); 43 | return new SuccessResult(); 44 | } 45 | 46 | public IResult Delete(CarImage carImage) 47 | { 48 | IResult result = BusinessRules.Run( 49 | CheckIfImageExists(carImage.Id) 50 | ); 51 | if (result != null) 52 | { 53 | return result; 54 | } 55 | string path = GetById(carImage.Id).Data.ImagePath; 56 | FileHelper.Delete(path); 57 | _carImageDal.Delete(carImage); 58 | return new SuccessResult(); 59 | } 60 | 61 | public IDataResult> GetAll() 62 | { 63 | return new SuccessDataResult>(_carImageDal.GetAll()); 64 | } 65 | 66 | public IDataResult> GetAllByCarId(int carId) 67 | { 68 | return new SuccessDataResult>(CheckIfCarHaveNoImage(carId)); 69 | } 70 | 71 | public IDataResult GetById(int id) 72 | { 73 | return new SuccessDataResult(_carImageDal.Get(c => c.Id == id)); 74 | } 75 | 76 | public IResult Update(CarImage carImage, IFormFile file) 77 | { 78 | IResult result = BusinessRules.Run( 79 | CheckIfImageLimitExpired(carImage.CarId), 80 | CheckIfImageExtensionValid(file), 81 | CheckIfImageExists(carImage.Id) 82 | ); 83 | 84 | if (result != null) 85 | { 86 | return result; 87 | } 88 | 89 | carImage.Date = DateTime.Now; 90 | string oldPath = GetById(carImage.Id).Data.ImagePath; 91 | FileHelper.Update(file, oldPath); 92 | _carImageDal.Update(carImage); 93 | return new SuccessResult(); 94 | } 95 | 96 | private IResult CheckIfImageLimitExpired(int carId) 97 | { 98 | int result = _carImageDal.GetAll(c => c.CarId == carId).Count; 99 | if (result >= 5) 100 | return new ErrorResult(Messages.ImageLimitExpiredForCar); 101 | return new SuccessResult(); 102 | } 103 | 104 | private IResult CheckIfImageExtensionValid(IFormFile file) 105 | { 106 | bool isValidFileExtension = Messages.ValidImageFileTypes.Any(t => t == Path.GetExtension(file.FileName).ToUpper()); 107 | if (!isValidFileExtension) 108 | return new ErrorResult(Messages.InvalidImageExtension); 109 | return new SuccessResult(); 110 | } 111 | 112 | private List CheckIfCarHaveNoImage(int carId) 113 | { 114 | string path = @"\Images\default.png"; /*Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName + @"\Images\default.png");*/ 115 | var result = _carImageDal.GetAll(c => c.CarId == carId); 116 | if (!result.Any()) 117 | return new List { new CarImage { CarId = carId, ImagePath = path } }; 118 | return result; 119 | } 120 | 121 | private IResult CheckIfImageExists(int id) 122 | { 123 | if (_carImageDal.IsExist(id)) 124 | return new SuccessResult(); 125 | return new ErrorResult(Messages.CarImageMustBeExists); 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /ReCapProject.Business/Concrete/CarManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ReCapProject.Business.Abstract; 6 | using ReCapProject.Business.BusinessAspects.Autofac; 7 | using ReCapProject.Business.Constants; 8 | using ReCapProject.Business.ValidationRules.FluentValidation; 9 | using ReCapProject.Core.Aspects.Caching; 10 | using ReCapProject.Core.Aspects.Performance; 11 | using ReCapProject.Core.Aspects.Transaction; 12 | using ReCapProject.Core.Aspects.Validation; 13 | using ReCapProject.Core.CrossCuttingConcerns.Validation; 14 | using ReCapProject.Core.Utilities.Business; 15 | using ReCapProject.Core.Utilities.Results; 16 | using ReCapProject.DataAccess.Abstract; 17 | using ReCapProject.Entities.Concrete; 18 | using ReCapProject.Entities.DTOs; 19 | 20 | namespace ReCapProject.Business.Concrete 21 | { 22 | public class CarManager : ICarService 23 | { 24 | private ICarDal _carDal; 25 | 26 | public CarManager(ICarDal carDal) 27 | { 28 | _carDal = carDal; 29 | } 30 | 31 | [CacheAspect] 32 | public IDataResult> GetAll() 33 | { 34 | //if (DateTime.Now.Hour==15) 35 | //{ 36 | // return new ErrorDataResult>(Messages.MaintenanceTime); 37 | //} 38 | return new SuccessDataResult>( _carDal.GetAll(),Messages.Listed); 39 | } 40 | 41 | [CacheAspect] 42 | //[PerformanceAspect(5)] Core katmanındaki AspectInterceptorSelector ekledim(Her methodu takip etsın diye) 43 | public IDataResult> GetCarsByCarId(int carId) 44 | { 45 | return new SuccessDataResult>( _carDal.GetAll(c => c.CarId == carId)); 46 | } 47 | 48 | public IDataResult> GetCarsByBrandId(int brandId) 49 | { 50 | return new SuccessDataResult>( _carDal.GetAll(c => c.BrandId == brandId)); 51 | } 52 | 53 | public IDataResult> GetCarsByColorId(int colorId) 54 | { 55 | return new SuccessDataResult>( _carDal.GetAll(c => c.ColorId == colorId)); 56 | } 57 | 58 | public IDataResult> GetCarDetailsByCarsId(int carId) 59 | { 60 | return new SuccessDataResult>(_carDal.GetCarDetails(c=>c.CarId==carId)); 61 | } 62 | 63 | public IDataResult> GetCarsDetailsByBrandId(int brandId) 64 | { 65 | return new SuccessDataResult>(_carDal.GetCarDetails(c=>c.BrandId==brandId)); 66 | } 67 | 68 | public IDataResult> GetCarsDetailsByColorId(int colorId) 69 | { 70 | return new SuccessDataResult>(_carDal.GetCarDetails(c=>c.ColorId==colorId)); 71 | } 72 | 73 | public IDataResult> GetCarsDetailsByBrandIdAndColorId(int brandId, int colorId) 74 | { 75 | return new SuccessDataResult>(_carDal.GetCarDetails(c => c.BrandId == brandId && c.ColorId==colorId)); 76 | } 77 | 78 | public IDataResult> GetCarDetails() 79 | { 80 | return new SuccessDataResult>( _carDal.GetCarDetails()); 81 | } 82 | 83 | [SecuredOperation("car.add,admin")] 84 | [ValidationAspect(typeof(CarValidator))] 85 | [CacheRemoveAspect("ICarService.Get")] 86 | public IResult Add(Car car) 87 | { 88 | IResult result = BusinessRules.Run(CheckIfProductNameExists(car.Description)); 89 | if (result!=null) 90 | { 91 | return result; 92 | } 93 | _carDal.Add(car); 94 | return new SuccessResult(Messages.Added); 95 | } 96 | 97 | [ValidationAspect(typeof(CarValidator))] 98 | [CacheRemoveAspect("ICarService.Get")] 99 | public IResult Update(Car car) 100 | { 101 | _carDal.Update(car); 102 | return new SuccessResult(Messages.Updated); 103 | } 104 | 105 | [CacheRemoveAspect("ICarService.Get")] 106 | public IResult Delete(int carId) 107 | { 108 | foreach (var id in _carDal.GetAll()) 109 | { 110 | if (id.CarId == carId) 111 | { 112 | _carDal.Delete(id); 113 | return new SuccessResult(Messages.Deleted); 114 | } 115 | } 116 | 117 | return new ErrorResult("Hata"); 118 | } 119 | 120 | [TransactionScopeAspect] 121 | public IResult TransactionalOperation(Car car) 122 | { 123 | _carDal.Update(car); 124 | _carDal.Add(car); 125 | return new SuccessResult(Messages.Updated); 126 | } 127 | 128 | private IResult CheckIfProductNameExists(string firstName) 129 | { 130 | var result = _carDal.GetAll(c => c.Description == firstName).Any(); 131 | if (result) 132 | { 133 | return new ErrorResult(Messages.ProductNameAlreadyExists); 134 | } 135 | return new SuccessResult(); 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /ReCapProject.Business/Concrete/ColorManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Business.Abstract; 5 | using ReCapProject.Business.Constants; 6 | using ReCapProject.Business.ValidationRules.FluentValidation; 7 | using ReCapProject.Core.Aspects.Validation; 8 | using ReCapProject.Core.Utilities.Results; 9 | using ReCapProject.DataAccess.Abstract; 10 | using ReCapProject.Entities.Concrete; 11 | 12 | namespace ReCapProject.Business.Concrete 13 | { 14 | public class ColorManager:IColorService 15 | { 16 | private IColorDal _colorDal; 17 | 18 | public ColorManager(IColorDal colorDal) 19 | { 20 | _colorDal = colorDal; 21 | } 22 | 23 | public IDataResult> GetAll() 24 | { 25 | return new SuccessDataResult>(_colorDal.GetAll(),Messages.Listed); 26 | } 27 | 28 | public IDataResult> GetColorsByColorId(int colorId) 29 | { 30 | return new SuccessDataResult>(_colorDal.GetAll(c=>c.ColorId==colorId)); 31 | } 32 | 33 | [ValidationAspect(typeof(ColorValidator))] 34 | public IResult Add(Color color) 35 | { 36 | _colorDal.Add(color); 37 | return new SuccessResult(Messages.Added); 38 | } 39 | 40 | public IResult Update(Color color) 41 | { 42 | _colorDal.Update(color); 43 | return new SuccessResult(Messages.Updated); 44 | } 45 | 46 | public IResult Delete(Color color) 47 | { 48 | _colorDal.Delete(color); 49 | return new SuccessResult(Messages.Deleted); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ReCapProject.Business/Concrete/CustomerManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Business.Abstract; 5 | using ReCapProject.Business.Constants; 6 | using ReCapProject.Business.ValidationRules.FluentValidation; 7 | using ReCapProject.Core.Aspects.Validation; 8 | using ReCapProject.Core.Utilities.Results; 9 | using ReCapProject.DataAccess.Abstract; 10 | using ReCapProject.Entities.Concrete; 11 | using ReCapProject.Entities.DTOs; 12 | 13 | namespace ReCapProject.Business.Concrete 14 | { 15 | public class CustomerManager:ICustomerService 16 | { 17 | private ICustomerDal _customerDal; 18 | 19 | public CustomerManager(ICustomerDal customerDal) 20 | { 21 | _customerDal = customerDal; 22 | } 23 | 24 | public IDataResult> GetAll() 25 | { 26 | return new SuccessDataResult>(_customerDal.GetAll(),Messages.Listed); 27 | } 28 | 29 | public IDataResult> GetCustomerDetails() 30 | { 31 | return new SuccessDataResult>(_customerDal.GetCustomerDetails()); 32 | } 33 | 34 | public IDataResult> GetCustomersByCustomerId(int customerId) 35 | { 36 | return new SuccessDataResult>(_customerDal.GetAll(c=>c.CustomerId==customerId)); 37 | } 38 | 39 | [ValidationAspect(typeof(CustomerValidator))] 40 | public IResult Add(Customer customer) 41 | { 42 | _customerDal.Add(customer); 43 | return new SuccessResult(Messages.Added); 44 | } 45 | 46 | public IResult Update(Customer customer) 47 | { 48 | _customerDal.Update(customer); 49 | return new SuccessResult(Messages.Updated); 50 | } 51 | 52 | public IResult Delete(Customer customer) 53 | { 54 | _customerDal.Delete(customer); 55 | return new SuccessResult(Messages.Deleted); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /ReCapProject.Business/Concrete/FakeCardManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Business.Abstract; 5 | using ReCapProject.Business.Constants; 6 | using ReCapProject.Core.Utilities.Results; 7 | using ReCapProject.DataAccess.Abstract; 8 | using ReCapProject.Entities.Concrete; 9 | 10 | namespace ReCapProject.Business.Concrete 11 | { 12 | public class FakeCardManager:IFakeCardService 13 | { 14 | private IFakeCardDal _fakeCardDal; 15 | 16 | public FakeCardManager(IFakeCardDal fakeCardDal) 17 | { 18 | _fakeCardDal = fakeCardDal; 19 | } 20 | 21 | public IResult Add(FakeCard fakeCard) 22 | { 23 | _fakeCardDal.Add(fakeCard); 24 | return new SuccessResult(Messages.Added); 25 | } 26 | 27 | public IResult Update(FakeCard fakeCard) 28 | { 29 | _fakeCardDal.Update(fakeCard); 30 | return new SuccessResult(Messages.Updated); 31 | } 32 | 33 | public IResult Delete(FakeCard fakeCard) 34 | { 35 | _fakeCardDal.Delete(fakeCard); 36 | return new SuccessResult(Messages.Deleted); 37 | } 38 | 39 | public IDataResult> GetAll() 40 | { 41 | return new SuccessDataResult>(_fakeCardDal.GetAll()); 42 | } 43 | 44 | public IDataResult GetById(int id) 45 | { 46 | return new SuccessDataResult(_fakeCardDal.Get(f=>f.Id==id)); 47 | } 48 | 49 | public IDataResult> GetByCardNumber(string cardNumber) 50 | { 51 | return new SuccessDataResult>(_fakeCardDal.GetAll(f=>f.CardNumber==cardNumber)); 52 | } 53 | 54 | public IResult IsCardExist(FakeCard fakeCard) 55 | { 56 | var result = _fakeCardDal.Get(f => 57 | f.CardNumber == fakeCard.CardName && f.CardNumber == fakeCard.CardNumber && 58 | f.CardCvv == fakeCard.CardCvv); 59 | 60 | if (result==null) 61 | { 62 | return new ErrorResult(); 63 | } 64 | return new SuccessResult(); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ReCapProject.Business/Concrete/RentalManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ReCapProject.Business.Abstract; 6 | using ReCapProject.Business.Constants; 7 | using ReCapProject.Business.ValidationRules.FluentValidation; 8 | using ReCapProject.Core.Aspects.Validation; 9 | using ReCapProject.Core.CrossCuttingConcerns.Validation; 10 | using ReCapProject.Core.Utilities.Results; 11 | using ReCapProject.DataAccess.Abstract; 12 | using ReCapProject.Entities.Concrete; 13 | using ReCapProject.Entities.DTOs; 14 | 15 | namespace ReCapProject.Business.Concrete 16 | { 17 | public class RentalManager : IRentalService 18 | { 19 | private IRentalDal _rentalDal; 20 | 21 | public RentalManager(IRentalDal rentalDal) 22 | { 23 | _rentalDal = rentalDal; 24 | } 25 | 26 | public IDataResult> GetAll() 27 | { 28 | return new SuccessDataResult>(_rentalDal.GetAll(), Messages.Listed); 29 | } 30 | 31 | public IDataResult> GetRentalsByRentalId(int rentalId) 32 | { 33 | return new SuccessDataResult>(_rentalDal.GetAll(r => r.RentalId == rentalId)); 34 | } 35 | 36 | public IDataResult> GetRentalDetails() 37 | { 38 | return new SuccessDataResult>(_rentalDal.GetRentalDetails()); 39 | } 40 | 41 | public IDataResult> GetAllByCarId(int carId) 42 | { 43 | return new SuccessDataResult>(_rentalDal.GetAll(r=>r.CarId==carId)); 44 | } 45 | 46 | public IDataResult> GetAllByCustomerId(int customerId) 47 | { 48 | return new SuccessDataResult>(_rentalDal.GetAll(r => r.CustomerId == customerId)); 49 | } 50 | 51 | [ValidationAspect(typeof(RentalValidator))] 52 | public IResult Add(Rental rental) 53 | { 54 | //İf in kapalı olan bölümünü RentalValidator de yazdım oyüzden burayı kapattım nasıl yazdığımı inceleyin diye silmedim. 55 | //if (/*rental.ReturnDate == null || */rental.RentDate.Date > rental.ReturnDate.Date) 56 | //{ 57 | // return new ErrorResult(Messages.CarNotRented); 58 | //} 59 | _rentalDal.Add(rental); 60 | return new SuccessResult(Messages.CarRented); 61 | } 62 | 63 | public IResult Update(Rental rental) 64 | { 65 | _rentalDal.Update(rental); 66 | return new SuccessResult(Messages.Updated); 67 | } 68 | 69 | public IResult Delete(Rental rental) 70 | { 71 | _rentalDal.Delete(rental); 72 | return new SuccessResult(Messages.Deleted); 73 | } 74 | 75 | public IResult IsDelivered(Rental rental) 76 | { 77 | var result = this.GetAllByCarId(rental.CarId).Data.LastOrDefault(); 78 | if (result==null || result.ReturnDate !=default) 79 | { 80 | return new SuccessResult(); 81 | } 82 | return new ErrorResult(); 83 | } 84 | 85 | public IResult IsRentable(Rental rental) 86 | { 87 | var result = this.GetAllByCarId(rental.CarId).Data.LastOrDefault(); 88 | if (IsDelivered(rental).Success || ( 89 | !(rental.RentDate < result.ReturnDate && rental.RentDate > result.RentDate) && 90 | !(rental.ReturnDate < result.ReturnDate && rental.ReturnDate > result.RentDate) && 91 | !(rental.RentDate < result.RentDate && rental.ReturnDate > result.ReturnDate) && 92 | rental.RentDate >= DateTime.Now)) 93 | { 94 | return new SuccessResult(); 95 | } 96 | return new ErrorResult(); 97 | } 98 | 99 | public bool Rentable(Rental rental) 100 | { 101 | var result = _rentalDal.GetAll(r => r.CarId == rental.CarId); 102 | if (result.Any(r=>r.RentEndDate >= rental.ReturnDate && 103 | r.RentDate <=rental.RentEndDate)) 104 | { 105 | return true; 106 | } 107 | 108 | return false; 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /ReCapProject.Business/Concrete/UserManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Business.Abstract; 5 | using ReCapProject.Business.Constants; 6 | using ReCapProject.Business.ValidationRules.FluentValidation; 7 | using ReCapProject.Core.Aspects.Validation; 8 | using ReCapProject.Core.Entities.Concrete; 9 | using ReCapProject.Core.Utilities.Results; 10 | using ReCapProject.DataAccess.Abstract; 11 | using ReCapProject.Entities.Concrete; 12 | 13 | namespace ReCapProject.Business.Concrete 14 | { 15 | public class UserManager:IUserService 16 | { 17 | private IUserDal _userDal; 18 | 19 | public UserManager(IUserDal userDal) 20 | { 21 | _userDal = userDal; 22 | } 23 | 24 | public IDataResult> GetAll() 25 | { 26 | return new SuccessDataResult>(_userDal.GetAll(),Messages.Listed); 27 | } 28 | 29 | public IDataResult> GetUsersByUserId(int userId) 30 | { 31 | return new SuccessDataResult>(_userDal.GetAll(u=>u.UserId==userId)); 32 | } 33 | 34 | public IDataResult> GetByEmail(string email) 35 | { 36 | return new SuccessDataResult>(_userDal.GetAll(u=>u.Email==email)); 37 | } 38 | 39 | public IDataResult> GetByName(string name) 40 | { 41 | return new SuccessDataResult>(_userDal.GetAll(u=>u.FirstName==name)); 42 | } 43 | 44 | [ValidationAspect(typeof(UserValidator))] 45 | public IResult Add(User user) 46 | { 47 | _userDal.Add(user); 48 | return new SuccessResult(Messages.Added); 49 | } 50 | 51 | public IResult Update(User user) 52 | { 53 | _userDal.Update(user); 54 | return new SuccessResult(Messages.Updated); 55 | } 56 | 57 | public IResult Delete(User user) 58 | { 59 | _userDal.Delete(user); 60 | return new SuccessResult(Messages.Deleted); 61 | } 62 | 63 | public List GetClaims(User user) 64 | { 65 | return _userDal.GetClaims(user); 66 | } 67 | 68 | public User GetByMail(string email) 69 | { 70 | return _userDal.Get(u => u.Email == email); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /ReCapProject.Business/Constants/Messages.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | using ReCapProject.Core.Entities.Concrete; 3 | 4 | namespace ReCapProject.Business.Constants 5 | { 6 | public static class Messages 7 | { 8 | public static string CarNameAndPriceInvalid = "Araç Modeli en az iki karakter ve Kiralama Ücreti sıfır liradan yüksek olmalıdır."; 9 | public static string Updated = "Güncellendi."; 10 | public static string Added = "Eklendi."; 11 | public static string Deleted = "Silindi."; 12 | public static string Listed = "Listelendi."; 13 | public static string Successful ="Başarılı"; 14 | public static string MaintenanceTime = "Site bakımdadır."; 15 | public static string CarNotRented = "Araç kiralanamadı."; 16 | public static string CarRented = "Araç kiralandı."; 17 | public static string ProductNameAlreadyExists = "Aynı isimde ürün bulunmaktadır."; 18 | public static string ImageLimit = "Fotoğraf limiti aşıldı."; 19 | public static string ImageLimitExpiredForCar = "Bir arabaya maximum 5 fotoğraf eklenebilir"; 20 | public static string[] ValidImageFileTypes = { ".JPG", ".JPEG", ".PNG", ".TIF", ".TIFF", ".GIF", ".BMP", ".ICO" }; 21 | public static string InvalidImageExtension = "Geçersiz dosya uzantısı, fotoğraf için kabul edilen uzantılar" + string.Join(",", ValidImageFileTypes); 22 | public static string CarImageMustBeExists = "Böyle bi resim bulunamadı"; 23 | public static string AuthorizationDenied = "Yetkiniz yok."; 24 | public static string UserRegistered = "Kullanıcı başarıyla kaydedildi"; 25 | public static string UserNotFound="Kullanıcı bulunamadı"; 26 | public static string PasswordError = "Şifre hatalı"; 27 | public static string SuccessfulLogin = "Sisteme giriş başarılı"; 28 | public static string UserAlreadyExists = "Bu kullanıcı zaten mevcut"; 29 | public static string AccessTokenCreated = "Access token başarıyla oluşturuldu"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ReCapProject.Business/DependencyResolvers/Autofac/AutofacBusinessModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Autofac; 5 | using Autofac.Extras.DynamicProxy; 6 | using Castle.DynamicProxy; 7 | using ReCapProject.Business.Abstract; 8 | using ReCapProject.Business.Concrete; 9 | using ReCapProject.Core.Utilities.İnterceptors; 10 | using ReCapProject.Core.Utilities.Security.JWT; 11 | using ReCapProject.DataAccess.Abstract; 12 | using ReCapProject.DataAccess.Concrete.EntityFramework; 13 | 14 | namespace ReCapProject.Business.DependencyResolvers.Autofac 15 | { 16 | public class AutofacBusinessModule:Module 17 | { 18 | protected override void Load(ContainerBuilder builder) 19 | { 20 | builder.RegisterType().As().SingleInstance(); 21 | builder.RegisterType().As().SingleInstance(); 22 | builder.RegisterType().As().SingleInstance(); 23 | builder.RegisterType().As().SingleInstance(); 24 | builder.RegisterType().As().SingleInstance(); 25 | builder.RegisterType().As().SingleInstance(); 26 | builder.RegisterType().As().SingleInstance(); 27 | builder.RegisterType().As().SingleInstance(); 28 | builder.RegisterType().As().SingleInstance(); 29 | builder.RegisterType().As().SingleInstance(); 30 | builder.RegisterType().As().SingleInstance(); 31 | builder.RegisterType().As().SingleInstance(); 32 | builder.RegisterType().As().SingleInstance(); 33 | builder.RegisterType().As().SingleInstance(); 34 | builder.RegisterType().As().SingleInstance(); 35 | builder.RegisterType().As().SingleInstance(); 36 | builder.RegisterType().As().SingleInstance(); 37 | builder.RegisterType().As().SingleInstance(); 38 | 39 | 40 | var assembly = System.Reflection.Assembly.GetExecutingAssembly(); 41 | 42 | builder.RegisterAssemblyTypes(assembly).AsImplementedInterfaces() 43 | .EnableInterfaceInterceptors(new ProxyGenerationOptions() 44 | { 45 | Selector = new AspectInterceptorSelector() 46 | }).SingleInstance(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ReCapProject.Business/ReCapProject.Business.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /ReCapProject.Business/ValidationRules/FluentValidation/BrandValidator.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | using ReCapProject.Entities.Concrete; 3 | 4 | namespace ReCapProject.Business.ValidationRules.FluentValidation 5 | { 6 | public class BrandValidator:AbstractValidator 7 | { 8 | public BrandValidator() 9 | { 10 | RuleFor(b => b.BrandName).NotEmpty(); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ReCapProject.Business/ValidationRules/FluentValidation/CarImageValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using FluentValidation; 5 | using ReCapProject.Entities.Concrete; 6 | 7 | namespace ReCapProject.Business.ValidationRules.FluentValidation 8 | { 9 | public class CarImageValidator:AbstractValidator 10 | { 11 | public CarImageValidator() 12 | { 13 | RuleFor(p => p.CarId).NotEmpty(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ReCapProject.Business/ValidationRules/FluentValidation/CarValidator.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | using ReCapProject.Entities.Concrete; 3 | 4 | namespace ReCapProject.Business.ValidationRules.FluentValidation 5 | { 6 | public class CarValidator:AbstractValidator 7 | { 8 | public CarValidator() 9 | { 10 | RuleFor(c => c.ColorId).NotEmpty(); 11 | RuleFor(c => c.BrandId).NotEmpty(); 12 | RuleFor(c => c.DailyPrice).NotEmpty(); 13 | RuleFor(c => c.DailyPrice).GreaterThan(0); 14 | RuleFor(c => c.ModelYear).NotEmpty(); 15 | RuleFor(c => c.Description).NotEmpty(); 16 | RuleFor(c => c.Description).MinimumLength(2); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ReCapProject.Business/ValidationRules/FluentValidation/ColorValidator.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | using ReCapProject.Entities.Concrete; 3 | 4 | namespace ReCapProject.Business.ValidationRules.FluentValidation 5 | { 6 | public class ColorValidator:AbstractValidator 7 | { 8 | public ColorValidator() 9 | { 10 | RuleFor(c => c.ColorName).NotEmpty(); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ReCapProject.Business/ValidationRules/FluentValidation/CustomerValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using FluentValidation; 5 | using ReCapProject.Entities.Concrete; 6 | 7 | namespace ReCapProject.Business.ValidationRules.FluentValidation 8 | { 9 | public class CustomerValidator:AbstractValidator 10 | { 11 | public CustomerValidator() 12 | { 13 | RuleFor(c => c.UserId).NotEmpty(); 14 | RuleFor(c => c.CompanyName).NotEmpty(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ReCapProject.Business/ValidationRules/FluentValidation/RentalValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using FluentValidation; 5 | using ReCapProject.Entities.Concrete; 6 | 7 | namespace ReCapProject.Business.ValidationRules.FluentValidation 8 | { 9 | public class RentalValidator:AbstractValidator 10 | { 11 | public RentalValidator() 12 | { 13 | RuleFor(r => r.CarId).NotEmpty(); 14 | RuleFor(r => r.CustomerId).NotEmpty(); 15 | RuleFor(r => r.RentDate).NotEmpty(); 16 | RuleFor(r => r.RentDate).Must(RentalDateCannotBeLessThanTodayDate).WithMessage("Verilen tarih bugünün tarihinden küçük olmamalıdır!"); 17 | RuleFor(r => r.ReturnDate).NotEmpty(); 18 | //RuleFor(r => r.ReturnDate).Must(DeliveryDateShouldBeGreater).WithMessage("Verilen tarih bugünün tarihinden büyük olmalıdır!"); 19 | } 20 | 21 | private bool RentalDateCannotBeLessThanTodayDate(DateTime arg) 22 | { 23 | return arg.Date >= DateTime.Today; 24 | } 25 | 26 | private bool DeliveryDateShouldBeGreater(DateTime arg) 27 | { 28 | return arg.Date > DateTime.Now; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ReCapProject.Business/ValidationRules/FluentValidation/UserValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using FluentValidation; 5 | using ReCapProject.Core.Entities.Concrete; 6 | using ReCapProject.Entities.Concrete; 7 | 8 | namespace ReCapProject.Business.ValidationRules.FluentValidation 9 | { 10 | public class UserValidator:AbstractValidator 11 | { 12 | public UserValidator() 13 | { 14 | RuleFor(u => u.FirstName).NotEmpty(); 15 | RuleFor(u => u.LastName).NotEmpty(); 16 | RuleFor(u => u.Email).NotEmpty(); 17 | RuleFor(u => u.Email).EmailAddress(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ReCapProject.Console/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using ReCapProject.Business.Concrete; 3 | using ReCapProject.Business.Constants; 4 | using ReCapProject.Core.Utilities.Results; 5 | using ReCapProject.DataAccess.Abstract; 6 | using ReCapProject.DataAccess.Concrete.EntityFramework; 7 | using ReCapProject.Entities.Concrete; 8 | 9 | namespace ReCapProject.Console 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | //CarAddUpdateDeleteTest(carManager); 16 | //CarManagerTest(); 17 | 18 | //RentalManagerAddTest(); 19 | //RentalUpdateTest(); 20 | } 21 | 22 | private static void RentalUpdateTest() 23 | { 24 | RentalManager rentalManager = new RentalManager(new EfRentalDal()); 25 | var result = rentalManager.Update(new Rental 26 | { 27 | RentalId = 1, 28 | CarId = 3, 29 | CustomerId = 1, 30 | RentDate = new DateTime(2021, 2, 15), 31 | ReturnDate = new DateTime(2021, 4, 11) 32 | }); 33 | System.Console.WriteLine(result.Message); 34 | } 35 | 36 | private static void RentalManagerAddTest() 37 | { 38 | RentalManager rentalManager = new RentalManager(new EfRentalDal()); 39 | var result = rentalManager.Add(new Rental 40 | { 41 | CarId = 2, 42 | CustomerId = 1, 43 | RentDate = new DateTime(2021, 3, 15), 44 | ReturnDate = new DateTime(2021, 5, 12) 45 | }); 46 | System.Console.WriteLine(result.Message); 47 | } 48 | 49 | private static void CarManagerTest() 50 | { 51 | CarManager carManager = new CarManager(new EfCarDal()); 52 | var result = carManager.GetAll(); 53 | 54 | if (result.Success) 55 | { 56 | foreach (var car in result.Data) 57 | { 58 | //Console.WriteLine("Marka:{0} Model:{1} Kiralama Ücreti:{2}",car.Description,car.ModelYear,car.DailyPrice ); 59 | System.Console.WriteLine("Araba Adı:{0} / Kiralama Ücreti:{1}", car.Description, car.DailyPrice); 60 | } 61 | } 62 | else 63 | { 64 | System.Console.WriteLine(result.Message); 65 | } 66 | } 67 | 68 | private static void CarAddUpdateDeleteTest(CarManager carManager) 69 | { 70 | //carManager.Add(new Car 71 | //{ 72 | // BrandId = 1, 73 | // ColorId = 2, 74 | // Description = "ugr", 75 | // DailyPrice = 152, 76 | // ModelYear = 2015 77 | //}); 78 | 79 | //carManager.Update(new Car 80 | //{ 81 | // CarId = 3, 82 | // BrandId = 2, 83 | // ColorId = 1, 84 | // Description = "ozan", 85 | // DailyPrice = 110, 86 | // ModelYear = 2016 87 | //}); 88 | 89 | //carManager.Delete(new Car 90 | //{ 91 | // CarId = 3, 92 | // BrandId = 2, 93 | // ColorId = 1, 94 | // Description = "Reno", 95 | // DailyPrice = 120, 96 | // ModelYear = 2016 97 | //} 98 | //); 99 | 100 | 101 | 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /ReCapProject.Console/ReCapProject.Console.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /ReCapProject.Core/Aspects/Caching/CacheAspect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Castle.DynamicProxy; 6 | using ReCapProject.Core.CrossCuttingConcerns.Caching; 7 | using ReCapProject.Core.Utilities.İnterceptors; 8 | using ReCapProject.Core.Utilities.IoC; 9 | using Microsoft.Extensions.DependencyInjection; 10 | 11 | namespace ReCapProject.Core.Aspects.Caching 12 | { 13 | public class CacheAspect : MethodInterception 14 | { 15 | private int _duration; 16 | private ICacheManager _cacheManager; 17 | 18 | public CacheAspect(int duration = 60) 19 | { 20 | _duration = duration; 21 | _cacheManager = ServiceTool.ServiceProvider.GetService(); 22 | } 23 | 24 | public override void Intercept(IInvocation invocation) 25 | { 26 | var methodName = string.Format($"{invocation.Method.ReflectedType.FullName}.{invocation.Method.Name}"); 27 | var arguments = invocation.Arguments.ToList(); 28 | var key = $"{methodName}({string.Join(",", arguments.Select(x => x?.ToString() ?? ""))})"; 29 | if (_cacheManager.IsAdd(key)) 30 | { 31 | invocation.ReturnValue = _cacheManager.Get(key); 32 | return; 33 | } 34 | invocation.Proceed(); 35 | _cacheManager.Add(key, invocation.ReturnValue, _duration); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ReCapProject.Core/Aspects/Caching/CacheRemoveAspect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Castle.DynamicProxy; 5 | using ReCapProject.Core.CrossCuttingConcerns.Caching; 6 | using ReCapProject.Core.Utilities.İnterceptors; 7 | using ReCapProject.Core.Utilities.IoC; 8 | using Microsoft.Extensions.DependencyInjection; 9 | 10 | namespace ReCapProject.Core.Aspects.Caching 11 | { 12 | public class CacheRemoveAspect : MethodInterception 13 | { 14 | private string _pattern; 15 | private ICacheManager _cacheManager; 16 | 17 | public CacheRemoveAspect(string pattern) 18 | { 19 | _pattern = pattern; 20 | _cacheManager = ServiceTool.ServiceProvider.GetService(); 21 | } 22 | 23 | protected override void OnSuccess(IInvocation invocation) 24 | { 25 | _cacheManager.RemoveByPattern(_pattern); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ReCapProject.Core/Aspects/Performance/PerformanceAspect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Text; 5 | using Castle.DynamicProxy; 6 | using Microsoft.Extensions.DependencyInjection; 7 | using ReCapProject.Core.Utilities.İnterceptors; 8 | using ReCapProject.Core.Utilities.IoC; 9 | 10 | namespace ReCapProject.Core.Aspects.Performance 11 | { 12 | public class PerformanceAspect:MethodInterception 13 | { 14 | private int _interval; 15 | private Stopwatch _stopwatch; 16 | 17 | public PerformanceAspect(int interval) 18 | { 19 | _interval = interval; 20 | _stopwatch = ServiceTool.ServiceProvider.GetService(); 21 | } 22 | 23 | 24 | protected override void OnBefore(IInvocation invocation) 25 | { 26 | _stopwatch.Start(); 27 | } 28 | 29 | protected override void OnAfter(IInvocation invocation) 30 | { 31 | if (_stopwatch.Elapsed.TotalSeconds > _interval) 32 | { 33 | Debug.WriteLine($"Performance : {invocation.Method.DeclaringType.FullName}.{invocation.Method.Name}-->{_stopwatch.Elapsed.TotalSeconds}"); 34 | } 35 | _stopwatch.Reset(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ReCapProject.Core/Aspects/Transaction/TransactionScopeAspect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Transactions; 5 | using Castle.DynamicProxy; 6 | using ReCapProject.Core.Utilities.İnterceptors; 7 | 8 | namespace ReCapProject.Core.Aspects.Transaction 9 | { 10 | public class TransactionScopeAspect:MethodInterception 11 | { 12 | public override void Intercept(IInvocation invocation) 13 | { 14 | using (TransactionScope transactionScope = new TransactionScope()) 15 | { 16 | try 17 | { 18 | invocation.Proceed(); 19 | transactionScope.Complete(); 20 | } 21 | catch (System.Exception e) 22 | { 23 | transactionScope.Dispose(); 24 | throw e; 25 | } 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ReCapProject.Core/Aspects/Validation/ValidationAspect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Castle.DynamicProxy; 6 | using FluentValidation; 7 | using ReCapProject.Core.CrossCuttingConcerns.Validation; 8 | using ReCapProject.Core.Utilities.İnterceptors; 9 | 10 | namespace ReCapProject.Core.Aspects.Validation 11 | { 12 | public class ValidationAspect : MethodInterception 13 | { 14 | private Type _validatorType; 15 | 16 | public ValidationAspect(Type validatorType) 17 | { 18 | if (!typeof(IValidator).IsAssignableFrom(validatorType)) 19 | { 20 | throw new System.Exception("Bu bir doğrulama sınıf değildir"); 21 | } 22 | _validatorType = validatorType; 23 | } 24 | 25 | protected override void OnBefore(IInvocation invocation) 26 | { 27 | var validator = (IValidator)Activator.CreateInstance(_validatorType); 28 | var entityType = _validatorType.BaseType.GetGenericArguments()[0]; 29 | var entities = invocation.Arguments.Where(t => t.GetType() == entityType); 30 | foreach (var entity in entities) 31 | { 32 | ValidationTool.Validate(validator, entity); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ReCapProject.Core/CrossCuttingConcerns/Caching/ICacheManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ReCapProject.Core.CrossCuttingConcerns.Caching 6 | { 7 | public interface ICacheManager 8 | { 9 | T Get(string key); 10 | object Get(string key); 11 | void Add(string key, object value, int duration); 12 | bool IsAdd(string key); 13 | void Remove(string key); 14 | void RemoveByPattern(string pattern); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ReCapProject.Core/CrossCuttingConcerns/Caching/Microsoft/MemoryCacheManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | using Microsoft.Extensions.Caching.Memory; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using ReCapProject.Core.Utilities.IoC; 9 | 10 | namespace ReCapProject.Core.CrossCuttingConcerns.Caching.Microsoft 11 | { 12 | public class MemoryCacheManager : ICacheManager 13 | { 14 | private IMemoryCache _memoryCache; 15 | 16 | public MemoryCacheManager() 17 | { 18 | _memoryCache = ServiceTool.ServiceProvider.GetService(); 19 | } 20 | 21 | public T Get(string key) 22 | { 23 | return _memoryCache.Get(key); 24 | } 25 | 26 | public object Get(string key) 27 | { 28 | return _memoryCache.Get(key); 29 | } 30 | 31 | public void Add(string key, object value, int duration) 32 | { 33 | _memoryCache.Set(key, value, TimeSpan.FromMinutes(duration)); 34 | } 35 | 36 | public bool IsAdd(string key) 37 | { 38 | return _memoryCache.TryGetValue(key, out _); 39 | } 40 | 41 | public void Remove(string key) 42 | { 43 | _memoryCache.Remove(key); 44 | } 45 | 46 | public void RemoveByPattern(string pattern) 47 | { 48 | var cacheEntriesCollectionDefinition = typeof(MemoryCache).GetProperty("EntriesCollection", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); 49 | var cacheEntriesCollection = cacheEntriesCollectionDefinition.GetValue(_memoryCache) as dynamic; 50 | List cacheCollectionValues = new List(); 51 | 52 | foreach (var cacheItem in cacheEntriesCollection) 53 | { 54 | ICacheEntry cacheItemValue = cacheItem.GetType().GetProperty("Value").GetValue(cacheItem, null); 55 | cacheCollectionValues.Add(cacheItemValue); 56 | } 57 | 58 | var regex = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase); 59 | var keysToRemove = cacheCollectionValues.Where(d => regex.IsMatch(d.Key.ToString())).Select(d => d.Key).ToList(); 60 | 61 | foreach (var key in keysToRemove) 62 | { 63 | _memoryCache.Remove(key); 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ReCapProject.Core/CrossCuttingConcerns/Validation/ValidationTool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using FluentValidation; 5 | 6 | namespace ReCapProject.Core.CrossCuttingConcerns.Validation 7 | { 8 | public static class ValidationTool 9 | { 10 | public static void Validate(IValidator validator,object entity) 11 | { 12 | var context=new ValidationContext(entity); 13 | var result = validator.Validate(context); 14 | if (!result.IsValid) 15 | { 16 | throw new ValidationException(result.Errors); 17 | } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ReCapProject.Core/DataAccess/EntityFramework/EfEntityRepositoryBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Text; 6 | using Microsoft.EntityFrameworkCore; 7 | using ReCapProject.Core.Entities; 8 | 9 | namespace ReCapProject.Core.DataAccess.EntityFramework 10 | { 11 | public class EfEntityRepositoryBase:IEntityRepository 12 | where TEntity:class,IEntity,new() 13 | where TContext:DbContext,new() 14 | { 15 | public List GetAll(Expression> filter = null) 16 | { 17 | using (TContext context = new TContext()) 18 | { 19 | return filter == null 20 | ? context.Set().ToList() 21 | : context.Set().Where(filter).ToList(); 22 | } 23 | } 24 | 25 | public TEntity Get(Expression> filter) 26 | { 27 | using (TContext context = new TContext()) 28 | { 29 | return context.Set().SingleOrDefault(filter); 30 | } 31 | } 32 | 33 | public void Add(TEntity entity) 34 | { 35 | using (TContext context = new TContext()) 36 | { 37 | var addedEntity = context.Entry(entity); 38 | addedEntity.State = EntityState.Added; 39 | context.SaveChanges(); 40 | 41 | } 42 | } 43 | 44 | public void Update(TEntity entity) 45 | { 46 | using (TContext context = new TContext()) 47 | { 48 | var updatedEntity = context.Entry(entity); 49 | updatedEntity.State = EntityState.Modified; 50 | context.SaveChanges(); 51 | } 52 | } 53 | 54 | public void Delete(TEntity entity) 55 | { 56 | using (TContext context = new TContext()) 57 | { 58 | var deletedEntity = context.Entry(entity); 59 | deletedEntity.State = EntityState.Deleted; 60 | context.SaveChanges(); 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /ReCapProject.Core/DataAccess/IEntityRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using ReCapProject.Core.Entities; 5 | 6 | namespace ReCapProject.Core.DataAccess 7 | { 8 | public interface IEntityRepository where T:class,IEntity,new() 9 | { 10 | List GetAll(Expression> filter=null); 11 | T Get(Expression> filter); 12 | void Add(T entity); 13 | void Update(T entity); 14 | void Delete(T entity); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ReCapProject.Core/DependencyResolvers/CoreModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Text; 5 | using Microsoft.AspNetCore.Http; 6 | using Microsoft.Extensions.DependencyInjection; 7 | using ReCapProject.Core.CrossCuttingConcerns.Caching; 8 | using ReCapProject.Core.CrossCuttingConcerns.Caching.Microsoft; 9 | using ReCapProject.Core.Utilities.IoC; 10 | 11 | namespace ReCapProject.Core.DependencyResolvers 12 | { 13 | public class CoreModule:ICoreModule 14 | { 15 | public void Load(IServiceCollection serviceCollection) 16 | { 17 | serviceCollection.AddMemoryCache(); 18 | serviceCollection.AddSingleton(); 19 | serviceCollection.AddSingleton(); 20 | serviceCollection.AddSingleton(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ReCapProject.Core/Entities/Concrete/OperationClaim.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ReCapProject.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 | -------------------------------------------------------------------------------- /ReCapProject.Core/Entities/Concrete/User.cs: -------------------------------------------------------------------------------- 1 | namespace ReCapProject.Core.Entities.Concrete 2 | { 3 | public class User:IEntity 4 | { 5 | public int UserId { get; set; } 6 | public string FirstName { get; set; } 7 | public string LastName { get; set; } 8 | public string Email { get; set; } 9 | public byte[] PasswordHash { get; set; } 10 | public byte[] PasswordSalt { get; set; } 11 | public bool Status { get; set; } 12 | public int Findeks { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ReCapProject.Core/Entities/Concrete/UserOperationClaim.cs: -------------------------------------------------------------------------------- 1 | namespace ReCapProject.Core.Entities.Concrete 2 | { 3 | public class UserOperationClaim:IEntity 4 | { 5 | public int Id { get; set; } 6 | public int UserId { get; set; } 7 | public int OperationClaimId { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /ReCapProject.Core/Entities/IDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ReCapProject.Core.Entities 6 | { 7 | public interface IDto 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /ReCapProject.Core/Entities/IEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ReCapProject.Core.Entities 6 | { 7 | public interface IEntity 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /ReCapProject.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 ReCapProject.Core.Extensions 9 | { 10 | public static class ClaimExtensions 11 | { 12 | public static void AddEmail(this ICollection claims, string email) 13 | { 14 | claims.Add(new Claim(JwtRegisteredClaimNames.Email,email)); 15 | } 16 | 17 | public static void AddName(this ICollection claims, string name) 18 | { 19 | claims.Add(new Claim(ClaimTypes.Name,name)); 20 | } 21 | 22 | public static void AddNameIdentifier(this ICollection claims, string nameIdentifier) 23 | { 24 | claims.Add(new Claim(ClaimTypes.NameIdentifier,nameIdentifier)); 25 | } 26 | 27 | public static void AddRoles(this ICollection claims, string[] roles) 28 | { 29 | roles.ToList().ForEach(role=>claims.Add(new Claim(ClaimTypes.Role,role))); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ReCapProject.Core/Extensions/ClaimsPrincipalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Claims; 5 | using System.Text; 6 | 7 | namespace ReCapProject.Core.Extensions 8 | { 9 | public static class ClaimsPrincipalExtensions 10 | { 11 | public static List Claims(this ClaimsPrincipal claimsPrincipal,string claimType) 12 | { 13 | var result = claimsPrincipal?.FindAll(claimType)?.Select(x => x.Value).ToList(); 14 | return result; 15 | } 16 | 17 | public static List ClaimRoles(this ClaimsPrincipal claimsPrincipal) 18 | { 19 | return claimsPrincipal?.Claims(ClaimTypes.Role); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ReCapProject.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 ReCapProject.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 Errors { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ReCapProject.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 ReCapProject.Core.Extensions 11 | { 12 | public class ExceptionMiddleware 13 | { 14 | private RequestDelegate _next; 15 | 16 | public ExceptionMiddleware(RequestDelegate next) 17 | { 18 | _next = next; 19 | } 20 | 21 | public async Task InvokeAsync(HttpContext httpContext) 22 | { 23 | try 24 | { 25 | await _next(httpContext); 26 | } 27 | catch (Exception e) 28 | { 29 | await HandleExceptionAsync(httpContext, e); 30 | } 31 | } 32 | 33 | private Task HandleExceptionAsync(HttpContext httpContext, Exception e) 34 | { 35 | httpContext.Response.ContentType = "application/json"; 36 | httpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; 37 | 38 | string message = "Internal Server Error"; 39 | IEnumerable errors; 40 | if (e.GetType() == typeof(ValidationException)) 41 | { 42 | message = e.Message; 43 | errors = ((ValidationException) e).Errors; 44 | httpContext.Response.StatusCode = 400; 45 | 46 | return httpContext.Response.WriteAsync(new ValidationErrorDetails 47 | { 48 | StatusCode = 400, 49 | Message = message, 50 | Errors=errors 51 | }.ToString()); 52 | } 53 | 54 | return httpContext.Response.WriteAsync(new ErrorDetails 55 | { 56 | StatusCode = httpContext.Response.StatusCode, 57 | Message = message 58 | }.ToString()); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /ReCapProject.Core/Extensions/ExceptionMiddlewareExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.AspNetCore.Builder; 5 | 6 | namespace ReCapProject.Core.Extensions 7 | { 8 | public static class ExceptionMiddlewareExtensions 9 | { 10 | public static void ConfigureCustomExceptionMiddleware(this IApplicationBuilder app) 11 | { 12 | app.UseMiddleware(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ReCapProject.Core/Extensions/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using ReCapProject.Core.Utilities.IoC; 6 | 7 | namespace ReCapProject.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 | 19 | return ServiceTool.Create(serviceCollection); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ReCapProject.Core/ReCapProject.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/Business/BusinessRules.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Utilities.Results; 5 | 6 | namespace ReCapProject.Core.Utilities.Business 7 | { 8 | public class BusinessRules 9 | { 10 | public static IResult Run(params IResult[] logics) 11 | { 12 | foreach (var logic in logics) 13 | { 14 | if (!logic.Success) 15 | { 16 | return logic; 17 | } 18 | } 19 | 20 | return null; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/FileHelper/FileHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using Microsoft.AspNetCore.Http; 4 | using ReCapProject.Core.Utilities.Results; 5 | 6 | namespace ReCapProject.Core.Utilities.FileHelper 7 | { 8 | public class FileHelper 9 | { 10 | static string directory = Directory.GetCurrentDirectory() + @"\wwwroot\"; 11 | static string path = @"Images\"; 12 | public static string Add(IFormFile file) 13 | { 14 | string extension = Path.GetExtension(file.FileName).ToUpper(); 15 | string newFileName = Guid.NewGuid().ToString("N") + extension; 16 | if (!Directory.Exists(directory + path)) 17 | { 18 | Directory.CreateDirectory(directory + path); 19 | } 20 | using (FileStream fileStream = File.Create(directory + path + newFileName)) 21 | { 22 | file.CopyTo(fileStream); 23 | fileStream.Flush(); 24 | } 25 | return (path + newFileName).Replace("\\", "/"); 26 | } 27 | 28 | public static string Update(IFormFile file, string oldImagePath) 29 | { 30 | Delete(oldImagePath); 31 | return Add(file); 32 | } 33 | 34 | public static void Delete(string imagePath) 35 | { 36 | if (File.Exists(directory + imagePath.Replace("/", "\\")) 37 | && Path.GetFileName(imagePath) != "default.png") 38 | { 39 | File.Delete(directory + imagePath.Replace("/", "\\")); 40 | } 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /ReCapProject.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 ReCapProject.Core.Utilities.IoC 7 | { 8 | public interface ICoreModule 9 | { 10 | void Load(IServiceCollection serviceCollection); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ReCapProject.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 ReCapProject.Core.Utilities.IoC 7 | { 8 | public static class ServiceTool 9 | { 10 | public static IServiceProvider ServiceProvider { get; private set; } 11 | 12 | public static IServiceCollection Create(IServiceCollection services) 13 | { 14 | ServiceProvider = services.BuildServiceProvider(); 15 | return services; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/Results/DataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ReCapProject.Core.Utilities.Results 6 | { 7 | public class DataResult:Result,IDataResult 8 | { 9 | public DataResult(T data,bool success,string message):base(success,message) 10 | { 11 | Data = data; 12 | } 13 | 14 | public DataResult(T data,bool success):base(success) 15 | { 16 | Data = data; 17 | } 18 | 19 | public T Data { get; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/Results/ErrorDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ReCapProject.Core.Utilities.Results 6 | { 7 | public class ErrorDataResult:DataResult 8 | { 9 | public ErrorDataResult(T data,string message):base(data,false,message) 10 | { 11 | 12 | } 13 | 14 | public ErrorDataResult(T data):base(data,false) 15 | { 16 | 17 | } 18 | 19 | public ErrorDataResult(string message):base(default,false,message) 20 | { 21 | 22 | } 23 | 24 | public ErrorDataResult():base(default,false) 25 | { 26 | 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/Results/ErrorResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ReCapProject.Core.Utilities.Results 6 | { 7 | public class ErrorResult:Result 8 | { 9 | public ErrorResult(string message):base(false,message) 10 | { 11 | 12 | } 13 | 14 | public ErrorResult():base(false) 15 | { 16 | 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/Results/IDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ReCapProject.Core.Utilities.Results 6 | { 7 | public interface IDataResult:IResult 8 | { 9 | T Data { get; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/Results/IResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ReCapProject.Core.Utilities.Results 6 | { 7 | public interface IResult 8 | { 9 | bool Success { get; } 10 | string Message { get; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/Results/Result.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ReCapProject.Core.Utilities.Results 6 | { 7 | public class Result:IResult 8 | { 9 | public Result(bool success,string message):this(success) 10 | { 11 | Message = message; 12 | } 13 | 14 | public Result(bool success) 15 | { 16 | Success = success; 17 | } 18 | public bool Success { get; } 19 | public string Message { get; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/Results/SuccessDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ReCapProject.Core.Utilities.Results 6 | { 7 | public class SuccessDataResult:DataResult 8 | { 9 | public SuccessDataResult(T data,string message):base(data, true, message) 10 | { 11 | 12 | } 13 | 14 | public SuccessDataResult(T data):base(data,true) 15 | { 16 | 17 | } 18 | 19 | public SuccessDataResult(string message):base(default,true,message) 20 | { 21 | 22 | } 23 | 24 | public SuccessDataResult():base(default,true) 25 | { 26 | 27 | } 28 | 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/Results/SuccessResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ReCapProject.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 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/Security/Encryption/SecurityKeyHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.IdentityModel.Tokens; 5 | 6 | namespace ReCapProject.Core.Utilities.Security.Encryption 7 | { 8 | public class SecurityKeyHelper 9 | { 10 | public static SecurityKey CreateSecurityKey(string securityKey) 11 | { 12 | return new SymmetricSecurityKey(Encoding.UTF8.GetBytes(securityKey)); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/Security/Encryption/SigningCredentialsHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.IdentityModel.Tokens; 5 | 6 | namespace ReCapProject.Core.Utilities.Security.Encryption 7 | { 8 | public class SigningCredentialsHelper 9 | { 10 | public static SigningCredentials CreateSigningCredentials(SecurityKey securityKey) 11 | { 12 | return new SigningCredentials(securityKey,SecurityAlgorithms.HmacSha512Signature); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/Security/Hashing/HashingHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ReCapProject.Core.Utilities.Security.Hashing 6 | { 7 | public 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 VerifyPasswordHash(string password, byte[] passwordHash, byte[] passwordSalt) 19 | { 20 | using (var hmac = new System.Security.Cryptography.HMACSHA512(passwordSalt)) 21 | { 22 | var computedHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(password)); 23 | for (int i = 0; i < computedHash.Length; i++) 24 | { 25 | if (computedHash[i]!=passwordHash[i]) 26 | { 27 | return false; 28 | } 29 | } 30 | 31 | return true; 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/Security/JWT/AccessToken.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ReCapProject.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 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/Security/JWT/ITokenHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Entities.Concrete; 5 | 6 | namespace ReCapProject.Core.Utilities.Security.JWT 7 | { 8 | public interface ITokenHelper 9 | { 10 | AccessToken CreateToken(User user, List operationClaims); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/Security/JWT/JwtHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IdentityModel.Tokens.Jwt; 4 | using System.Linq; 5 | using System.Security.Claims; 6 | using System.Text; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.IdentityModel.Tokens; 9 | using ReCapProject.Core.Entities.Concrete; 10 | using ReCapProject.Core.Extensions; 11 | using ReCapProject.Core.Utilities.Security.Encryption; 12 | 13 | namespace ReCapProject.Core.Utilities.Security.JWT 14 | { 15 | public class JwtHelper:ITokenHelper 16 | { 17 | public IConfiguration Configuration { get; } 18 | private TokenOptions _tokenOptions; 19 | private DateTime _accessTokenExpiration; 20 | 21 | public JwtHelper(IConfiguration configuration) 22 | { 23 | Configuration = configuration; 24 | _tokenOptions = Configuration.GetSection("TokenOptions").Get(); 25 | } 26 | 27 | public AccessToken CreateToken(User user, List operationClaims) 28 | { 29 | _accessTokenExpiration=DateTime.Now.AddMinutes(_tokenOptions.AccessTokenExpiration); 30 | var securityKey = SecurityKeyHelper.CreateSecurityKey(_tokenOptions.SecurityKey); 31 | var signingCredentials = SigningCredentialsHelper.CreateSigningCredentials(securityKey); 32 | var jwt = CreateJwtSecurityToken(_tokenOptions, user, signingCredentials, operationClaims); 33 | var jwtSecurityTokenHandler = new JwtSecurityTokenHandler(); 34 | var token = jwtSecurityTokenHandler.WriteToken(jwt); 35 | 36 | return new AccessToken 37 | { 38 | Token = token, 39 | Expiration = _accessTokenExpiration 40 | }; 41 | } 42 | 43 | public JwtSecurityToken CreateJwtSecurityToken(TokenOptions tokenOptions, User user, 44 | SigningCredentials signingCredentials, List operationClaims) 45 | { 46 | var jwt=new JwtSecurityToken( 47 | issuer:tokenOptions.Issuer, 48 | audience:tokenOptions.Audience, 49 | expires:_accessTokenExpiration, 50 | notBefore:DateTime.Now, 51 | claims:SetClaims(user,operationClaims), 52 | signingCredentials:signingCredentials); 53 | return jwt; 54 | } 55 | 56 | private IEnumerable SetClaims(User user, List operationClaims) 57 | { 58 | var claims=new List(); 59 | claims.AddNameIdentifier(user.UserId.ToString()); 60 | claims.AddEmail(user.Email); 61 | claims.AddName($"{user.FirstName} {user.LastName}"); 62 | claims.AddRoles(operationClaims.Select(c=>c.Name).ToArray()); 63 | 64 | return claims; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/Security/JWT/TokenOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ReCapProject.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 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/İnterceptors/AspectInterceptorSelector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using Castle.DynamicProxy; 7 | using ReCapProject.Core.Aspects.Performance; 8 | 9 | namespace ReCapProject.Core.Utilities.İnterceptors 10 | { 11 | public class AspectInterceptorSelector:IInterceptorSelector 12 | { 13 | public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) 14 | { 15 | var classAttributes = type.GetCustomAttributes 16 | (true).ToList(); 17 | var methodAttributes = type.GetMethod(method.Name) 18 | .GetCustomAttributes(true); 19 | classAttributes.AddRange(methodAttributes); 20 | //classAttributes.Add(new PerformanceAspect(5)); 21 | 22 | return classAttributes.OrderBy(x => x.Priority).ToArray(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/İnterceptors/MethodInterception.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Castle.DynamicProxy; 5 | 6 | namespace ReCapProject.Core.Utilities.İnterceptors 7 | { 8 | public abstract class MethodInterception:MethodInterceptionBaseAttribute 9 | { 10 | protected virtual void OnBefore(IInvocation invocation){} 11 | protected virtual void OnAfter(IInvocation invocation){} 12 | protected virtual void OnException(IInvocation invocation,System.Exception e){} 13 | protected virtual void OnSuccess(IInvocation invocation){} 14 | public override void Intercept(IInvocation invocation) 15 | { 16 | var isSuccess = true; 17 | OnBefore(invocation); 18 | try 19 | { 20 | invocation.Proceed(); 21 | } 22 | catch (Exception e) 23 | { 24 | isSuccess = false; 25 | OnException(invocation, e); 26 | throw; 27 | } 28 | finally 29 | { 30 | if (isSuccess) 31 | { 32 | OnSuccess(invocation); 33 | } 34 | } 35 | OnAfter(invocation); 36 | } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ReCapProject.Core/Utilities/İnterceptors/MethodInterceptionBaseAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Castle.DynamicProxy; 5 | 6 | namespace ReCapProject.Core.Utilities.İnterceptors 7 | { 8 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true,Inherited = true)] 9 | public abstract class MethodInterceptionBaseAttribute:Attribute,IInterceptor 10 | { 11 | public int Priority { get; set; } 12 | public virtual void Intercept(IInvocation invocation) 13 | { 14 | 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Abstract/IBrandDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.DataAccess; 5 | using ReCapProject.Entities.Concrete; 6 | 7 | namespace ReCapProject.DataAccess.Abstract 8 | { 9 | public interface IBrandDal:IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Abstract/ICarDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Text; 5 | using ReCapProject.Core.DataAccess; 6 | using ReCapProject.Entities.Concrete; 7 | using ReCapProject.Entities.DTOs; 8 | 9 | namespace ReCapProject.DataAccess.Abstract 10 | { 11 | public interface ICarDal:IEntityRepository 12 | { 13 | List GetCarDetails(Expression> filter = null); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Abstract/ICarImageDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Text; 5 | using ReCapProject.Core.DataAccess; 6 | using ReCapProject.Entities.Concrete; 7 | using ReCapProject.Entities.DTOs; 8 | 9 | namespace ReCapProject.DataAccess.Abstract 10 | { 11 | public interface ICarImageDal:IEntityRepository 12 | { 13 | bool IsExist(int id); 14 | List GetCarImageDetails(Expression> filter = null); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Abstract/IColorDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.DataAccess; 5 | using ReCapProject.Entities.Concrete; 6 | 7 | namespace ReCapProject.DataAccess.Abstract 8 | { 9 | public interface IColorDal:IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Abstract/ICustomerDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.DataAccess; 5 | using ReCapProject.Entities.Concrete; 6 | using ReCapProject.Entities.DTOs; 7 | 8 | namespace ReCapProject.DataAccess.Abstract 9 | { 10 | public interface ICustomerDal:IEntityRepository 11 | { 12 | List GetCustomerDetails(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Abstract/IFakeCardDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.DataAccess; 5 | using ReCapProject.Entities.Concrete; 6 | 7 | namespace ReCapProject.DataAccess.Abstract 8 | { 9 | public interface IFakeCardDal:IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Abstract/IRentalDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.DataAccess; 5 | using ReCapProject.Entities.Concrete; 6 | using ReCapProject.Entities.DTOs; 7 | 8 | namespace ReCapProject.DataAccess.Abstract 9 | { 10 | public interface IRentalDal:IEntityRepository 11 | { 12 | List GetRentalDetails(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Abstract/IUserDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.DataAccess; 5 | using ReCapProject.Core.Entities.Concrete; 6 | using ReCapProject.Entities.Concrete; 7 | 8 | namespace ReCapProject.DataAccess.Abstract 9 | { 10 | public interface IUserDal : IEntityRepository 11 | { 12 | List GetClaims(User user); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Concrete/EntityFramework/EfBrandDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.DataAccess.EntityFramework; 5 | using ReCapProject.DataAccess.Abstract; 6 | using ReCapProject.Entities.Concrete; 7 | 8 | namespace ReCapProject.DataAccess.Concrete.EntityFramework 9 | { 10 | public class EfBrandDal:EfEntityRepositoryBase,IBrandDal 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Concrete/EntityFramework/EfCarDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Text; 6 | using Microsoft.EntityFrameworkCore; 7 | using ReCapProject.Core.DataAccess.EntityFramework; 8 | using ReCapProject.DataAccess.Abstract; 9 | using ReCapProject.Entities.Concrete; 10 | using ReCapProject.Entities.DTOs; 11 | 12 | namespace ReCapProject.DataAccess.Concrete.EntityFramework 13 | { 14 | public class EfCarDal : EfEntityRepositoryBase, ICarDal 15 | { 16 | public List GetCarDetails(Expression> filter = null) 17 | { 18 | using (NorthwindContext context = new NorthwindContext()) 19 | { 20 | var result = from c in filter==null ? context.Cars :context.Cars.Where(filter) 21 | join b in context.Brands on c.BrandId equals b.BrandId 22 | join cl in context.Colors on c.ColorId equals cl.ColorId 23 | select new CarDetailDto 24 | { 25 | CarId = c.CarId, 26 | BrandId = b.BrandId, 27 | ColorId = cl.ColorId, 28 | Description = c.Description, 29 | DailyPrice = c.DailyPrice, 30 | BrandName = b.BrandName, 31 | ModelYear=c.ModelYear, 32 | ColorName = cl.ColorName, 33 | Findeks = c.Findeks 34 | 35 | }; 36 | return result.ToList(); 37 | } 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Concrete/EntityFramework/EfCarImageDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Text; 6 | using ReCapProject.Core.DataAccess.EntityFramework; 7 | using ReCapProject.DataAccess.Abstract; 8 | using ReCapProject.Entities.Concrete; 9 | using ReCapProject.Entities.DTOs; 10 | 11 | namespace ReCapProject.DataAccess.Concrete.EntityFramework 12 | { 13 | public class EfCarImageDal:EfEntityRepositoryBase,ICarImageDal 14 | { 15 | public bool IsExist(int id) 16 | { 17 | using (NorthwindContext context = new NorthwindContext()) 18 | { 19 | return context.CarImages.Any(p => p.Id == id); 20 | } 21 | } 22 | 23 | public List GetCarImageDetails(Expression> filter = null) 24 | { 25 | using (NorthwindContext context=new NorthwindContext()) 26 | { 27 | var result = from cari in filter == null ? context.CarImages : context.CarImages.Where(filter) 28 | join c in context.Cars on cari.CarId equals c.CarId 29 | select new CarImageDto 30 | { 31 | CarId = c.CarId, ImagePath = cari.ImagePath 32 | }; 33 | return result.ToList(); 34 | } 35 | 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Concrete/EntityFramework/EfColorDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.DataAccess.EntityFramework; 5 | using ReCapProject.DataAccess.Abstract; 6 | using ReCapProject.Entities.Concrete; 7 | 8 | namespace ReCapProject.DataAccess.Concrete.EntityFramework 9 | { 10 | public class EfColorDal:EfEntityRepositoryBase,IColorDal 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Concrete/EntityFramework/EfCustomerDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ReCapProject.Core.DataAccess.EntityFramework; 6 | using ReCapProject.DataAccess.Abstract; 7 | using ReCapProject.Entities.Concrete; 8 | using ReCapProject.Entities.DTOs; 9 | 10 | namespace ReCapProject.DataAccess.Concrete.EntityFramework 11 | { 12 | public class EfCustomerDal:EfEntityRepositoryBase,ICustomerDal 13 | { 14 | public List GetCustomerDetails() 15 | { 16 | using (NorthwindContext context=new NorthwindContext()) 17 | { 18 | var result = from cu in context.Customers 19 | join u in context.Users on cu.UserId equals u.UserId 20 | select new CustomerDetailDto 21 | { 22 | CustomerId = cu.CustomerId, 23 | UserId = u.UserId, 24 | CompanyName = cu.CompanyName, 25 | Email = u.Email, 26 | FirstName = u.FirstName, 27 | LastName = u.LastName, 28 | Status = u.Status 29 | }; 30 | return result.ToList(); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Concrete/EntityFramework/EfFakeCardDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.DataAccess.EntityFramework; 5 | using ReCapProject.DataAccess.Abstract; 6 | using ReCapProject.Entities.Concrete; 7 | 8 | namespace ReCapProject.DataAccess.Concrete.EntityFramework 9 | { 10 | public class EfFakeCardDal:EfEntityRepositoryBase, IFakeCardDal 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Concrete/EntityFramework/EfRentalDal.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using ReCapProject.Core.DataAccess.EntityFramework; 4 | using ReCapProject.DataAccess.Abstract; 5 | using ReCapProject.Entities.Concrete; 6 | using ReCapProject.Entities.DTOs; 7 | 8 | namespace ReCapProject.DataAccess.Concrete.EntityFramework 9 | { 10 | public class EfRentalDal : EfEntityRepositoryBase, IRentalDal 11 | { 12 | public List GetRentalDetails() 13 | { 14 | using (NorthwindContext context = new NorthwindContext()) 15 | { 16 | var result = from r in context.Rentals 17 | join cu in context.Customers on r.CustomerId equals cu.CustomerId 18 | join c in context.Cars on r.CarId equals c.CarId 19 | join b in context.Brands on c.BrandId equals b.BrandId 20 | join col in context.Colors on c.ColorId equals col.ColorId 21 | join u in context.Users on cu.UserId equals u.UserId 22 | select new RentalDetailDto 23 | { 24 | RentalId = r.RentalId, 25 | CarId = c.CarId, 26 | BrandName = b.BrandName, 27 | ColorName = col.ColorName, 28 | CustomerName = u.FirstName+u.LastName, 29 | ModelYear = c.ModelYear, 30 | DailyPrice = c.DailyPrice, 31 | Description = c.Description, 32 | CompanyName = cu.CompanyName, 33 | RentDate = r.RentDate, 34 | ReturnDate = r.ReturnDate 35 | }; 36 | return result.ToList(); 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Concrete/EntityFramework/EfUserDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ReCapProject.Core.DataAccess.EntityFramework; 6 | using ReCapProject.Core.Entities.Concrete; 7 | using ReCapProject.DataAccess.Abstract; 8 | using ReCapProject.Entities.Concrete; 9 | 10 | namespace ReCapProject.DataAccess.Concrete.EntityFramework 11 | { 12 | public class EfUserDal : EfEntityRepositoryBase, IUserDal 13 | { 14 | public List GetClaims(User user) 15 | { 16 | using (var context = new NorthwindContext()) 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.UserId 22 | select new OperationClaim 23 | { 24 | Id = operationClaim.Id, 25 | Name = operationClaim.Name 26 | }; 27 | return result.ToList(); 28 | 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Concrete/EntityFramework/NorthwindContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.EntityFrameworkCore; 5 | using ReCapProject.Core.Entities.Concrete; 6 | using ReCapProject.Entities.Concrete; 7 | using ReCapProject.Entities.DTOs; 8 | 9 | namespace ReCapProject.DataAccess.Concrete.EntityFramework 10 | { 11 | public class NorthwindContext:DbContext 12 | { 13 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 14 | { 15 | optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=CarDb;Trusted_Connection=true"); 16 | } 17 | 18 | public DbSet Cars { get; set; } 19 | public DbSet Brands { get; set; } 20 | public DbSet Colors { get; set; } 21 | public DbSet Customers { get; set; } 22 | public DbSet Rentals { get; set; } 23 | public DbSet CarImages { get; set; } 24 | public DbSet OperationClaims { get; set; } 25 | public DbSet Users { get; set; } 26 | public DbSet UserOperationClaims { get; set; } 27 | public DbSet FakeCards { get; set; } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/Concrete/InMemory/IMCarDal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Text; 6 | using ReCapProject.DataAccess.Abstract; 7 | using ReCapProject.Entities.Concrete; 8 | using ReCapProject.Entities.DTOs; 9 | 10 | namespace ReCapProject.DataAccess.Concrete.InMemory 11 | { 12 | public class IMCarDal : ICarDal 13 | { 14 | private List _cars; 15 | private List _brands; 16 | private List _colors; 17 | 18 | public IMCarDal() 19 | { 20 | _brands = new List 21 | { 22 | new Brand 23 | { 24 | BrandId = 1, BrandName = "Fiyat" 25 | }, 26 | new Brand 27 | { 28 | BrandId = 2, BrandName = "Ford" 29 | }, 30 | new Brand 31 | { 32 | BrandId = 1, BrandName = "Mercedes" 33 | } 34 | 35 | }; 36 | 37 | _colors = new List 38 | { 39 | new Color 40 | { 41 | ColorId = 1, ColorName = "Black" 42 | }, 43 | 44 | new Color 45 | { 46 | ColorId = 1, ColorName = "White" 47 | }, 48 | 49 | new Color 50 | { 51 | ColorId = 1, ColorName = "Yellow" 52 | } 53 | }; 54 | _cars = new List 55 | { 56 | new Car{CarId = 1,BrandId = 1,ColorId = 2,DailyPrice = 155, 57 | Description ="95 Kilometrede",ModelYear = 2019}, 58 | new Car{CarId = 2,BrandId = 1,ColorId = 3,DailyPrice = 165, 59 | Description ="115 Kilometrede",ModelYear = 2019}, 60 | new Car{CarId = 3,BrandId = 2,ColorId = 1,DailyPrice = 115, 61 | Description ="335 Kilometrede",ModelYear = 2013}, 62 | new Car{CarId = 4,BrandId = 2,ColorId = 1,DailyPrice = 159, 63 | Description ="35 Kilometrede",ModelYear = 2020}, 64 | new Car{CarId = 5,BrandId = 3,ColorId = 2,DailyPrice = 145, 65 | Description ="135 Kilometrede",ModelYear = 2018}, 66 | new Car{CarId = 6,BrandId = 3,ColorId = 3,DailyPrice = 105, 67 | Description ="235 Kilometrede",ModelYear = 2010} 68 | }; 69 | } 70 | 71 | public List GetByIdBrand(int brandId) 72 | { 73 | return _cars.Where(c => c.BrandId == brandId).ToList(); 74 | } 75 | 76 | public List GetByIdColor(int colorId) 77 | { 78 | return _cars.Where(c => c.ColorId == colorId).ToList(); 79 | } 80 | 81 | public List GetAll() 82 | { 83 | return _cars; 84 | } 85 | 86 | public List GetAll(Expression> filter = null) 87 | { 88 | throw new NotImplementedException(); 89 | } 90 | 91 | public Car Get(Expression> filter) 92 | { 93 | throw new NotImplementedException(); 94 | } 95 | 96 | public void Add(Car car) 97 | { 98 | _cars.Add(car); 99 | } 100 | 101 | public void Update(Car car) 102 | { 103 | Car carToUpdate = _cars.SingleOrDefault(c => c.CarId == car.CarId); 104 | carToUpdate.ColorId = car.ColorId; 105 | carToUpdate.BrandId = car.BrandId; 106 | carToUpdate.DailyPrice = car.DailyPrice; 107 | carToUpdate.Description = car.Description; 108 | carToUpdate.ModelYear = car.ModelYear; 109 | } 110 | 111 | public void Delete(Car car) 112 | { 113 | Car carToDelete = _cars.SingleOrDefault(c => c.CarId == car.CarId); 114 | _cars.Remove(carToDelete); 115 | } 116 | 117 | public List GetCarDetails(Expression> filter = null) 118 | { 119 | throw new NotImplementedException(); 120 | } 121 | 122 | public List GetCarDetails() 123 | { 124 | throw new NotImplementedException(); 125 | } 126 | 127 | public List GetCarDetails1(Expression> filter = null) 128 | { 129 | throw new NotImplementedException(); 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /ReCapProject.DataAccess/ReCapProject.DataAccess.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /ReCapProject.Entities/Concrete/Brand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Entities; 5 | 6 | namespace ReCapProject.Entities.Concrete 7 | { 8 | public class Brand:IEntity 9 | { 10 | public int BrandId { get; set; } 11 | public string BrandName { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ReCapProject.Entities/Concrete/Car.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Entities; 5 | 6 | namespace ReCapProject.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 int ModelYear { get; set; } 14 | public decimal DailyPrice { get; set; } 15 | public string Description { get; set; } 16 | public int Findeks { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ReCapProject.Entities/Concrete/CarImage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Text; 5 | using ReCapProject.Core.Entities; 6 | 7 | namespace ReCapProject.Entities.Concrete 8 | { 9 | public class CarImage:IEntity 10 | { 11 | public int Id { get; set; } 12 | public int CarId { get; set; } 13 | public string ImagePath { get; set; } 14 | public DateTime Date { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ReCapProject.Entities/Concrete/Color.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Entities; 5 | 6 | namespace ReCapProject.Entities.Concrete 7 | { 8 | public class Color:IEntity 9 | { 10 | public int ColorId { get; set; } 11 | public string ColorName { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ReCapProject.Entities/Concrete/Customer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Entities; 5 | 6 | namespace ReCapProject.Entities.Concrete 7 | { 8 | public class Customer:IEntity 9 | { 10 | public int CustomerId { get; set; } 11 | public int UserId { get; set; } 12 | public string CompanyName { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ReCapProject.Entities/Concrete/FakeCard.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Entities; 5 | 6 | namespace ReCapProject.Entities.Concrete 7 | { 8 | public class FakeCard:IEntity 9 | { 10 | public int Id { get; set; } 11 | public string CardName { get; set; } 12 | public string CardNumber { get; set; } 13 | public string CardCvv { get; set; } 14 | public string ExpirationDate { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ReCapProject.Entities/Concrete/Rental.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Entities; 5 | 6 | namespace ReCapProject.Entities.Concrete 7 | { 8 | public class Rental:IEntity 9 | { 10 | public int RentalId { get; set; } 11 | public int CarId { get; set; } 12 | public int CustomerId { get; set; } 13 | public DateTime RentDate { get; set; } 14 | public DateTime? ReturnDate { get; set; } 15 | public DateTime RentEndDate { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ReCapProject.Entities/DTOs/CarDetailDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Entities; 5 | 6 | namespace ReCapProject.Entities.DTOs 7 | { 8 | public class CarDetailDto:IDto 9 | { 10 | public int CarId { get; set; } 11 | public int BrandId { get; set; } 12 | public int ColorId { get; set; } 13 | public string Description { get; set; } 14 | public string BrandName { get; set; } 15 | public string ColorName { get; set; } 16 | public int ModelYear { get; set; } 17 | public decimal DailyPrice { get; set; } 18 | public int Findeks { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ReCapProject.Entities/DTOs/CarImageDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Entities; 5 | 6 | namespace ReCapProject.Entities.DTOs 7 | { 8 | public class CarImageDto:IDto 9 | { 10 | public int CarId { get; set; } 11 | public string ImagePath { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ReCapProject.Entities/DTOs/CustomerDetailDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Entities; 5 | 6 | namespace ReCapProject.Entities.DTOs 7 | { 8 | public class CustomerDetailDto:IDto 9 | { 10 | public int CustomerId { get; set; } 11 | public int UserId { get; set; } 12 | public string CompanyName { get; set; } 13 | public string FirstName { get; set; } 14 | public string LastName { get; set; } 15 | public string Email { get; set; } 16 | public bool Status { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ReCapProject.Entities/DTOs/RentalDetailDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Entities; 5 | 6 | namespace ReCapProject.Entities.DTOs 7 | { 8 | public class RentalDetailDto:IDto 9 | { 10 | public int RentalId { get; set; } 11 | public int CarId { get; set; } 12 | public string BrandName { get; set; } 13 | public string ColorName { get; set; } 14 | public string CustomerName { get; set; } 15 | public string CompanyName { get; set; } 16 | public int ModelYear { get; set; } 17 | public decimal DailyPrice { get; set; } 18 | public string Description { get; set; } 19 | public DateTime RentDate { get; set; } 20 | public DateTime? ReturnDate { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ReCapProject.Entities/DTOs/UserForLoginDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Entities; 5 | 6 | namespace ReCapProject.Entities.DTOs 7 | { 8 | public class UserForLoginDto : IDto 9 | { 10 | public string Email { get; set; } 11 | public string Password { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ReCapProject.Entities/DTOs/UserForRegisterDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReCapProject.Core.Entities; 5 | 6 | namespace ReCapProject.Entities.DTOs 7 | { 8 | public class UserForRegisterDto : IDto 9 | { 10 | public int Id { get; set; } 11 | public string Email { get; set; } 12 | public string Password { get; set; } 13 | public string FirstName { get; set; } 14 | public string LastName { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ReCapProject.Entities/ReCapProject.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}") = "ReCapProject.DataAccess", "ReCapProject.DataAccess\ReCapProject.DataAccess.csproj", "{48C48F25-B803-42B4-98B1-527AE583A958}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReCapProject.Business", "ReCapProject.Business\ReCapProject.Business.csproj", "{ECED19DD-DF0B-4317-BF6D-BC96C93795C9}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReCapProject.Entities", "ReCapProject.Entities\ReCapProject.Entities.csproj", "{D783730E-5CA4-4D26-82D9-20AB8F4D72E6}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReCapProject.Core", "ReCapProject.Core\ReCapProject.Core.csproj", "{B6230612-E5A7-4061-B41B-B1250AFA2BC7}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReCapProject.Console", "ReCapProject.Console\ReCapProject.Console.csproj", "{B206DB01-8F0A-4433-A0C3-9BD8F092890C}" 15 | EndProject 16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebAPI", "WebAPI\WebAPI.csproj", "{7FE07786-7CE7-4B4B-92BA-FEACDB0C8171}" 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 | {48C48F25-B803-42B4-98B1-527AE583A958}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {48C48F25-B803-42B4-98B1-527AE583A958}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {48C48F25-B803-42B4-98B1-527AE583A958}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {48C48F25-B803-42B4-98B1-527AE583A958}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {ECED19DD-DF0B-4317-BF6D-BC96C93795C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {ECED19DD-DF0B-4317-BF6D-BC96C93795C9}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {ECED19DD-DF0B-4317-BF6D-BC96C93795C9}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {ECED19DD-DF0B-4317-BF6D-BC96C93795C9}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {D783730E-5CA4-4D26-82D9-20AB8F4D72E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {D783730E-5CA4-4D26-82D9-20AB8F4D72E6}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {D783730E-5CA4-4D26-82D9-20AB8F4D72E6}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {D783730E-5CA4-4D26-82D9-20AB8F4D72E6}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {B6230612-E5A7-4061-B41B-B1250AFA2BC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {B6230612-E5A7-4061-B41B-B1250AFA2BC7}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {B6230612-E5A7-4061-B41B-B1250AFA2BC7}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {B6230612-E5A7-4061-B41B-B1250AFA2BC7}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {B206DB01-8F0A-4433-A0C3-9BD8F092890C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {B206DB01-8F0A-4433-A0C3-9BD8F092890C}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {B206DB01-8F0A-4433-A0C3-9BD8F092890C}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {B206DB01-8F0A-4433-A0C3-9BD8F092890C}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {7FE07786-7CE7-4B4B-92BA-FEACDB0C8171}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {7FE07786-7CE7-4B4B-92BA-FEACDB0C8171}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {7FE07786-7CE7-4B4B-92BA-FEACDB0C8171}.Release|Any CPU.ActiveCfg = Release|Any CPU 47 | {7FE07786-7CE7-4B4B-92BA-FEACDB0C8171}.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 = {7181DFCC-F3B9-4F17-9720-6B7D16894E78} 54 | EndGlobalSection 55 | EndGlobal 56 | -------------------------------------------------------------------------------- /WebAPI/Controllers/AuthController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using Microsoft.AspNetCore.Mvc; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using ReCapProject.Business.Abstract; 8 | using ReCapProject.Entities.DTOs; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class AuthController : ControllerBase 15 | { 16 | private IAuthService _authService; 17 | private IUserService _userService; 18 | 19 | public AuthController(IAuthService authService, IUserService userService) 20 | { 21 | _authService = authService; 22 | _userService = userService; 23 | } 24 | 25 | [HttpPost("login")] 26 | public ActionResult Login(UserForLoginDto userForLoginDto) 27 | { 28 | var userToLogin = _authService.Login(userForLoginDto); 29 | if (!userToLogin.Success) 30 | { 31 | return BadRequest(userToLogin.Message); 32 | } 33 | 34 | var result = _authService.CreateAccessToken(userToLogin.Data); 35 | if (result.Success) 36 | { 37 | return Ok(result); 38 | } 39 | 40 | return BadRequest(result.Message); 41 | } 42 | 43 | [HttpPost("register")] 44 | public ActionResult Register(UserForRegisterDto userForRegisterDto) 45 | { 46 | var userExists = _authService.UserExists(userForRegisterDto.Email); 47 | if (!userExists.Success) 48 | { 49 | return BadRequest(userExists.Message); 50 | } 51 | 52 | var registerResult = _authService.Register(userForRegisterDto, userForRegisterDto.Password); 53 | var result = _authService.CreateAccessToken(registerResult.Data); 54 | if (result.Success) 55 | { 56 | return Ok(result.Data); 57 | } 58 | 59 | return BadRequest(result.Message); 60 | } 61 | 62 | [HttpPost("update")] 63 | public ActionResult Update(UserForRegisterDto userForRegisterDto) 64 | { 65 | 66 | var registerResult = _authService.Update(userForRegisterDto, userForRegisterDto.Password); 67 | if (registerResult.Success) 68 | { 69 | return Ok(registerResult); 70 | } 71 | 72 | return BadRequest(registerResult.Message); 73 | } 74 | 75 | [HttpGet("getall")] 76 | public IActionResult GetAll() 77 | { 78 | var result = _userService.GetAll(); 79 | if (result.Success) 80 | { 81 | return Ok(result); 82 | } 83 | return BadRequest(result); 84 | } 85 | 86 | [HttpGet("getbyid")] 87 | public IActionResult GetById(int userId) 88 | { 89 | var result = _userService.GetUsersByUserId(userId); 90 | if (result.Success) 91 | { 92 | return Ok(result); 93 | } 94 | return BadRequest(result); 95 | } 96 | 97 | [HttpGet("getbyemail")] 98 | public IActionResult GetByEmail(string email) 99 | { 100 | var result = _userService.GetByEmail(email); 101 | if (result.Success) 102 | { 103 | return Ok(result); 104 | } 105 | return BadRequest(result); 106 | } 107 | 108 | [HttpGet("getbyname")] 109 | public IActionResult GetByName(string name) 110 | { 111 | var result = _userService.GetByName(name); 112 | if (result.Success) 113 | { 114 | return Ok(result); 115 | } 116 | return BadRequest(result); 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /WebAPI/Controllers/BrandsController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using Microsoft.AspNetCore.Mvc; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using ReCapProject.Business.Abstract; 8 | using ReCapProject.Entities.Concrete; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class BrandsController : ControllerBase 15 | { 16 | private IBrandService _brandService; 17 | 18 | public BrandsController(IBrandService brandService) 19 | { 20 | _brandService = brandService; 21 | } 22 | 23 | [HttpGet("getall")] 24 | public IActionResult GetAll() 25 | { 26 | var result = _brandService.GetAll(); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | 32 | return BadRequest(result); 33 | } 34 | 35 | [HttpGet("getbybrandid")] 36 | public IActionResult GetBrandsByBrandId(int brandId) 37 | { 38 | var result = _brandService.GetBrandsByBrandId(brandId); 39 | if (result.Success) 40 | { 41 | return Ok(result); 42 | } 43 | 44 | return BadRequest(result); 45 | } 46 | 47 | [HttpPost("add")] 48 | public IActionResult Add(Brand brand) 49 | { 50 | var result = _brandService.Add(brand); 51 | if (result.Success) 52 | { 53 | return Ok(result); 54 | } 55 | 56 | return BadRequest(result); 57 | } 58 | 59 | [HttpPost("update")] 60 | public IActionResult Update(Brand brand) 61 | { 62 | var result = _brandService.Update(brand); 63 | if (result.Success) 64 | { 65 | return Ok(result); 66 | } 67 | 68 | return BadRequest(result); 69 | } 70 | 71 | [HttpPost("delete")] 72 | public IActionResult Delete(Brand brand) 73 | { 74 | var result = _brandService.Delete(brand); 75 | if (result.Success) 76 | { 77 | return Ok(result); 78 | } 79 | 80 | return BadRequest(result); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CarImagesController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.AspNetCore.Http; 3 | using Microsoft.AspNetCore.Mvc; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | using ReCapProject.Business.Abstract; 9 | using ReCapProject.Core.Utilities.Results; 10 | using ReCapProject.Entities.Concrete; 11 | 12 | namespace WebAPI.Controllers 13 | { 14 | [Route("api/[controller]")] 15 | [ApiController] 16 | public class CarImagesController : ControllerBase 17 | { 18 | ICarImageService _carImageService; 19 | public CarImagesController(ICarImageService carImageService) 20 | { 21 | _carImageService = carImageService; 22 | } 23 | 24 | [HttpGet("getall")] 25 | public IActionResult GetAll() 26 | { 27 | var result = _carImageService.GetAll(); 28 | if (result.Success) 29 | { 30 | return Ok(result); 31 | } 32 | return BadRequest(result); 33 | } 34 | 35 | [HttpGet("getbyid")] 36 | public IActionResult GetById(int id) 37 | { 38 | var result = _carImageService.GetById(id); 39 | if (result.Success) 40 | { 41 | return Ok(result); 42 | } 43 | return BadRequest(result); 44 | } 45 | 46 | [HttpGet("getbycarid")] 47 | public IActionResult GetAllByCarId(int carId) 48 | { 49 | var result = _carImageService.GetAllByCarId(carId); 50 | if (result.Success) 51 | { 52 | return Ok(result); 53 | } 54 | return BadRequest(result); 55 | } 56 | 57 | [HttpPost("add")] 58 | public IActionResult Add([FromForm] CarImage carImage, [FromForm] IFormFile file) 59 | { 60 | IResult result = _carImageService.Add(carImage, file); 61 | if (result.Success) 62 | { 63 | return Ok(result); 64 | } 65 | return BadRequest(result); 66 | } 67 | 68 | [HttpPut("update")] 69 | public IActionResult Update([FromForm] CarImage carImage, [FromForm] IFormFile file) 70 | { 71 | IResult result = _carImageService.Update(carImage, file); 72 | if (result.Success) 73 | { 74 | return Ok(result); 75 | } 76 | return BadRequest(result); 77 | } 78 | 79 | [HttpDelete("delete")] 80 | public IActionResult Delete(CarImage carImage) 81 | { 82 | IResult result = _carImageService.Delete(carImage); 83 | if (result.Success) 84 | { 85 | return Ok(result); 86 | } 87 | return BadRequest(result); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CarsController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using Microsoft.AspNetCore.Mvc; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using ReCapProject.Business.Abstract; 9 | using ReCapProject.Entities.Concrete; 10 | 11 | namespace WebAPI.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | [ApiController] 15 | public class CarsController : ControllerBase 16 | { 17 | private ICarService _carService; 18 | 19 | public CarsController(ICarService carService) 20 | { 21 | _carService = carService; 22 | } 23 | 24 | [HttpGet("getall")] 25 | public IActionResult GetAll() 26 | { 27 | var result = _carService.GetAll(); 28 | if (result.Success) 29 | { 30 | return Ok(result); 31 | } 32 | 33 | return BadRequest(result); 34 | } 35 | 36 | [HttpGet("getbycarid")] 37 | public IActionResult GetCarsByCarId(int carId) 38 | { 39 | var result = _carService.GetCarsByCarId(carId); 40 | if (result.Success) 41 | { 42 | return Ok(result); 43 | } 44 | 45 | return BadRequest(result); 46 | } 47 | 48 | [HttpGet("getbybrandid")] 49 | public IActionResult GetCarsByBrandId(int brandId) 50 | { 51 | var result = _carService.GetCarsByBrandId(brandId); 52 | if (result.Success) 53 | { 54 | return Ok(result); 55 | } 56 | 57 | return BadRequest(result); 58 | } 59 | 60 | [HttpGet("getbycolorid")] 61 | public IActionResult GetCarsByColorId(int colorId) 62 | { 63 | var result = _carService.GetCarsByColorId(colorId); 64 | if (result.Success) 65 | { 66 | return Ok(result); 67 | } 68 | 69 | return BadRequest(result); 70 | } 71 | 72 | [HttpGet("getdetailbycarid")] 73 | public IActionResult GetCarsDetailsByCarId(int carId) 74 | { 75 | var result = _carService.GetCarDetailsByCarsId(carId); 76 | if (result.Success) 77 | { 78 | return Ok(result); 79 | } 80 | 81 | return BadRequest(result); 82 | } 83 | 84 | [HttpGet("getdetailbybrandid")] 85 | public IActionResult GetCarsDetailsByBrandId(int brandId) 86 | { 87 | var result = _carService.GetCarsDetailsByBrandId(brandId); 88 | if (result.Success) 89 | { 90 | return Ok(result); 91 | } 92 | 93 | return BadRequest(result); 94 | } 95 | 96 | [HttpGet("getdetailbycolorid")] 97 | public IActionResult GetCarsDetailsByColorId(int colorId) 98 | { 99 | var result = _carService.GetCarsDetailsByColorId(colorId); 100 | if (result.Success) 101 | { 102 | return Ok(result); 103 | } 104 | 105 | return BadRequest(result); 106 | } 107 | 108 | [HttpGet("getbybrandandcolor")] 109 | public IActionResult GetByBrand(int brandId, int colorId) 110 | { 111 | var result = _carService.GetCarsDetailsByBrandIdAndColorId(brandId, colorId); 112 | if (result.Success) 113 | { 114 | return Ok(result); 115 | } 116 | return BadRequest(result); 117 | } 118 | 119 | 120 | [HttpGet("getcardetails")] 121 | public IActionResult GetCarDetails() 122 | { 123 | var result = _carService.GetCarDetails(); 124 | if (result.Success) 125 | { 126 | return Ok(result); 127 | } 128 | 129 | return BadRequest(result); 130 | } 131 | 132 | [HttpPost("add")] 133 | public IActionResult Add(Car car) 134 | { 135 | var result = _carService.Add(car); 136 | if (result.Success) 137 | { 138 | return Ok(result); 139 | } 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 | 153 | return BadRequest(result); 154 | } 155 | 156 | [HttpPost("delete")] 157 | public IActionResult Delete(int carId) 158 | { 159 | var result = _carService.Delete(carId); 160 | if (result.Success) 161 | { 162 | return Ok(result); 163 | } 164 | 165 | return BadRequest(result); 166 | } 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /WebAPI/Controllers/ColorsController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using Microsoft.AspNetCore.Mvc; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using ReCapProject.Business.Abstract; 8 | using ReCapProject.Entities.Concrete; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class ColorsController : ControllerBase 15 | { 16 | private IColorService _colorService; 17 | 18 | public ColorsController(IColorService colorService) 19 | { 20 | _colorService = colorService; 21 | } 22 | 23 | [HttpGet("getall")] 24 | public IActionResult GetAll() 25 | { 26 | var result = _colorService.GetAll(); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | 32 | return BadRequest(result); 33 | } 34 | 35 | [HttpGet("getbycolorid")] 36 | public IActionResult GetColorsByColorId(int colorId) 37 | { 38 | var result = _colorService.GetColorsByColorId(colorId); 39 | if (result.Success) 40 | { 41 | return Ok(result); 42 | } 43 | 44 | return BadRequest(result); 45 | } 46 | 47 | [HttpPost("add")] 48 | public IActionResult Add(Color color) 49 | { 50 | var result = _colorService.Add(color); 51 | if (result.Success) 52 | { 53 | return Ok(result); 54 | } 55 | 56 | return BadRequest(result); 57 | } 58 | 59 | [HttpPost("update")] 60 | public IActionResult Update(Color color) 61 | { 62 | var result = _colorService.Update(color); 63 | if (result.Success) 64 | { 65 | return Ok(result); 66 | } 67 | 68 | return BadRequest(result); 69 | } 70 | 71 | [HttpPost("delete")] 72 | public IActionResult Delete(Color color) 73 | { 74 | var result = _colorService.Delete(color); 75 | if (result.Success) 76 | { 77 | return Ok(result); 78 | } 79 | 80 | return BadRequest(result); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CustomersController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using Microsoft.AspNetCore.Mvc; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using ReCapProject.Business.Abstract; 8 | using ReCapProject.Entities.Concrete; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class CustomersController : ControllerBase 15 | { 16 | private ICustomerService _customerService; 17 | 18 | public CustomersController(ICustomerService customerService) 19 | { 20 | _customerService = customerService; 21 | } 22 | 23 | [HttpGet("getall")] 24 | public IActionResult GetAll() 25 | { 26 | var result = _customerService.GetAll(); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | 32 | return BadRequest(result); 33 | } 34 | 35 | [HttpGet("getcustomerdetail")] 36 | public IActionResult GetCustomerDetail() 37 | { 38 | var result = _customerService.GetCustomerDetails(); 39 | if (result.Success) 40 | { 41 | return Ok(result); 42 | } 43 | 44 | return BadRequest(result); 45 | } 46 | 47 | [HttpGet("getbycustomerid")] 48 | public IActionResult GetCustomersByCustomerId(int customerId) 49 | { 50 | var result = _customerService.GetCustomersByCustomerId(customerId); 51 | if (result.Success) 52 | { 53 | return Ok(result); 54 | } 55 | 56 | return BadRequest(result); 57 | } 58 | 59 | [HttpPost("add")] 60 | public IActionResult Add(Customer customer) 61 | { 62 | var result = _customerService.Add(customer); 63 | if (result.Success) 64 | { 65 | return Ok(result); 66 | } 67 | 68 | return BadRequest(result); 69 | } 70 | 71 | [HttpPost("update")] 72 | public IActionResult Update(Customer customer) 73 | { 74 | var result = _customerService.Update(customer); 75 | if (result.Success) 76 | { 77 | return Ok(result); 78 | } 79 | 80 | return BadRequest(result); 81 | } 82 | 83 | [HttpPost("delete")] 84 | public IActionResult Delete(Customer customer) 85 | { 86 | var result = _customerService.Delete(customer); 87 | if (result.Success) 88 | { 89 | return Ok(result); 90 | } 91 | 92 | return BadRequest(result); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /WebAPI/Controllers/FakeCardsController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using Microsoft.AspNetCore.Mvc; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using ReCapProject.Business.Abstract; 8 | using ReCapProject.Entities.Concrete; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class FakeCardsController : ControllerBase 15 | { 16 | private IFakeCardService _fakeCardService; 17 | 18 | public FakeCardsController(IFakeCardService fakeCardService) 19 | { 20 | _fakeCardService = fakeCardService; 21 | } 22 | 23 | [HttpPost("add")] 24 | public IActionResult Add(FakeCard fakeCard) 25 | { 26 | var result = _fakeCardService.Add(fakeCard); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result); 32 | } 33 | 34 | [HttpPost("delete")] 35 | public IActionResult Delete(FakeCard fakeCard) 36 | { 37 | var result = _fakeCardService.Delete(fakeCard); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result); 43 | } 44 | 45 | [HttpPost("update")] 46 | public IActionResult Update(FakeCard fakeCard) 47 | { 48 | var result = _fakeCardService.Update(fakeCard); 49 | if (result.Success) 50 | { 51 | return Ok(result); 52 | } 53 | return BadRequest(result); 54 | } 55 | 56 | [HttpGet("getall")] 57 | public IActionResult GetAll() 58 | { 59 | var result = _fakeCardService.GetAll(); 60 | if (result.Success) 61 | { 62 | return Ok(result); 63 | } 64 | return BadRequest(result); 65 | } 66 | 67 | [HttpGet("getbyid")] 68 | public IActionResult GetById(int id) 69 | { 70 | var result = _fakeCardService.GetById(id); 71 | if (result.Success) 72 | { 73 | return Ok(result); 74 | } 75 | return BadRequest(result); 76 | } 77 | 78 | [HttpGet("getbycardnumber")] 79 | public IActionResult GetByCardNumber(string cardNumber) 80 | { 81 | var result = _fakeCardService.GetByCardNumber(cardNumber); 82 | if (result.Success) 83 | { 84 | return Ok(result); 85 | } 86 | return BadRequest(result); 87 | } 88 | 89 | [HttpPost("iscardexist")] 90 | public IActionResult IsCardExist(FakeCard fakeCard) 91 | { 92 | var result = _fakeCardService.IsCardExist(fakeCard); 93 | if (result.Success) 94 | { 95 | return Ok(result); 96 | } 97 | return Ok(result); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /WebAPI/Controllers/RentalsController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using Microsoft.AspNetCore.Mvc; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using ReCapProject.Business.Abstract; 8 | using ReCapProject.Entities.Concrete; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class RentalsController : ControllerBase 15 | { 16 | private IRentalService _rentalService; 17 | 18 | public RentalsController(IRentalService rentalService) 19 | { 20 | _rentalService = rentalService; 21 | } 22 | 23 | [HttpGet("getall")] 24 | public IActionResult GetAll() 25 | { 26 | var result = _rentalService.GetAll(); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | 32 | return BadRequest(result); 33 | } 34 | 35 | [HttpGet("getbyrentalid")] 36 | public IActionResult GetRentalsByRentalId(int rentalId) 37 | { 38 | var result = _rentalService.GetRentalsByRentalId(rentalId); 39 | if (result.Success) 40 | { 41 | return Ok(result); 42 | } 43 | 44 | return BadRequest(result); 45 | } 46 | 47 | [HttpGet("getallbycarid")] 48 | public IActionResult GetAllByCarId(int carId) 49 | { 50 | var result = _rentalService.GetAllByCarId(carId); 51 | if (result.Success) 52 | { 53 | return Ok(result); 54 | } 55 | return BadRequest(result); 56 | } 57 | 58 | [HttpGet("getallbycustomerid")] 59 | public IActionResult GetAllByCustomerId(int customerId) 60 | { 61 | var result = _rentalService.GetAllByCustomerId(customerId); 62 | if (result.Success) 63 | { 64 | return Ok(result); 65 | } 66 | return BadRequest(result); 67 | } 68 | 69 | [HttpGet("getrentaldetails")] 70 | public IActionResult GetRentalDetails() 71 | { 72 | var result = _rentalService.GetRentalDetails(); 73 | if (result.Success) 74 | { 75 | return Ok(result); 76 | } 77 | 78 | return BadRequest(result); 79 | } 80 | 81 | [HttpPost("add2")] 82 | public IActionResult Add2(Rental rental) 83 | { 84 | if (_rentalService.GetAll().Data.Count != 0) 85 | { 86 | if (_rentalService.Rentable(rental)) 87 | { 88 | var result1 = _rentalService.Add(rental); 89 | if (result1.Success) 90 | { 91 | return Ok(result1); 92 | } 93 | 94 | } 95 | } 96 | 97 | var result = _rentalService.Add(rental); 98 | if (result.Success) 99 | { 100 | return Ok(result); 101 | } 102 | return BadRequest(); 103 | 104 | 105 | } 106 | 107 | [HttpPost("add")] 108 | public IActionResult Add(Rental rental) 109 | { 110 | var result = _rentalService.Add(rental); 111 | if (result.Success) 112 | { 113 | return Ok(result); 114 | } 115 | 116 | return BadRequest(result); 117 | } 118 | 119 | [HttpPost("update")] 120 | public IActionResult Update(Rental rental) 121 | { 122 | var result = _rentalService.Update(rental); 123 | if (result.Success) 124 | { 125 | return Ok(result); 126 | } 127 | 128 | return BadRequest(result); 129 | } 130 | 131 | [HttpPost("delete")] 132 | public IActionResult Delete(Rental rental) 133 | { 134 | var result = _rentalService.Delete(rental); 135 | if (result.Success) 136 | { 137 | return Ok(result); 138 | } 139 | 140 | return BadRequest(result); 141 | } 142 | 143 | [HttpPost("isrentable")] 144 | public IActionResult IsRentable(Rental rental) 145 | { 146 | var result = _rentalService.IsRentable(rental); 147 | if (result.Success) 148 | { 149 | return Ok(result); 150 | } 151 | return Ok(result); 152 | } 153 | 154 | [HttpPost("isdelivered")] 155 | public IActionResult IsDelivered(Rental rental) 156 | { 157 | var result = _rentalService.IsDelivered(rental); 158 | if (result.Success) 159 | { 160 | return Ok(result); 161 | } 162 | return Ok(result); 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /WebAPI/Controllers/UsersController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using Microsoft.AspNetCore.Mvc; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using ReCapProject.Business.Abstract; 8 | using ReCapProject.Core.Entities.Concrete; 9 | using ReCapProject.Entities.Concrete; 10 | 11 | namespace WebAPI.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | [ApiController] 15 | public class UsersController : ControllerBase 16 | { 17 | private IUserService _userService; 18 | 19 | public UsersController(IUserService userService) 20 | { 21 | _userService = userService; 22 | } 23 | 24 | [HttpGet("getall")] 25 | public IActionResult GetAll() 26 | { 27 | var result = _userService.GetAll(); 28 | if (result.Success) 29 | { 30 | return Ok(result); 31 | } 32 | 33 | return BadRequest(result); 34 | } 35 | 36 | [HttpGet("getbyuserid")] 37 | public IActionResult GetUsersByUserId(int userId) 38 | { 39 | var result = _userService.GetUsersByUserId(userId); 40 | if (result.Success) 41 | { 42 | return Ok(result); 43 | } 44 | 45 | return BadRequest(result); 46 | } 47 | 48 | [HttpPost("add")] 49 | public IActionResult Add(User user) 50 | { 51 | var result = _userService.Add(user); 52 | if (result.Success) 53 | { 54 | return Ok(result); 55 | } 56 | 57 | return BadRequest(result); 58 | } 59 | 60 | [HttpPost("update")] 61 | public IActionResult Update(User user) 62 | { 63 | var result = _userService.Update(user); 64 | if (result.Success) 65 | { 66 | return Ok(result); 67 | } 68 | 69 | return BadRequest(result); 70 | } 71 | 72 | [HttpPost("delete")] 73 | public IActionResult Delete(User user) 74 | { 75 | var result = _userService.Delete(user); 76 | if (result.Success) 77 | { 78 | return Ok(result); 79 | } 80 | 81 | return BadRequest(result); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /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: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.Hosting; 4 | using Microsoft.Extensions.Logging; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | using Autofac; 10 | using Autofac.Extensions.DependencyInjection; 11 | using ReCapProject.Business.DependencyResolvers.Autofac; 12 | 13 | namespace WebAPI 14 | { 15 | public class Program 16 | { 17 | public static void Main(string[] args) 18 | { 19 | CreateHostBuilder(args).Build().Run(); 20 | } 21 | 22 | public static IHostBuilder CreateHostBuilder(string[] args) => 23 | Host.CreateDefaultBuilder(args) 24 | .UseServiceProviderFactory(new AutofacServiceProviderFactory()) 25 | .ConfigureContainer(builder => 26 | { 27 | builder.RegisterModule(new AutofacBusinessModule()); 28 | }) 29 | .ConfigureWebHostDefaults(webBuilder => 30 | { 31 | webBuilder.UseStartup(); 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /WebAPI/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:58561", 8 | "sslPort": 44357 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 Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.AspNetCore.HttpsPolicy; 4 | using Microsoft.AspNetCore.Mvc; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.Extensions.DependencyInjection; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Threading.Tasks; 13 | using Microsoft.AspNetCore.Authentication.JwtBearer; 14 | using Microsoft.AspNetCore.Http; 15 | using Microsoft.IdentityModel.Tokens; 16 | using ReCapProject.Business.Abstract; 17 | using ReCapProject.Business.Concrete; 18 | using ReCapProject.Core.DependencyResolvers; 19 | using ReCapProject.Core.Extensions; 20 | using ReCapProject.Core.Utilities.IoC; 21 | using ReCapProject.Core.Utilities.Security.Encryption; 22 | using ReCapProject.Core.Utilities.Security.JWT; 23 | using ReCapProject.DataAccess.Abstract; 24 | using ReCapProject.DataAccess.Concrete.EntityFramework; 25 | 26 | namespace WebAPI 27 | { 28 | public class Startup 29 | { 30 | public Startup(IConfiguration configuration) 31 | { 32 | Configuration = configuration; 33 | } 34 | 35 | public IConfiguration Configuration { get; } 36 | 37 | // This method gets called by the runtime. Use this method to add services to the container. 38 | public void ConfigureServices(IServiceCollection services) 39 | { 40 | services.AddControllers(); 41 | //services.AddSingleton(); 42 | //services.AddSingleton(); 43 | //services.AddSingleton(); 44 | //services.AddSingleton(); 45 | //services.AddSingleton(); 46 | //services.AddSingleton(); 47 | //services.AddSingleton(); 48 | //services.AddSingleton(); 49 | //services.AddSingleton(); 50 | //services.AddSingleton(); 51 | //services.AddSingleton(); 52 | //services.AddSingleton(); 53 | services.AddCors(); 54 | 55 | var tokenOptions = Configuration.GetSection("TokenOptions").Get(); 56 | 57 | services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) 58 | .AddJwtBearer(options => 59 | { 60 | options.TokenValidationParameters = new TokenValidationParameters 61 | { 62 | ValidateIssuer = true, 63 | ValidateAudience = true, 64 | ValidateLifetime = true, 65 | ValidIssuer = tokenOptions.Issuer, 66 | ValidAudience = tokenOptions.Audience, 67 | ValidateIssuerSigningKey = true, 68 | IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) 69 | }; 70 | }); 71 | 72 | services.AddDependencyResolvers(new ICoreModule[] 73 | { 74 | new CoreModule() 75 | }); 76 | } 77 | 78 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 79 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 80 | { 81 | if (env.IsDevelopment()) 82 | { 83 | app.UseDeveloperExceptionPage(); 84 | } 85 | 86 | app.ConfigureCustomExceptionMiddleware(); 87 | 88 | app.UseCors(builder=>builder.WithOrigins("http://localhost:4201").AllowAnyHeader()); 89 | 90 | app.UseHttpsRedirection(); 91 | 92 | app.UseRouting(); 93 | 94 | app.UseStaticFiles(); 95 | 96 | app.UseAuthentication(); 97 | 98 | app.UseAuthorization(); 99 | 100 | app.UseEndpoints(endpoints => 101 | { 102 | endpoints.MapControllers(); 103 | }); 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /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 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /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": "ozan@ozan.com", 4 | "Issuer": "ozan@ozan.com", 5 | "AccessTokenExpiration": 10, 6 | "SecurityKey": "mysupersecretkeymysupersecretkey" 7 | }, 8 | "Logging": { 9 | "LogLevel": { 10 | "Default": "Information", 11 | "Microsoft": "Warning", 12 | "Microsoft.Hosting.Lifetime": "Information" 13 | } 14 | }, 15 | "AllowedHosts": "*" 16 | } 17 | -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/07f8041a153345ecac7dcb88090f6857.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzhanet/ReCapProject/1ed4a2b52c93710bec8837b80d54ddbdedb88b1c/WebAPI/wwwroot/Images/07f8041a153345ecac7dcb88090f6857.JPG -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/083bdc5ad5b94464b21bcb7a20323658-3-8-2021.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzhanet/ReCapProject/1ed4a2b52c93710bec8837b80d54ddbdedb88b1c/WebAPI/wwwroot/Images/083bdc5ad5b94464b21bcb7a20323658-3-8-2021.JPG -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/3dd65d62c8e142fa95eaa4601e4128ad.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzhanet/ReCapProject/1ed4a2b52c93710bec8837b80d54ddbdedb88b1c/WebAPI/wwwroot/Images/3dd65d62c8e142fa95eaa4601e4128ad.JPG -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/cc53d921a7e04be6915308bff157acc0.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzhanet/ReCapProject/1ed4a2b52c93710bec8837b80d54ddbdedb88b1c/WebAPI/wwwroot/Images/cc53d921a7e04be6915308bff157acc0.JPG -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/d3e1d3b0a7cc4afaa43401a361316225-2-28-2021.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzhanet/ReCapProject/1ed4a2b52c93710bec8837b80d54ddbdedb88b1c/WebAPI/wwwroot/Images/d3e1d3b0a7cc4afaa43401a361316225-2-28-2021.JPG -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/d4f7916a8b444381a531f2f5ecbda9ae.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzhanet/ReCapProject/1ed4a2b52c93710bec8837b80d54ddbdedb88b1c/WebAPI/wwwroot/Images/d4f7916a8b444381a531f2f5ecbda9ae.JPG -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/default.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzhanet/ReCapProject/1ed4a2b52c93710bec8837b80d54ddbdedb88b1c/WebAPI/wwwroot/Images/default.PNG --------------------------------------------------------------------------------