├── .gitattributes ├── .gitignore ├── Business ├── Abstract │ ├── IAuthService.cs │ ├── IBrandService.cs │ ├── ICarImageService.cs │ ├── ICarService.cs │ ├── IColorService.cs │ ├── ICustomerService.cs │ ├── IRentalService.cs │ └── IUserService.cs ├── Business.csproj ├── BusinessAspects │ └── Autofac │ │ └── SecuredOperation.cs ├── Concrete │ ├── AuthManager.cs │ ├── BrandManager.cs │ ├── CarImageManager.cs │ ├── CarManager.cs │ ├── ColorManager.cs │ ├── CustomerManager.cs │ ├── RentalManager.cs │ └── UserManager.cs ├── Constants │ └── Messages.cs ├── DependencyResolver │ └── Autofac │ │ └── AutofacBusinessModule.cs └── ValidationRules │ └── FluentValidation │ ├── BrandValidator.cs │ ├── CarImageValidator.cs │ ├── CarValidator.cs │ ├── ColorValidator.cs │ ├── CustomerValidator.cs │ ├── RantalValidator.cs │ └── UserValidator.cs ├── ConsoleUI ├── ConsoleUI.csproj └── Program.cs ├── Core ├── Aspects │ └── Autofac │ │ ├── Caching │ │ ├── CacheAspect.cs │ │ └── CacheRemoveAspect.cs │ │ ├── Performance │ │ └── PerformanceAspect.cs │ │ ├── Transaction │ │ └── TransactionScopeAspect.cs │ │ └── Validation │ │ └── ValidationAspect.cs ├── Core.csproj ├── CrossCuttingConcerns │ ├── Caching │ │ ├── ICacheManager.cs │ │ └── Microsoft │ │ │ └── MemoryCacheManager.cs │ └── Validation │ │ └── ValidationTool.cs ├── DataAccess │ ├── EntityFramework │ │ └── EfEntityRepositoryBase.cs │ └── IEntityRepository.cs ├── DependencyResolver │ └── CoreModule.cs ├── Entities │ ├── Concrete │ │ ├── OperatiomClaim.cs │ │ ├── User.cs │ │ └── UserOperationClaim.cs │ ├── IDto.cs │ └── IEntity.cs ├── Extensions │ ├── ClaimExtensions.cs │ ├── ClaimsPrincipalExtensions.cs │ └── ServiceCollectionExtensions.cs └── Utilities │ ├── Business │ └── BusinessRules.cs │ ├── Interceptors │ ├── AspectInterceptorSelector.cs │ ├── MethodInterception.cs │ └── MethodInterceptionBaseAttribute.cs │ ├── IoC │ ├── ICoreModule.cs │ └── ServiceTool.cs │ ├── Results │ ├── DataResult.cs │ ├── ErrorDataResult.cs │ ├── ErrorResult.cs │ ├── IDataResult.cs │ ├── IResult.cs │ ├── Result.cs │ ├── SuccessDataResult.cs │ └── SuccessResult.cs │ └── Security │ ├── Encryption │ ├── SecurityKeyHelper.cs │ └── SigningCredentialsHelper.cs │ ├── Hashing │ └── HashingHelper.cs │ └── JWT │ ├── AccessToken.cs │ ├── ITokenHelper.cs │ ├── JwtHelper.cs │ └── TokenOptions.cs ├── DataAccess ├── Abstract │ ├── IBrandDal.cs │ ├── ICarDal.cs │ ├── ICarImageDal.cs │ ├── IColorDal.cs │ ├── ICustomerDal.cs │ ├── IRentalDal.cs │ └── IUserDal.cs ├── Concrete │ ├── EntityFramework │ │ ├── CarDatabaseContext.cs │ │ ├── EfBrandDal.cs │ │ ├── EfCarDal.cs │ │ ├── EfCarImageDal.cs │ │ ├── EfColorDal.cs │ │ ├── EfCustomerDal.cs │ │ ├── EfRentalDal.cs │ │ └── EfUserDal.cs │ └── InMemory │ │ └── InMemoryCarDal.cs └── DataAccess.csproj ├── Entities ├── Concrete │ ├── Brand.cs │ ├── Car.cs │ ├── CarImage.cs │ ├── Color.cs │ ├── Customer.cs │ └── Rental.cs ├── DTOs │ ├── CarDetailsDto.cs │ ├── UserForLoginDto.cs │ └── UserForRegisterDto.cs └── Entities.csproj ├── ReCapProject.sln └── WebAPI ├── Controllers ├── AuthController.cs ├── BrandsController.cs ├── CarImagesController.cs ├── CarsController.cs ├── ColorsController.cs ├── CustomersController.cs ├── RentalsController.cs └── WeatherForecastController.cs ├── Program.cs ├── Properties └── launchSettings.json ├── Startup.cs ├── WeatherForecast.cs ├── WebAPI.csproj ├── appsettings.Development.json └── appsettings.json /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /Business/Abstract/IAuthService.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Core.Utilities.Results; 3 | using Core.Utilities.Security.JWT; 4 | using Entities.DTOs; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace Business.Abstract 10 | { 11 | public interface IAuthService 12 | { 13 | IDataResult Register(UserForRegisterDto userForRegisterDto, string password); 14 | IDataResult Login(UserForLoginDto userForLoginDto); 15 | IResult UserExist(string email); 16 | IDataResult CreateAccessToken(User user); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Business/Abstract/IBrandService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq.Expressions; 6 | using System.Text; 7 | 8 | namespace Business.Abstract 9 | { 10 | public interface IBrandService 11 | { 12 | IResult Add(Brand brand); 13 | IResult Update(Brand brand); 14 | IResult Delete(Brand brand); 15 | IDataResult> GetAll(); 16 | IDataResult GetById(int brandId); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Business/Abstract/ICarImageService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface ICarImageService 10 | { 11 | IResult Add(CarImage carImage); 12 | IResult Update(CarImage carImage); 13 | IResult Delete(CarImage carImage); 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int imageId); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Business/Abstract/ICarService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace Business.Abstract 9 | { 10 | public interface ICarService 11 | { 12 | IResult Add(Car car); 13 | IResult Update(Car car); 14 | IResult Delete(Car car); 15 | IDataResult> GetAll(); 16 | IDataResult GetById(int id); 17 | IDataResult> GetCarDetails(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Business/Abstract/IColorService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface IColorService 10 | { 11 | IResult Add(Color color); 12 | IResult Update(Color color); 13 | IResult Delete(Color color); 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int colorId); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Business/Abstract/ICustomerService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface ICustomerService 10 | { 11 | IResult Add(Customer customer); 12 | IResult Update(Customer customer); 13 | IResult Delete(Customer customer); 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int customerId); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Business/Abstract/IRentalService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface IRentalService 10 | { 11 | IResult Add(Rental rental); 12 | IResult Update(Rental rental); 13 | IResult Delete(Rental rental); 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int rentalId); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Business/Abstract/IUserService.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Core.Utilities.Results; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace Business.Abstract 9 | { 10 | public interface IUserService 11 | { 12 | List GetClaims(User user); 13 | User GetByMail(string email); 14 | void Add(User user); 15 | IResult Update(User user); 16 | IResult Delete(User user); 17 | IDataResult> GetAll(); 18 | IDataResult GetById(int userId); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Business/Business.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Business/BusinessAspects/Autofac/SecuredOperation.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.Extensions; 3 | using Core.Utilities.Interceptors; 4 | using Microsoft.AspNetCore.Http; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Core.Utilities.IoC; 10 | using Business.Constants; 11 | 12 | namespace Business.BusinessAspects.Autofac 13 | { 14 | public class SecuredOperation : MethodInterception 15 | { 16 | private string[] _roles; 17 | private IHttpContextAccessor _httpContextAccessor;//jwt isteklerini her kişi için 18 | 19 | public SecuredOperation(string roles) 20 | { 21 | _roles = roles.Split(','); // rolleri belirttiğim karaktere göre ayrıp array e atıyor.. 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 | -------------------------------------------------------------------------------- /Business/Concrete/AuthManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Core.Entities.Concrete; 4 | using Core.Utilities.Results; 5 | using Core.Utilities.Security.Hashing; 6 | using Core.Utilities.Security.JWT; 7 | using Entities.DTOs; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Text; 11 | 12 | namespace Business.Concrete 13 | { 14 | public class AuthManager : IAuthService 15 | { 16 | IUserService _userService; 17 | ITokenHelper _tokenHelper; 18 | 19 | public AuthManager(IUserService userService, ITokenHelper tokenHelper) 20 | { 21 | _userService = userService; 22 | _tokenHelper = tokenHelper; 23 | } 24 | 25 | public IDataResult CreateAccessToken(User user) 26 | { 27 | var claims = _userService.GetClaims(user); 28 | var accessToken = _tokenHelper.CreateToken(user, claims); 29 | return new SuccessDataResult(accessToken, Messages.AccessTokenCreated); 30 | } 31 | 32 | public IDataResult Login(UserForLoginDto userForLoginDto) 33 | { 34 | var userToCheck = _userService.GetByMail(userForLoginDto.Email); 35 | if(userToCheck == null) 36 | { 37 | return new ErrorDataResult(Messages.UserNotFound); 38 | } 39 | if(!HashingHelper.VerifyPasswordHash(userForLoginDto.Password,userToCheck.PasswordHash,userToCheck.PasswordSalt)) 40 | { 41 | return new ErrorDataResult(Messages.PasswordIncorrect); 42 | } 43 | return new SuccessDataResult(userToCheck, Messages.SuccessfullLogin); 44 | } 45 | 46 | public IDataResult Register(UserForRegisterDto userForRegisterDto, string password) 47 | { 48 | byte[] passwordHash, passwordSalt; 49 | HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt); 50 | var user = new User 51 | { 52 | Email = userForRegisterDto.Email, 53 | FirstName = userForRegisterDto.FirstName, 54 | LastName = userForRegisterDto.LastName, 55 | PasswordHash = passwordHash, 56 | PasswordSalt = passwordSalt, 57 | Status = true 58 | }; 59 | _userService.Add(user); 60 | return new SuccessDataResult(user, Messages.UserRegisteredSuccessfully); 61 | } 62 | 63 | public IResult UserExist(string email) 64 | { 65 | if(_userService.GetByMail(email) != null) 66 | { 67 | return new ErrorResult(Messages.UserExist); 68 | } 69 | return new SuccessResult(); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Business/Concrete/BrandManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Core.Utilities.Results; 4 | using DataAccess.Abstract; 5 | using Entities.Concrete; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq.Expressions; 9 | using System.Text; 10 | 11 | namespace Business.Concrete 12 | { 13 | public class BrandManager : IBrandService 14 | { 15 | IBrandDal _brandDal; 16 | 17 | public BrandManager(IBrandDal brandDal) 18 | { 19 | _brandDal = brandDal; 20 | } 21 | 22 | public IResult Add(Brand brand) 23 | { 24 | _brandDal.Add(brand); 25 | return new SuccessResult(Messages.AddedSuccessfully); 26 | } 27 | 28 | public IResult Delete(Brand brand) 29 | { 30 | _brandDal.Delete(brand); 31 | return new SuccessResult(Messages.DeletedSuccessfully); 32 | } 33 | 34 | public IDataResult GetById(int brandId) 35 | { 36 | return new SuccessDataResult(_brandDal.Get(b => b.BrandId == brandId)); 37 | } 38 | 39 | public IDataResult> GetAll() 40 | { 41 | return new SuccessDataResult>(_brandDal.GetAll()); 42 | } 43 | 44 | public IResult Update(Brand brand) 45 | { 46 | _brandDal.Update(brand); 47 | return new SuccessResult(Messages.UpdatedSuccessfully); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Business/Concrete/CarImageManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Business.ValidationRules.FluentValidation; 4 | using Core.Aspects.Autofac.Validation; 5 | using Core.Utilities.Results; 6 | using DataAccess.Abstract; 7 | using Entities.Concrete; 8 | using Entities.DTOs; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Text; 12 | 13 | namespace Business.Concrete 14 | { 15 | public class CarImageManager : ICarImageService 16 | { 17 | ICarImageDal _carImageDal; 18 | 19 | public CarImageManager(ICarImageDal carImageDal) 20 | { 21 | _carImageDal = carImageDal; 22 | } 23 | 24 | [ValidationAspect(typeof(CarImageValidator))] 25 | public IResult Add(CarImage car) 26 | { 27 | _carImageDal.Add(car); 28 | return new SuccessResult(Messages.AddedSuccessfully); 29 | } 30 | 31 | public IResult Delete(CarImage car) 32 | { 33 | _carImageDal.Delete(car); 34 | return new SuccessResult(Messages.DeletedSuccessfully); 35 | } 36 | 37 | public IDataResult> GetAll() 38 | { 39 | return new SuccessDataResult>(_carImageDal.GetAll()); 40 | } 41 | 42 | public IDataResult GetById(int imageId) 43 | { 44 | return new SuccessDataResult(_carImageDal.Get(i => i.Id == imageId)); 45 | } 46 | 47 | 48 | public IResult Update(CarImage car) 49 | { 50 | _carImageDal.Update(car); 51 | return new SuccessResult(Messages.UpdatedSuccessfully); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Business/Concrete/CarManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using DataAccess.Abstract; 3 | using DataAccess.Concrete.EntityFramework; 4 | using Entities.Concrete; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | using System.Linq; 9 | using Entities.DTOs; 10 | using Core.Utilities.Results; 11 | using Business.ValidationRules.FluentValidation; 12 | using Core.Aspects.Autofac.Validation; 13 | using Business.BusinessAspects.Autofac; 14 | using Business.Constants; 15 | 16 | namespace Business.Concrete 17 | { 18 | public class CarManager : ICarService 19 | { 20 | ICarDal _carDal; 21 | 22 | public CarManager(ICarDal carDal) 23 | { 24 | _carDal = carDal; 25 | } 26 | 27 | public IDataResult> GetAll() 28 | { 29 | return new SuccessDataResult>(_carDal.GetAll()); 30 | } 31 | 32 | [SecuredOperation("admin")] 33 | [ValidationAspect(typeof(CarValidator))] 34 | public IResult Add(Car car) 35 | { 36 | _carDal.Add(car); 37 | return new SuccessResult(Messages.AddedSuccessfully); 38 | } 39 | 40 | public IResult Update(Car car) 41 | { 42 | _carDal.Update(car); 43 | return new SuccessResult(Messages.UpdatedSuccessfully); 44 | } 45 | 46 | public IResult Delete(Car car) 47 | { 48 | _carDal.Delete(car); 49 | return new SuccessResult(Messages.DeletedSuccessfully); 50 | } 51 | 52 | public IDataResult GetById(int id) 53 | { 54 | return new SuccessDataResult(_carDal.Get(c => c.Id == id)); 55 | } 56 | 57 | public IDataResult> GetCarDetails() 58 | { 59 | return new SuccessDataResult>(_carDal.GetCarDetails()); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Business/Concrete/ColorManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Core.Utilities.Results; 4 | using DataAccess.Abstract; 5 | using Entities.Concrete; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | 10 | namespace Business.Concrete 11 | { 12 | public class ColorManager : IColorService 13 | { 14 | IColorDal _colorDal; 15 | 16 | public ColorManager(IColorDal colorDal) 17 | { 18 | _colorDal = colorDal; 19 | } 20 | 21 | public IResult Add(Color color) 22 | { 23 | _colorDal.Add(color); 24 | return new SuccessResult(Messages.AddedSuccessfully); 25 | } 26 | 27 | public IResult Delete(Color color) 28 | { 29 | _colorDal.Delete(color); 30 | return new SuccessResult(Messages.DeletedSuccessfully); 31 | } 32 | 33 | public IDataResult> GetAll() 34 | { 35 | return new SuccessDataResult>(_colorDal.GetAll()); 36 | } 37 | 38 | public IDataResult GetById(int colorId) 39 | { 40 | return new SuccessDataResult(_colorDal.Get(c => c.ColorId == colorId)); 41 | } 42 | 43 | public IResult Update(Color color) 44 | { 45 | _colorDal.Update(color); 46 | return new SuccessResult(Messages.UpdatedSuccessfully); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Business/Concrete/CustomerManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Core.Utilities.Results; 4 | using DataAccess.Abstract; 5 | using Entities.Concrete; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | 10 | namespace Business.Concrete 11 | { 12 | public class CustomerManager : ICustomerService 13 | { 14 | ICustomerDal _customerDal; 15 | 16 | public CustomerManager(ICustomerDal customerDal) 17 | { 18 | _customerDal = customerDal; 19 | } 20 | 21 | public IResult Add(Customer customer) 22 | { 23 | _customerDal.Add(customer); 24 | return new SuccessResult(Messages.AddedSuccessfully); 25 | } 26 | 27 | public IResult Delete(Customer customer) 28 | { 29 | _customerDal.Delete(customer); 30 | return new SuccessResult(Messages.DeletedSuccessfully); 31 | } 32 | 33 | public IDataResult> GetAll() 34 | { 35 | return new SuccessDataResult>(_customerDal.GetAll(), Messages.ListedSuccessfully); 36 | } 37 | 38 | public IDataResult GetById(int customerId) 39 | { 40 | return new SuccessDataResult(_customerDal.Get(c=>c.CustomerId == customerId)); 41 | } 42 | 43 | public IResult Update(Customer customer) 44 | { 45 | _customerDal.Update(customer); 46 | return new SuccessResult(Messages.UpdatedSuccessfully); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Business/Concrete/RentalManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Core.Utilities.Results; 4 | using DataAccess.Abstract; 5 | using Entities.Concrete; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | 10 | namespace Business.Concrete 11 | { 12 | public class RentalManager : IRentalService 13 | { 14 | IRentalDal _rentalDal; 15 | 16 | public RentalManager(IRentalDal rentalDal) 17 | { 18 | _rentalDal = rentalDal; 19 | } 20 | 21 | public IResult Add(Rental rental) 22 | { 23 | if (_rentalDal.Get(r => r.CarId == rental.CarId).ReturnDate == null) 24 | { 25 | return new ErrorResult(Messages.RentalOperationFailed); 26 | } 27 | else 28 | { 29 | _rentalDal.Add(rental); 30 | return new SuccessResult(Messages.RentalOperationSuccedd); 31 | } 32 | } 33 | 34 | public IResult Delete(Rental rental) 35 | { 36 | _rentalDal.Delete(rental); 37 | return new SuccessResult(); 38 | } 39 | 40 | public IDataResult> GetAll() 41 | { 42 | return new SuccessDataResult>(_rentalDal.GetAll()); 43 | } 44 | 45 | public IDataResult GetById(int rentalId) 46 | { 47 | return new SuccessDataResult(_rentalDal.Get(r=>r.RentalId == rentalId)); 48 | } 49 | 50 | public IResult Update(Rental rental) 51 | { 52 | _rentalDal.Update(rental); 53 | return new SuccessResult(); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Business/Concrete/UserManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Core.Entities.Concrete; 4 | using Core.Utilities.Results; 5 | using DataAccess.Abstract; 6 | using Entities.Concrete; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | 11 | namespace Business.Concrete 12 | { 13 | public class UserManager : IUserService 14 | { 15 | IUserDal _userDal; 16 | 17 | public UserManager(IUserDal userDal) 18 | { 19 | _userDal = userDal; 20 | } 21 | 22 | public void Add(User user) 23 | { 24 | _userDal.Add(user); 25 | } 26 | 27 | public IResult Delete(User user) 28 | { 29 | _userDal.Delete(user); 30 | return new SuccessResult(Messages.DeletedSuccessfully); 31 | } 32 | 33 | public IDataResult> GetAll() 34 | { 35 | return new SuccessDataResult>(_userDal.GetAll()); 36 | } 37 | 38 | public IDataResult GetById(int userId) 39 | { 40 | return new SuccessDataResult(_userDal.Get(u => u.UserId == userId)); 41 | } 42 | 43 | public User GetByMail(string email) 44 | { 45 | return _userDal.Get(u => u.Email == email); 46 | } 47 | 48 | public List GetClaims(User user) 49 | { 50 | return _userDal.GetClaims(user); 51 | } 52 | 53 | public IResult Update(User user) 54 | { 55 | _userDal.Update(user); 56 | return new SuccessResult(Messages.UpdatedSuccessfully); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Business/Constants/Messages.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Runtime.Serialization; 5 | using System.Text; 6 | 7 | namespace Business.Constants 8 | { 9 | public static class Messages 10 | { 11 | public static string AuthorizationDenied = "Bu alana ulaşma yetkiniz yok."; 12 | 13 | public static string AddedSuccessfully = "Bilgiler veri tabanına başarı ile eklendi."; 14 | public static string UpdatedSuccessfully = "Bilgiler başarı ile güncellendi."; 15 | public static string DeletedSuccessfully = "Bilgiler veri tabanından başarı ile silindi"; 16 | public static string ListedSuccessfully = "Bilgiler başarı ile listelendi."; 17 | 18 | public static string RentalOperationFailed = "Kiralama işlemi başarısız."; 19 | public static string RentalOperationSuccedd = "Kiralama işlemi başarı ile gerçekleştirildi."; 20 | 21 | public static string AccessTokenCreated = "Access Token başarı ile oluşturuldu."; 22 | public static string UserNotFound = "Kullanıcı bulunamadı."; 23 | public static string PasswordIncorrect = "Şifre hatalı."; 24 | public static string SuccessfullLogin = "Giriş başarılı."; 25 | public static string UserExist = "Kullanıcı mevcut"; 26 | public static string UserRegisteredSuccessfully = "Kullanıcı başarı ile kayıt edildi."; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Business/DependencyResolver/Autofac/AutofacBusinessModule.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Extras.DynamicProxy; 3 | using Business.Abstract; 4 | using Business.Concrete; 5 | using Castle.DynamicProxy; 6 | using Core.Utilities.Interceptors; 7 | using Core.Utilities.Security.JWT; 8 | using DataAccess.Abstract; 9 | using DataAccess.Concrete.EntityFramework; 10 | using Microsoft.AspNetCore.Http; 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Text; 14 | 15 | namespace Business.DependencyResolver.Autofac 16 | { 17 | public class AutofacBusinessModule : Module 18 | { 19 | protected override void Load(ContainerBuilder builder) 20 | { 21 | builder.RegisterType().As().SingleInstance(); 22 | builder.RegisterType().As().SingleInstance(); 23 | 24 | builder.RegisterType().As().SingleInstance(); 25 | builder.RegisterType().As().SingleInstance(); 26 | 27 | builder.RegisterType().As().SingleInstance(); 28 | builder.RegisterType().As().SingleInstance(); 29 | 30 | builder.RegisterType().As().SingleInstance(); 31 | builder.RegisterType().As().SingleInstance(); 32 | 33 | builder.RegisterType().As().SingleInstance(); 34 | builder.RegisterType().As().SingleInstance(); 35 | 36 | builder.RegisterType().As().SingleInstance(); 37 | builder.RegisterType().As().SingleInstance(); 38 | 39 | builder.RegisterType().As().SingleInstance(); 40 | builder.RegisterType().As().SingleInstance(); 41 | 42 | builder.RegisterType().As().SingleInstance(); 43 | builder.RegisterType().As().SingleInstance(); 44 | 45 | builder.RegisterType().As(); 46 | 47 | var assembly = System.Reflection.Assembly.GetExecutingAssembly(); 48 | 49 | builder.RegisterAssemblyTypes(assembly).AsImplementedInterfaces() 50 | .EnableInterfaceInterceptors(new ProxyGenerationOptions() 51 | { 52 | Selector = new AspectInterceptorSelector() 53 | }).SingleInstance(); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/BrandValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class BrandValidator : AbstractValidator 10 | { 11 | public BrandValidator() 12 | { 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/CarImageValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class CarImageValidator : AbstractValidator 10 | { 11 | public CarImageValidator() 12 | { 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/CarValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class CarValidator : AbstractValidator 10 | { 11 | public CarValidator() 12 | { 13 | RuleFor(c => c.DailyPrice).GreaterThan(0); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/ColorValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class ColorValidator : AbstractValidator 10 | { 11 | public ColorValidator() 12 | { 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/CustomerValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class CustomerValidator : AbstractValidator 10 | { 11 | public CustomerValidator() 12 | { 13 | //doğrulama kodları buraya gelecek. 14 | RuleFor(c => c.CompanyName).MinimumLength(3); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/RantalValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class RantalValidator : AbstractValidator 10 | { 11 | public RantalValidator() 12 | { 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/UserValidator.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Entities.Concrete; 3 | using FluentValidation; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace Business.ValidationRules.FluentValidation 9 | { 10 | class UserValidator : AbstractValidator 11 | { 12 | public UserValidator() 13 | { 14 | 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ConsoleUI/ConsoleUI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ConsoleUI/Program.cs: -------------------------------------------------------------------------------- 1 | using Business.Concrete; 2 | using Core.Entities.Concrete; 3 | using DataAccess.Concrete.EntityFramework; 4 | using DataAccess.Concrete.InMemory; 5 | using Entities.Concrete; 6 | using System; 7 | 8 | namespace ConsoleUI 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | //CarTest(); 15 | //BrandTest(); 16 | //ColorTest(); 17 | //CustomerTest(); 18 | RentalTest(); 19 | //UserTest(); 20 | } 21 | 22 | private static void UserTest() 23 | { 24 | UserManager userManager = new UserManager(new EfUserDal()); 25 | // userManager.Add(new User { UserId = 1, FirstName = "Ebru", LastName = "Terziogu", Email = "eterzioglu8", Password = "12345" }); 26 | } 27 | 28 | private static void RentalTest() 29 | { 30 | RentalManager rentalManager = new RentalManager(new EfRentalDal()); 31 | rentalManager.Add(new Rental { RentalId = 7, CarId = 3, CustomerId = 1}); 32 | 33 | //foreach (var rental in rentalManager.GetAll().Data) 34 | //{ 35 | // Console.WriteLine(rental.RentalId); 36 | //} 37 | } 38 | 39 | private static void CustomerTest() 40 | { 41 | CustomerManager customerManager = new CustomerManager(new EfCustomerDal()); 42 | //customerManager.Add(new Customer { CustomerId = 2, UserId = 2, CompanyName = "Allianz" }); 43 | 44 | foreach (var customer in customerManager.GetAll().Data) 45 | { 46 | Console.WriteLine(customer.CompanyName); 47 | } 48 | } 49 | 50 | private static void ColorTest() 51 | { 52 | ColorManager colorManager = new ColorManager(new EfColorDal()); 53 | 54 | foreach (var color in colorManager.GetAll().Data) 55 | { 56 | Console.WriteLine(color.ColorName); 57 | } 58 | } 59 | 60 | private static void BrandTest() 61 | { 62 | BrandManager brandManager = new BrandManager(new EfBrandDal()); 63 | 64 | foreach (var brand in brandManager.GetAll().Data) 65 | { 66 | Console.WriteLine(brand.BrandName); 67 | } 68 | } 69 | 70 | private static void CarTest() 71 | { 72 | CarManager carManager = new CarManager(new EfCarDal()); 73 | 74 | foreach (var car in carManager.GetCarDetails().Data) 75 | { 76 | Console.WriteLine(car.CarName + " / " + car.ColorName + " / " +car.BrandName); 77 | } 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Caching/CacheAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.CrossCuttingConcerns.Caching; 3 | using Core.Utilities.Interceptors; 4 | using Core.Utilities.IoC; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using System.Linq; 10 | 11 | namespace Core.Aspects.Autofac.Caching 12 | { 13 | public class CacheAspect : MethodInterception 14 | { 15 | private int _duration; 16 | private ICacheManager _cacheManager; 17 | 18 | public CacheAspect(int duration = 60) 19 | { 20 | _duration = duration; 21 | _cacheManager = ServiceTool.ServiceProvider.GetService(); 22 | } 23 | 24 | public override void Intercept(IInvocation invocation) 25 | { 26 | var methodName = string.Format($"{invocation.Method.ReflectedType.FullName}.{invocation.Method.Name}"); 27 | var arguments = invocation.Arguments.ToList(); 28 | var key = $"{methodName}({string.Join(",", arguments.Select(x => x?.ToString() ?? ""))})";//varsa bunu ekle yoksa null de.. 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 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Caching/CacheRemoveAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.CrossCuttingConcerns.Caching; 3 | using Core.Utilities.Interceptors; 4 | using Core.Utilities.IoC; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | using Microsoft.Extensions.DependencyInjection; 9 | 10 | namespace Core.Aspects.Autofac.Caching 11 | { 12 | public class CacheRemoveAspect : MethodInterception 13 | { 14 | private string _pattern; 15 | private ICacheManager _cacheManager; 16 | 17 | public CacheRemoveAspect(string pattern) 18 | { 19 | _pattern = pattern; 20 | _cacheManager = ServiceTool.ServiceProvider.GetService(); 21 | } 22 | 23 | protected override void OnSuccess(IInvocation invocation) 24 | { 25 | _cacheManager.RemoveByPattern(_pattern); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Performance/PerformanceAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.Utilities.Interceptors; 3 | using Core.Utilities.IoC; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Diagnostics; 7 | using System.Text; 8 | using Microsoft.Extensions.DependencyInjection; 9 | 10 | namespace Core.Aspects.Autofac.Performance 11 | { 12 | public class PerformanceAspect : MethodInterception 13 | { 14 | private int _interval; 15 | private Stopwatch _stopwatch; 16 | 17 | public PerformanceAspect(int interval) 18 | { 19 | _interval = interval; 20 | _stopwatch = ServiceTool.ServiceProvider.GetService(); 21 | } 22 | 23 | 24 | protected override void OnBefore(IInvocation invocation) 25 | { 26 | _stopwatch.Start(); 27 | } 28 | 29 | protected override void OnAfter(IInvocation invocation) 30 | { 31 | if (_stopwatch.Elapsed.TotalSeconds > _interval) 32 | { 33 | Debug.WriteLine($"Performance : {invocation.Method.DeclaringType.FullName}.{invocation.Method.Name}-->{_stopwatch.Elapsed.TotalSeconds}"); 34 | } 35 | _stopwatch.Reset(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Transaction/TransactionScopeAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.Utilities.Interceptors; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using System.Transactions; 7 | 8 | namespace Core.Aspects.Autofac.Transaction 9 | { 10 | public class TransactionScopeAspect : MethodInterception 11 | { 12 | public override void Intercept(IInvocation invocation) 13 | { 14 | using (TransactionScope transactionScope = new TransactionScope()) 15 | { 16 | try 17 | { 18 | invocation.Proceed(); 19 | transactionScope.Complete(); 20 | } 21 | catch (System.Exception e) 22 | { 23 | transactionScope.Dispose(); 24 | throw; 25 | } 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Validation/ValidationAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.CrossCuttingConcerns.Validation; 3 | using Core.Utilities.Interceptors; 4 | using FluentValidation; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | namespace Core.Aspects.Autofac.Validation 11 | { 12 | public class ValidationAspect : MethodInterception 13 | { 14 | private Type _validatorType; 15 | public ValidationAspect(Type validatorType) 16 | { 17 | if (!typeof(IValidator).IsAssignableFrom(validatorType)) 18 | { 19 | throw new System.Exception("Bu bir doğrulama sınıfı değil"); 20 | } 21 | 22 | _validatorType = validatorType; 23 | } 24 | protected override void OnBefore(IInvocation invocation) 25 | { 26 | var validator = (IValidator)Activator.CreateInstance(_validatorType); 27 | var entityType = _validatorType.BaseType.GetGenericArguments()[0]; 28 | var entities = invocation.Arguments.Where(t => t.GetType() == entityType); 29 | foreach (var entity in entities) 30 | { 31 | ValidationTool.Validate(validator, entity); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Core/Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Caching/ICacheManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Caching 6 | { 7 | public interface ICacheManager 8 | { 9 | T Get(string key); 10 | object Get(string key); 11 | void Add(string key, object value, int duration); 12 | bool IsAdd(string key); 13 | void Remove(string key); 14 | void RemoveByPattern(string pattern); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Caching/Microsoft/MemoryCacheManager.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.IoC; 2 | using Microsoft.Extensions.Caching.Memory; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Text.RegularExpressions; 9 | 10 | namespace Core.CrossCuttingConcerns.Caching.Microsoft 11 | { 12 | class MemoryCacheManager : ICacheManager 13 | { 14 | IMemoryCache _memoryCache; 15 | 16 | public MemoryCacheManager() 17 | { 18 | _memoryCache = ServiceTool.ServiceProvider.GetService(); 19 | } 20 | 21 | public void Add(string key, object value, int duration) 22 | { 23 | _memoryCache.Set(key, value, TimeSpan.FromMinutes(duration)); 24 | } 25 | 26 | public T Get(string key) 27 | { 28 | return _memoryCache.Get(key); 29 | } 30 | 31 | public object Get(string key) 32 | { 33 | return _memoryCache.Get(key); 34 | } 35 | 36 | public bool IsAdd(string key) 37 | { 38 | return _memoryCache.TryGetValue(key, out _); 39 | } 40 | 41 | public void Remove(string key) 42 | { 43 | _memoryCache.Remove(key); 44 | } 45 | 46 | public void RemoveByPattern(string pattern) 47 | { 48 | var cacheEntriesCollectionDefinition = typeof(MemoryCache).GetProperty("EntriesCollection", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); 49 | var cacheEntriesCollection = cacheEntriesCollectionDefinition.GetValue(_memoryCache) as dynamic; 50 | List cacheCollectionValues = new List(); 51 | 52 | foreach (var cacheItem in cacheEntriesCollection) 53 | { 54 | ICacheEntry cacheItemValue = cacheItem.GetType().GetProperty("Value").GetValue(cacheItem, null); 55 | cacheCollectionValues.Add(cacheItemValue); 56 | } 57 | 58 | var regex = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase); 59 | var keysToRemove = cacheCollectionValues.Where(d => regex.IsMatch(d.Key.ToString())).Select(d => d.Key).ToList(); 60 | 61 | foreach (var key in keysToRemove) 62 | { 63 | _memoryCache.Remove(key); 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Validation/ValidationTool.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.CrossCuttingConcerns.Validation 7 | { 8 | public static class ValidationTool 9 | { 10 | public static void Validate(IValidator validator,object entity) 11 | { 12 | var context = new ValidationContext(entity); 13 | var result = validator.Validate(context); 14 | 15 | if (!result.IsValid) 16 | { 17 | throw new ValidationException(result.Errors); 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Core/DataAccess/EntityFramework/EfEntityRepositoryBase.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using Microsoft.EntityFrameworkCore; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Linq.Expressions; 7 | using System.Text; 8 | 9 | namespace Core.DataAccess.EntityFramework 10 | { 11 | public class EfEntityRepositoryBase : IEntityRepository 12 | where TEntity:class,IEntity, new() 13 | where TContext:DbContext, new() 14 | { 15 | public void Add(TEntity entity) 16 | { 17 | using (TContext context = new TContext()) 18 | { 19 | var addedEntity = context.Entry(entity); 20 | addedEntity.State = EntityState.Added; 21 | context.SaveChanges(); 22 | } 23 | } 24 | 25 | public void Delete(TEntity entity) 26 | { 27 | using (TContext context = new TContext()) 28 | { 29 | var deletedEntity = context.Entry(entity); 30 | deletedEntity.State = EntityState.Deleted; 31 | context.SaveChanges(); 32 | } 33 | } 34 | 35 | public TEntity Get(Expression> filter) 36 | { 37 | using (TContext context = new TContext()) 38 | { 39 | return context.Set().SingleOrDefault(filter); 40 | } 41 | } 42 | 43 | public List GetAll(Expression> filter = null) 44 | { 45 | using (TContext context = new TContext()) 46 | { 47 | return filter == null ? context.Set().ToList() : context.Set().Where(filter).ToList(); 48 | } 49 | } 50 | 51 | public void Update(TEntity entity) 52 | { 53 | using (TContext context = new TContext()) 54 | { 55 | var updatedEntity = context.Entry(entity); 56 | updatedEntity.State = EntityState.Modified; 57 | context.SaveChanges(); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Core/DataAccess/IEntityRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Text; 5 | 6 | namespace Core.DataAccess 7 | 8 | { 9 | public interface IEntityRepository 10 | { 11 | List GetAll(Expression> filter = null); 12 | T Get(Expression> filter); 13 | void Add(T entity); 14 | void Update(T entity); 15 | void Delete(T entity); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Core/DependencyResolver/CoreModule.cs: -------------------------------------------------------------------------------- 1 | using Core.CrossCuttingConcerns.Caching; 2 | using Core.CrossCuttingConcerns.Caching.Microsoft; 3 | using Core.Utilities.IoC; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.Extensions.DependencyInjection; 6 | 7 | namespace Core.DependencyResolver 8 | { 9 | public class CoreModule : ICoreModule 10 | { 11 | public void Load(IServiceCollection serviceCollection) 12 | { 13 | serviceCollection.AddMemoryCache(); 14 | serviceCollection.AddSingleton(); 15 | serviceCollection.AddSingleton(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/OperatiomClaim.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities.Concrete 6 | { 7 | public class OperationClaim : IEntity 8 | { 9 | public int Id { get; set; } 10 | public string Name { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities.Concrete 6 | { 7 | public class User:IEntity 8 | { 9 | public int UserId { get; set; } 10 | public string FirstName { get; set; } 11 | public string LastName { get; set; } 12 | public string Email { get; set; } 13 | public byte[] PasswordSalt { get; set; } 14 | public byte[] PasswordHash { get; set; } 15 | public bool Status { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/UserOperationClaim.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities.Concrete 6 | { 7 | public class UserOperationClaim : IEntity 8 | { 9 | public int Id { get; set; } 10 | public int UserId { get; set; } 11 | public int OperationClaimId { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/Entities/IDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities 6 | { 7 | public interface IDto 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Core/Entities/IEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities 6 | { 7 | public interface IEntity 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Core/Extensions/ClaimExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IdentityModel.Tokens.Jwt; 4 | using System.Linq; 5 | using System.Security.Claims; 6 | using System.Text; 7 | 8 | namespace Core.Extensions 9 | { 10 | public static class ClaimExtensions 11 | { 12 | public static void AddEmail(this ICollection claims, string email) 13 | { 14 | claims.Add(new Claim(JwtRegisteredClaimNames.Email, email)); 15 | } 16 | 17 | public static void AddName(this ICollection claims, string name) 18 | { 19 | claims.Add(new Claim(ClaimTypes.Name, name)); 20 | } 21 | 22 | public static void AddNameIdentifier(this ICollection claims, string nameIdentifier) 23 | { 24 | claims.Add(new Claim(ClaimTypes.NameIdentifier, nameIdentifier)); 25 | } 26 | 27 | public static void AddRoles(this ICollection claims, string[] roles) 28 | { 29 | roles.ToList().ForEach(role => claims.Add(new Claim(ClaimTypes.Role, role))); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Core/Extensions/ClaimsPrincipalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Claims; 5 | using System.Text; 6 | 7 | namespace Core.Extensions 8 | { 9 | public static class ClaimsPrincipalExtensions 10 | { 11 | public static List Claims(this ClaimsPrincipal claimsPrincipal, string claimType) 12 | { 13 | var result = claimsPrincipal?.FindAll(claimType)?.Select(x => x.Value).ToList(); 14 | return result; 15 | } 16 | 17 | public static List ClaimRoles(this ClaimsPrincipal claimsPrincipal) 18 | { 19 | return claimsPrincipal?.Claims(ClaimTypes.Role); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Extensions/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.IoC; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Core.Extensions 8 | { 9 | public static class ServiceCollectionExtensions 10 | { 11 | public static IServiceCollection AddDependencyResolvers(this IServiceCollection serviceCollection, ICoreModule[] modules) 12 | { 13 | foreach (var module in modules) 14 | { 15 | module.Load(serviceCollection); 16 | } 17 | 18 | return ServiceTool.Create(serviceCollection); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Core/Utilities/Business/BusinessRules.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Business 7 | { 8 | public class BusinessRules 9 | { 10 | public static IResult Run(params IResult[] logics) 11 | { 12 | foreach (var logic in logics) 13 | { 14 | if (!logic.Success) 15 | { 16 | return logic; 17 | } 18 | } 19 | return null; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/AspectInterceptorSelector.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | 8 | namespace Core.Utilities.Interceptors 9 | { 10 | public class AspectInterceptorSelector : IInterceptorSelector 11 | { 12 | public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) 13 | { 14 | var classAttributes = type.GetCustomAttributes 15 | (true).ToList(); 16 | var methodAttributes = type.GetMethod(method.Name) 17 | .GetCustomAttributes(true); 18 | classAttributes.AddRange(methodAttributes); 19 | 20 | return classAttributes.OrderBy(x => x.Priority).ToArray(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/MethodInterception.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | 4 | namespace Core.Utilities.Interceptors 5 | { 6 | public abstract class MethodInterception : MethodInterceptionBaseAttribute 7 | { 8 | protected virtual void OnBefore(IInvocation invocation) { } 9 | protected virtual void OnAfter(IInvocation invocation) { } 10 | protected virtual void OnException(IInvocation invocation, System.Exception e) { } 11 | protected virtual void OnSuccess(IInvocation invocation) { } 12 | public override void Intercept(IInvocation invocation) 13 | { 14 | var isSuccess = true; 15 | OnBefore(invocation); 16 | try 17 | { 18 | invocation.Proceed(); 19 | } 20 | catch (Exception e) 21 | { 22 | isSuccess = false; 23 | OnException(invocation, e); 24 | throw; 25 | } 26 | finally 27 | { 28 | if (isSuccess) 29 | { 30 | OnSuccess(invocation); 31 | } 32 | } 33 | OnAfter(invocation); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/MethodInterceptionBaseAttribute.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | 4 | namespace Core.Utilities.Interceptors 5 | { 6 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] 7 | public abstract class MethodInterceptionBaseAttribute : Attribute, IInterceptor 8 | { 9 | public int Priority { get; set; } 10 | 11 | public virtual void Intercept(IInvocation invocation) 12 | { 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Core/Utilities/IoC/ICoreModule.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.IoC 7 | { 8 | public interface ICoreModule 9 | { 10 | void Load(IServiceCollection serviceCollection); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Utilities/IoC/ServiceTool.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.IoC 7 | { 8 | public static class ServiceTool 9 | { 10 | public static IServiceProvider ServiceProvider { get; private set; } 11 | 12 | public static IServiceCollection Create(IServiceCollection services) 13 | { 14 | ServiceProvider = services.BuildServiceProvider(); 15 | return services; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Core/Utilities/Results/DataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class DataResult : Result, IDataResult 8 | { 9 | public DataResult(T data,bool success,string message):base(success,message) 10 | { 11 | Data = data; 12 | } 13 | 14 | public DataResult(T data,bool success):base(success) 15 | { 16 | Data = data; 17 | } 18 | 19 | 20 | public T Data { get; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Utilities/Results/ErrorDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class ErrorDataResult : DataResult 8 | { 9 | public ErrorDataResult(T data, string message) : base(data, false, message) 10 | { 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 | -------------------------------------------------------------------------------- /Core/Utilities/Results/ErrorResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class ErrorResult:Result 8 | { 9 | public ErrorResult(string message):base(false, message) 10 | { 11 | 12 | } 13 | 14 | public ErrorResult():base(false) 15 | { 16 | 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Core/Utilities/Results/IDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public interface IDataResult:IResult 8 | { 9 | T Data { get; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Core/Utilities/Results/IResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public interface IResult 8 | { 9 | bool Success { get; } 10 | string Message { get; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Utilities/Results/Result.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class Result : IResult 8 | { 9 | 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 | 19 | public bool Success { get; } 20 | 21 | public string Message { get; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Core/Utilities/Results/SuccessDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class SuccessDataResult: DataResult 8 | { 9 | public SuccessDataResult(T data,string message):base(data,true,message) 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 | -------------------------------------------------------------------------------- /Core/Utilities/Results/SuccessResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class SuccessResult : Result 8 | { 9 | public SuccessResult(string message):base(true,message) 10 | { 11 | 12 | } 13 | 14 | public SuccessResult():base(true) 15 | { 16 | 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Encryption/SecurityKeyHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IdentityModel.Tokens; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Security.Encryption 7 | { 8 | public class SecurityKeyHelper 9 | { 10 | public static SecurityKey CreateSecurityKey(string securityKey) 11 | { 12 | return new SymmetricSecurityKey(Encoding.UTF8.GetBytes(securityKey)); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Encryption/SigningCredentialsHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IdentityModel.Tokens; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Security.Encryption 7 | { 8 | public class SigningCredentialsHelper 9 | { 10 | public static SigningCredentials CreateSigningCredentials(SecurityKey securityKey) 11 | { 12 | return new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha512Signature); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Hashing/HashingHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Security.Hashing 6 | { 7 | public 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 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/AccessToken.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Security.JWT 6 | { 7 | public class AccessToken 8 | { 9 | public string Token { get; set; } 10 | public DateTime Expiration { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/ITokenHelper.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Security.JWT 7 | { 8 | public interface ITokenHelper 9 | { 10 | AccessToken CreateToken(User user, List operationClaims); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/JwtHelper.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Core.Extensions; 3 | using Core.Utilities.Security.Encryption; 4 | using Microsoft.Extensions.Configuration; 5 | using Microsoft.IdentityModel.Tokens; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.IdentityModel.Tokens.Jwt; 9 | using System.Linq; 10 | using System.Security.Claims; 11 | using System.Text; 12 | 13 | namespace Core.Utilities.Security.JWT 14 | { 15 | public class JwtHelper : ITokenHelper 16 | { 17 | public IConfiguration _configuration { get; } 18 | TokenOptions _tokenOptions; 19 | DateTime _accesTokenExpiration; 20 | 21 | public JwtHelper(IConfiguration configuration) 22 | { 23 | _configuration = configuration; 24 | _tokenOptions = _configuration.GetSection("TokenOptions").Get(); 25 | _accesTokenExpiration = DateTime.Now.AddMinutes(_tokenOptions.AccessTokenExpiration); 26 | } 27 | 28 | public AccessToken CreateToken(User user, List operationClaims) 29 | { 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 = _accesTokenExpiration 40 | }; 41 | } 42 | 43 | public JwtSecurityToken CreateJwtSecurityToken(TokenOptions tokenOptions, User user, SigningCredentials signingCredentials,List operationClaims) 44 | { 45 | var jwt = new JwtSecurityToken( 46 | issuer: tokenOptions.Issuer, 47 | audience: tokenOptions.Audience, 48 | expires: _accesTokenExpiration, 49 | notBefore: DateTime.Now, 50 | claims: SetClaims(user,operationClaims), 51 | signingCredentials: signingCredentials 52 | ); 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 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/TokenOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Security.JWT 6 | { 7 | public class TokenOptions 8 | { 9 | public string Audience { get; set; } 10 | public string Issuer { get; set; } 11 | public int AccessTokenExpiration { get; set; } 12 | public string SecurityKey { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IBrandDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface IBrandDal :IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICarDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Abstract 9 | { 10 | public interface ICarDal : IEntityRepository 11 | { 12 | List GetCarDetails(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICarImageDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface ICarImageDal : IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IColorDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface IColorDal :IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICustomerDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface ICustomerDal : IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IRentalDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface IRentalDal : IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IUserDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Core.Entities.Concrete; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Abstract 9 | { 10 | public interface IUserDal : IEntityRepository 11 | { 12 | List GetClaims(User user); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/CarDatabaseContext.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Entities.Concrete; 3 | using Microsoft.EntityFrameworkCore; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFramework 9 | { 10 | public class CarDatabaseContext : DbContext 11 | { 12 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 13 | { 14 | optionsBuilder.UseSqlServer(@"Server=(localdb)\MSSQLLocalDB;Database=CarDatabase;Trusted_Connection=true"); 15 | } 16 | 17 | public DbSet Cars { get; set; } 18 | public DbSet Brands { get; set; } 19 | public DbSet Colors { get; set; } 20 | public DbSet Customers { get; set; } 21 | public DbSet Users { get; set; } 22 | public DbSet Rentals { get; set; } 23 | public DbSet CarImages { get; set; } 24 | public DbSet OperationClaims { get; set; } 25 | public DbSet UserOperationClaims { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfBrandDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using Microsoft.EntityFrameworkCore; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Linq.Expressions; 9 | using System.Text; 10 | 11 | namespace DataAccess.Concrete.EntityFramework 12 | { 13 | public class EfBrandDal : EfEntityRepositoryBase, IBrandDal 14 | { 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCarDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using Entities.DTOs; 5 | using Microsoft.EntityFrameworkCore; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Linq.Expressions; 10 | using System.Text; 11 | 12 | namespace DataAccess.Concrete.EntityFramework 13 | { 14 | public class EfCarDal : EfEntityRepositoryBase,ICarDal 15 | { 16 | public List GetCarDetails() 17 | { 18 | using(CarDatabaseContext context = new CarDatabaseContext()) 19 | { 20 | var result = from car in context.Cars 21 | join brand in context.Brands 22 | on car.BrandId equals brand.BrandId 23 | join color in context.Colors 24 | on car.ColorId equals color.ColorId 25 | select new CarDetailsDto 26 | { 27 | CarName = car.Id, 28 | BrandName = brand.BrandName, 29 | ColorName = color.ColorName, 30 | DailyPrice = car.DailyPrice 31 | }; 32 | return result.ToList(); 33 | } 34 | 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCarImageDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFramework 9 | { 10 | public class EfCarImageDal : EfEntityRepositoryBase,ICarImageDal 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfColorDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using Microsoft.EntityFrameworkCore; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Linq.Expressions; 9 | using System.Text; 10 | 11 | namespace DataAccess.Concrete.EntityFramework 12 | { 13 | public class EfColorDal : EfEntityRepositoryBase, IColorDal 14 | { 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCustomerDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFramework 9 | { 10 | public class EfCustomerDal : EfEntityRepositoryBase, ICustomerDal 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfRentalDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFramework 9 | { 10 | public class EfRentalDal : EfEntityRepositoryBase, IRentalDal 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfUserDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using Core.Entities.Concrete; 3 | using DataAccess.Abstract; 4 | using Entities.Concrete; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | using System.Linq; 9 | 10 | namespace DataAccess.Concrete.EntityFramework 11 | { 12 | public class EfUserDal : EfEntityRepositoryBase, IUserDal 13 | { 14 | //Kullanıcının sahip olduğu rolleri çekicez.. 15 | public List GetClaims(User user) 16 | { 17 | using (var context = new CarDatabaseContext()) 18 | { 19 | var result = from operationClaim in context.OperationClaims join userOperationClaim in 20 | context.UserOperationClaims on operationClaim.Id equals userOperationClaim.OperationClaimId 21 | where userOperationClaim.UserId == user.UserId 22 | select new OperationClaim { Id = operationClaim.Id,Name = operationClaim.Name}; 23 | return result.ToList(); 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DataAccess/Concrete/InMemory/InMemoryCarDal.cs: -------------------------------------------------------------------------------- 1 | using DataAccess.Abstract; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Linq.Expressions; 8 | using System.Text; 9 | 10 | namespace DataAccess.Concrete.InMemory 11 | { 12 | public class InMemoryCarDal :ICarDal 13 | { 14 | List _cars; 15 | 16 | public InMemoryCarDal() 17 | { 18 | _cars = new List() 19 | { 20 | new Car{Id = 1, BrandId = 1, ColorId = 1, ModelYear ="2005", DailyPrice = 1000, Description ="Dağ aracı"}, 21 | new Car{Id = 2, BrandId = 2, ColorId = 2, ModelYear ="2015", DailyPrice = 1500, Description ="Konfor severlere özel"}, 22 | new Car{Id = 3, BrandId = 3, ColorId = 3, ModelYear ="2020", DailyPrice = 2000, Description ="En yenilerden"}, 23 | }; 24 | } 25 | 26 | public void Add(Car car) 27 | { 28 | _cars.Add(car); 29 | } 30 | 31 | public void Delete(Car car) 32 | { 33 | Car carToDelete = _cars.SingleOrDefault(c => c.Id == car.Id); 34 | _cars.Remove(carToDelete); 35 | } 36 | 37 | public Car Get(Expression> filter) 38 | { 39 | return null; 40 | } 41 | 42 | public List GetAll(Expression> filter = null) 43 | { 44 | return _cars; 45 | } 46 | 47 | public List GetById(int id) 48 | { 49 | return _cars.Where(c => c.Id == id).ToList(); 50 | } 51 | 52 | public List GetCarDetails() 53 | { 54 | throw new NotImplementedException(); 55 | } 56 | 57 | public void Update(Car car) 58 | { 59 | Car carToUpdate = _cars.SingleOrDefault(c => c.Id == car.Id); 60 | carToUpdate.BrandId = car.BrandId; 61 | carToUpdate.ColorId = car.ColorId; 62 | carToUpdate.ModelYear = car.ModelYear; 63 | carToUpdate.DailyPrice = car.DailyPrice; 64 | carToUpdate.Description = car.Description; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /DataAccess/DataAccess.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Entities/Concrete/Brand.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Brand :IEntity 9 | { 10 | public int BrandId { get; set; } 11 | public string BrandName { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Entities/Concrete/Car.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Car :IEntity 9 | { 10 | public int Id { get; set; } 11 | public int BrandId {get; set; } 12 | public int ColorId { get; set; } 13 | public string ModelYear { get; set; } 14 | public int DailyPrice { get; set; } 15 | public string Description { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Entities/Concrete/CarImage.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class CarImage : IEntity 9 | { 10 | public int Id { get; set; } 11 | public int CarId { get; set; } 12 | public string ImagePath { get; set; } 13 | public DateTime Date { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Entities/Concrete/Color.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Color :IEntity 9 | { 10 | public int ColorId { get; set; } 11 | public string ColorName { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Entities/Concrete/Customer.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Customer:IEntity 9 | { 10 | public int CustomerId { get; set; } 11 | public int UserId { get; set; } 12 | public string CompanyName { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Entities/Concrete/Rental.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Rental : IEntity 9 | { 10 | public int 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 | } 16 | } 17 | -------------------------------------------------------------------------------- /Entities/DTOs/CarDetailsDto.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class CarDetailsDto:IDto 9 | { 10 | public int CarName { get; set; } 11 | public string BrandName { get; set; } 12 | public string ColorName { get; set; } 13 | public int DailyPrice { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Entities/DTOs/UserForLoginDto.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class UserForLoginDto : IDto 9 | { 10 | public string Email { get; set; } 11 | public string Password { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Entities/DTOs/UserForRegisterDto.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class UserForRegisterDto : IDto 9 | { 10 | public string FirstName { get; set; } 11 | public string LastName { get; set; } 12 | public string Email { get; set; } 13 | public string Password { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Entities/Entities.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /ReCapProject.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30907.101 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "Entities\Entities.csproj", "{2C1702F9-6FDB-4C97-837F-C55205407870}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAccess", "DataAccess\DataAccess.csproj", "{202710F6-ED12-4179-9E81-317092765591}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Business", "Business\Business.csproj", "{FBBAB6DD-203C-48B8-A63F-DAA158879A28}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleUI", "ConsoleUI\ConsoleUI.csproj", "{D9E72E35-2940-4EFF-8FF6-2A634C26AD4F}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{4D10724D-6B51-441A-816C-5E28049463B2}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPI", "WebAPI\WebAPI.csproj", "{B47FA518-BEBA-461A-87A4-D1B3664B354E}" 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 | {2C1702F9-6FDB-4C97-837F-C55205407870}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {2C1702F9-6FDB-4C97-837F-C55205407870}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {2C1702F9-6FDB-4C97-837F-C55205407870}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {2C1702F9-6FDB-4C97-837F-C55205407870}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {202710F6-ED12-4179-9E81-317092765591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {202710F6-ED12-4179-9E81-317092765591}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {202710F6-ED12-4179-9E81-317092765591}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {202710F6-ED12-4179-9E81-317092765591}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {FBBAB6DD-203C-48B8-A63F-DAA158879A28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {FBBAB6DD-203C-48B8-A63F-DAA158879A28}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {FBBAB6DD-203C-48B8-A63F-DAA158879A28}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {FBBAB6DD-203C-48B8-A63F-DAA158879A28}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {D9E72E35-2940-4EFF-8FF6-2A634C26AD4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {D9E72E35-2940-4EFF-8FF6-2A634C26AD4F}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {D9E72E35-2940-4EFF-8FF6-2A634C26AD4F}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {D9E72E35-2940-4EFF-8FF6-2A634C26AD4F}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {4D10724D-6B51-441A-816C-5E28049463B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {4D10724D-6B51-441A-816C-5E28049463B2}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {4D10724D-6B51-441A-816C-5E28049463B2}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {4D10724D-6B51-441A-816C-5E28049463B2}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {B47FA518-BEBA-461A-87A4-D1B3664B354E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {B47FA518-BEBA-461A-87A4-D1B3664B354E}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {B47FA518-BEBA-461A-87A4-D1B3664B354E}.Release|Any CPU.ActiveCfg = Release|Any CPU 47 | {B47FA518-BEBA-461A-87A4-D1B3664B354E}.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 = {A5FCCA01-719B-43BF-9E0E-6ABB1A3A2562} 54 | EndGlobalSection 55 | EndGlobal 56 | -------------------------------------------------------------------------------- /WebAPI/Controllers/AuthController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Core.Entities.Concrete; 3 | using Entities.Concrete; 4 | using Entities.DTOs; 5 | using Microsoft.AspNetCore.Http; 6 | using Microsoft.AspNetCore.Mvc; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using System.Threading.Tasks; 11 | 12 | namespace WebAPI.Controllers 13 | { 14 | [Route("api/[controller]")] 15 | [ApiController] 16 | public class AuthController : ControllerBase 17 | { 18 | IAuthService _authService; 19 | 20 | public AuthController(IAuthService authService) 21 | { 22 | _authService = authService; 23 | } 24 | 25 | 26 | [HttpPost("login")] 27 | public IActionResult Login(UserForLoginDto userForLoginDto) 28 | { 29 | var userToLogin = _authService.Login(userForLoginDto); 30 | if(!userToLogin.Success) 31 | { 32 | return BadRequest(userToLogin.Message); 33 | } 34 | var result = _authService.CreateAccessToken(userToLogin.Data); 35 | if (result.Success) 36 | { 37 | return Ok(result); 38 | } 39 | return BadRequest(result.Message); 40 | } 41 | 42 | [HttpPost("register")] 43 | public IActionResult Register(UserForRegisterDto userForRegisterDto) 44 | { 45 | var userExist = _authService.UserExist(userForRegisterDto.Email); 46 | if(!userExist.Success) 47 | { 48 | return BadRequest(userExist.Message); 49 | } 50 | var registerResult = _authService.Register(userForRegisterDto, userForRegisterDto.Password); 51 | var result = _authService.CreateAccessToken(registerResult.Data); 52 | if (result.Success) 53 | { 54 | return Ok(result); 55 | } 56 | return BadRequest(result.Message); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /WebAPI/Controllers/BrandsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class BrandsController : ControllerBase 15 | { 16 | 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 | return BadRequest(result); 32 | } 33 | 34 | [HttpGet("getbyid")] 35 | public IActionResult GetById(int brandId) 36 | { 37 | var result = _brandService.GetById(brandId); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result); 43 | } 44 | 45 | [HttpPost("add")] 46 | public IActionResult Add(Brand brand) 47 | { 48 | var result = _brandService.Add(brand); 49 | 50 | if (result.Success) 51 | { 52 | return Ok(result); 53 | } 54 | return BadRequest(result); 55 | } 56 | 57 | [HttpPost("delete")] 58 | public IActionResult Delete(Brand brand) 59 | { 60 | var result = _brandService.Delete(brand); 61 | 62 | if (result.Success) 63 | { 64 | return Ok(result); 65 | } 66 | return BadRequest(result); 67 | } 68 | 69 | [HttpPost("update")] 70 | public IActionResult Update(Brand brand) 71 | { 72 | var result = _brandService.Update(brand); 73 | 74 | if (result.Success) 75 | { 76 | return Ok(result); 77 | } 78 | return BadRequest(result); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CarImagesController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Business.Abstract; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using Entities.Concrete; 8 | 9 | namespace WebAPI.Controllers 10 | { 11 | [Route("api/[controller]")] 12 | [ApiController] 13 | public class CarImagesController : ControllerBase 14 | { 15 | ICarImageService _carImageService; 16 | 17 | public CarImagesController(ICarImageService carImageService) 18 | { 19 | _carImageService = carImageService; 20 | } 21 | 22 | [HttpGet("getall")] 23 | public IActionResult GetAll() 24 | { 25 | var result = _carImageService.GetAll(); 26 | if (result.Success) 27 | { 28 | return Ok(result); 29 | } 30 | return BadRequest(result); 31 | } 32 | 33 | [HttpGet("getbyid")] 34 | public IActionResult GetById(int imageId) 35 | { 36 | var result = _carImageService.GetById(imageId); 37 | if (result.Success) 38 | { 39 | return Ok(result); 40 | } 41 | return BadRequest(result); 42 | } 43 | 44 | [HttpPost("add")] 45 | public IActionResult Add(CarImage carImage) 46 | { 47 | var result = _carImageService.Add(carImage); 48 | 49 | if (result.Success) 50 | { 51 | return Ok(result); 52 | } 53 | return BadRequest(result); 54 | } 55 | 56 | [HttpPost("delete")] 57 | public IActionResult Delete(CarImage carImage) 58 | { 59 | var result = _carImageService.Delete(carImage); 60 | 61 | if (result.Success) 62 | { 63 | return Ok(result); 64 | } 65 | return BadRequest(result); 66 | } 67 | 68 | [HttpPost("update")] 69 | public IActionResult Update(CarImage carImage) 70 | { 71 | var result = _carImageService.Update(carImage); 72 | 73 | if (result.Success) 74 | { 75 | return Ok(result); 76 | } 77 | return BadRequest(result); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CarsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Authorization; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.AspNetCore.Mvc; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Threading.Tasks; 10 | 11 | namespace WebAPI.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | [ApiController] 15 | public class CarsController : ControllerBase 16 | { 17 | ICarService _carService; 18 | 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 | return BadRequest(result); 33 | } 34 | 35 | [HttpGet("getbyid")] 36 | public IActionResult GetById(int carId) 37 | { 38 | var result = _carService.GetById(carId); 39 | if (result.Success) 40 | { 41 | return Ok(result); 42 | } 43 | return BadRequest(result); 44 | } 45 | 46 | [HttpPost("add")] 47 | public IActionResult Add(Car car) 48 | { 49 | var result = _carService.Add(car); 50 | 51 | if (result.Success) 52 | { 53 | return Ok(result); 54 | } 55 | return BadRequest(result); 56 | } 57 | 58 | [HttpPost("delete")] 59 | public IActionResult Delete(Car car) 60 | { 61 | var result = _carService.Delete(car); 62 | 63 | if (result.Success) 64 | { 65 | return Ok(result); 66 | } 67 | return BadRequest(result); 68 | } 69 | 70 | [HttpPost("update")] 71 | public IActionResult Update(Car car) 72 | { 73 | var result = _carService.Update(car); 74 | 75 | if (result.Success) 76 | { 77 | return Ok(result); 78 | } 79 | return BadRequest(result); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /WebAPI/Controllers/ColorsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class ColorsController : ControllerBase 15 | { 16 | IColorService _colorService; 17 | 18 | public ColorsController(IColorService colorService) 19 | { 20 | _colorService = colorService; 21 | } 22 | 23 | [HttpGet("getall")] 24 | public IActionResult GetAll() 25 | { 26 | var result = _colorService.GetAll(); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result); 32 | } 33 | 34 | [HttpGet("getbyid")] 35 | public IActionResult GetById(int colorId) 36 | { 37 | var result = _colorService.GetById(colorId); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result); 43 | } 44 | 45 | [HttpPost("add")] 46 | public IActionResult Add(Color color) 47 | { 48 | var result = _colorService.Add(color); 49 | 50 | if (result.Success) 51 | { 52 | return Ok(result); 53 | } 54 | return BadRequest(result); 55 | } 56 | 57 | [HttpPost("delete")] 58 | public IActionResult Delete(Color color) 59 | { 60 | var result = _colorService.Delete(color); 61 | 62 | if (result.Success) 63 | { 64 | return Ok(result); 65 | } 66 | return BadRequest(result); 67 | } 68 | 69 | [HttpPost("update")] 70 | public IActionResult Update(Color color) 71 | { 72 | var result = _colorService.Update(color); 73 | 74 | if (result.Success) 75 | { 76 | return Ok(result); 77 | } 78 | return BadRequest(result); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CustomersController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class CustomersController : ControllerBase 15 | { 16 | ICustomerService _customerService; 17 | 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 | return BadRequest(result); 32 | } 33 | 34 | [HttpGet("getbyid")] 35 | public IActionResult GetById(int customerId) 36 | { 37 | var result = _customerService.GetById(customerId); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result); 43 | } 44 | 45 | [HttpPost("add")] 46 | public IActionResult Add(Customer customer) 47 | { 48 | var result = _customerService.Add(customer); 49 | 50 | if (result.Success) 51 | { 52 | return Ok(result); 53 | } 54 | return BadRequest(result); 55 | } 56 | 57 | [HttpPost("delete")] 58 | public IActionResult Delete(Customer customer) 59 | { 60 | var result = _customerService.Delete(customer); 61 | 62 | if (result.Success) 63 | { 64 | return Ok(result); 65 | } 66 | return BadRequest(result); 67 | } 68 | 69 | [HttpPost("update")] 70 | public IActionResult Update(Customer customer) 71 | { 72 | var result = _customerService.Update(customer); 73 | 74 | if (result.Success) 75 | { 76 | return Ok(result); 77 | } 78 | return BadRequest(result); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /WebAPI/Controllers/RentalsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class RentalsController : ControllerBase 15 | { 16 | IRentalService _rentalService; 17 | 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 | return BadRequest(result); 32 | } 33 | 34 | [HttpGet("getbyid")] 35 | public IActionResult GetById(int rentalId) 36 | { 37 | var result = _rentalService.GetById(rentalId); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result); 43 | } 44 | 45 | [HttpPost("add")] 46 | public IActionResult Add(Rental rental) 47 | { 48 | var result = _rentalService.Add(rental); 49 | 50 | if (result.Success) 51 | { 52 | return Ok(result); 53 | } 54 | return BadRequest(result); 55 | } 56 | 57 | [HttpPost("delete")] 58 | public IActionResult Delete(Rental rental) 59 | { 60 | var result = _rentalService.Delete(rental); 61 | 62 | if (result.Success) 63 | { 64 | return Ok(result); 65 | } 66 | return BadRequest(result); 67 | } 68 | 69 | [HttpPost("update")] 70 | public IActionResult Update(Rental rental) 71 | { 72 | var result = _rentalService.Update(rental); 73 | 74 | if (result.Success) 75 | { 76 | return Ok(result); 77 | } 78 | return BadRequest(result); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /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 Autofac; 2 | using Autofac.Extensions.DependencyInjection; 3 | using Business.DependencyResolver.Autofac; 4 | using Microsoft.AspNetCore.Hosting; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.Extensions.Hosting; 7 | using Microsoft.Extensions.Logging; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | using System.Threading.Tasks; 12 | 13 | namespace WebAPI 14 | { 15 | public class Program 16 | { 17 | public static void Main(string[] args) 18 | { 19 | CreateHostBuilder(args).Build().Run(); 20 | } 21 | 22 | public static IHostBuilder CreateHostBuilder(string[] args) => 23 | Host.CreateDefaultBuilder(args) 24 | .UseServiceProviderFactory(new AutofacServiceProviderFactory()) 25 | .ConfigureContainer(builder => 26 | { 27 | builder.RegisterModule(new AutofacBusinessModule()); 28 | }) 29 | .ConfigureWebHostDefaults(webBuilder => 30 | { 31 | webBuilder.UseStartup(); 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /WebAPI/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:50074", 8 | "sslPort": 44322 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "weatherforecast", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "WebAPI": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "weatherforecast", 24 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /WebAPI/Startup.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Concrete; 3 | using DataAccess.Abstract; 4 | using DataAccess.Concrete.EntityFramework; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Authentication.JwtBearer; 8 | using Microsoft.AspNetCore.HttpsPolicy; 9 | using Microsoft.AspNetCore.Mvc; 10 | using Microsoft.Extensions.Configuration; 11 | using Microsoft.Extensions.DependencyInjection; 12 | using Microsoft.Extensions.Hosting; 13 | using Microsoft.Extensions.Logging; 14 | using System; 15 | using System.Collections.Generic; 16 | using System.Linq; 17 | using System.Threading.Tasks; 18 | using Microsoft.IdentityModel.Tokens; 19 | using Core.Utilities.Security.JWT; 20 | using Core.Utilities.Security.Encryption; 21 | using Microsoft.AspNetCore.Http; 22 | using Core.Extensions; 23 | using Core.Utilities.IoC; 24 | using Core.DependencyResolver; 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 | 42 | services.AddCors(); 43 | 44 | services.AddSingleton(); 45 | 46 | var tokenOptions = Configuration.GetSection("TokenOptions").Get(); 47 | 48 | services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => 49 | { 50 | options.TokenValidationParameters = new TokenValidationParameters 51 | { 52 | ValidateIssuer = true, 53 | ValidateAudience = true, 54 | ValidateLifetime = true, 55 | ValidIssuer = tokenOptions.Issuer, 56 | ValidAudience = tokenOptions.Audience, 57 | ValidateIssuerSigningKey = true, 58 | IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) 59 | }; 60 | }); 61 | 62 | services.AddDependencyResolvers(new ICoreModule[]{ 63 | new CoreModule() 64 | }); 65 | } 66 | 67 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 68 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 69 | { 70 | if (env.IsDevelopment()) 71 | { 72 | app.UseDeveloperExceptionPage(); 73 | } 74 | app.UseCors(ApplicationBuilder => ApplicationBuilder.WithOrigins("http://localhost:4200").AllowAnyHeader()); 75 | 76 | app.UseHttpsRedirection(); 77 | 78 | app.UseRouting(); 79 | 80 | app.UseAuthentication(); 81 | 82 | app.UseAuthorization(); 83 | 84 | app.UseEndpoints(endpoints => 85 | { 86 | endpoints.MapControllers(); 87 | }); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /WebAPI/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebAPI 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WebAPI/WebAPI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /WebAPI/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /WebAPI/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "TokenOptions": { 3 | "Audience": "www.ebru.com", 4 | "Issuer": "www.ebru.com", 5 | "AccessTokenExpiration": 10, 6 | "SecurityKey": "mysecuritykeymysecuritykey" 7 | }, 8 | "Logging": { 9 | "LogLevel": { 10 | "Default": "Information", 11 | "Microsoft": "Warning", 12 | "Microsoft.Hosting.Lifetime": "Information" 13 | } 14 | }, 15 | "AllowedHosts": "*" 16 | } 17 | --------------------------------------------------------------------------------