├── .gitignore ├── .vs ├── ReCapDemo │ └── DesignTimeBuild │ │ └── .dtbcache.v2 └── ReCapProject │ └── DesignTimeBuild │ └── .dtbcache.v2 ├── Business ├── Abstract │ ├── IAuthService.cs │ ├── IBrandService.cs │ ├── ICarImageService.cs │ ├── ICarService.cs │ ├── IColorService.cs │ ├── ICreditCardService.cs │ ├── ICustomerService.cs │ ├── IRentalService.cs │ └── IUserService.cs ├── Business.csproj ├── BusinessAspect │ └── Autofac │ │ └── SecuredOperation.cs ├── Concrete │ ├── AuthManager.cs │ ├── BrandManager.cs │ ├── CarImageManager.cs │ ├── CarManager.cs │ ├── ColorManager.cs │ ├── CreditCardManager.cs │ ├── CustomerManager.cs │ ├── RentalManager.cs │ └── UserManager.cs ├── Constants │ └── Messages.cs ├── DependencyResolvers │ └── Autofac │ │ └── AutofacBusinessModule.cs └── ValidationRules │ └── FluentValidation │ ├── BrandValidator.cs │ ├── CarImageValidator.cs │ ├── CarValidator.cs │ ├── ColorValidator.cs │ ├── CustomerValidator.cs │ ├── RentalValidator.cs │ └── UserValidator.cs ├── ConsoleUI ├── ConsoleUI.csproj └── Program.cs ├── Core ├── Aspects │ └── Autofac │ │ ├── Caching │ │ ├── CacheAspect.cs │ │ └── CacheRemoveAspect.cs │ │ ├── Exception │ │ └── ExceptionLogAspect.cs │ │ ├── Logging │ │ └── LogAspect.cs │ │ ├── Performance │ │ └── PerformanceAspect.cs │ │ ├── Transaction │ │ └── TransactionScopeAspect.cs │ │ └── Validation │ │ └── ValidationAspect.cs ├── Core.csproj ├── CrossCuttingConcerns │ ├── Caching │ │ ├── ICacheManager.cs │ │ └── Microsoft │ │ │ └── MemoryCacheManager.cs │ ├── Logging │ │ ├── Log4Net │ │ │ ├── Layouts │ │ │ │ └── JsonLayout.cs │ │ │ ├── LoggerServiceBase.cs │ │ │ ├── Loggers │ │ │ │ └── FileLogger.cs │ │ │ └── SerializableLogEvent.cs │ │ ├── LogDetail.cs │ │ ├── LogDetailWithException.cs │ │ └── LogParameter.cs │ └── Validation │ │ └── ValidationTool.cs ├── DataAccess │ ├── EntityFramework │ │ └── EfEntityRepositoryBase.cs │ └── IEntityRepository.cs ├── DependencyResolvers │ └── CoreModule.cs ├── Entities │ ├── Concrete │ │ ├── OperationClaim.cs │ │ ├── User.cs │ │ └── UserOperationClaim.cs │ ├── IDto.cs │ └── IEntity.cs ├── Extensions │ ├── ClaimExtensions.cs │ ├── ClaimsPrincipalExtensions.cs │ ├── ErrorDetails.cs │ ├── ExceptionMiddleware.cs │ ├── ExceptionMiddlewareExtensions.cs │ └── ServiceCollectionExtensions.cs └── Utilities │ ├── Business │ └── BusinessRules.cs │ ├── Helpers │ └── FileHelper.cs │ ├── Interceptors │ ├── AspectInterceptorSelector.cs │ ├── MethodInterception.cs │ └── MethodInterceptionBaseAttribute.cs │ ├── IoC │ ├── ICoreModule.cs │ └── ServiceTool.cs │ ├── Messages │ └── AspectMessages.cs │ ├── Results │ ├── DataResult.cs │ ├── ErrorDataResult.cs │ ├── ErrorResult.cs │ ├── IDataResult.cs │ ├── IResult.cs │ ├── Result.cs │ ├── SuccessDataResult.cs │ └── SuccessResult.cs │ └── Security │ ├── Encryption │ ├── SecurityKeyHelper.cs │ └── SigningCredentialsHelper.cs │ ├── Hashing │ └── HashingHelper.cs │ └── JWT │ ├── AccessToken.cs │ ├── ITokenHelper.cs │ ├── JwtHelper.cs │ └── TokenOptions.cs ├── DataAccess ├── Abstract │ ├── IBrandDal.cs │ ├── ICarDal.cs │ ├── ICarImageDal.cs │ ├── IColorDal.cs │ ├── ICreditCardDal.cs │ ├── ICustomerDal.cs │ ├── IRentalDal.cs │ └── IUserDal.cs ├── Concrete │ ├── EntityFramework │ │ ├── Context │ │ │ └── RentACarContext.cs │ │ └── Repository │ │ │ ├── EfBrandDal.cs │ │ │ ├── EfCarDal.cs │ │ │ ├── EfCarImageDal.cs │ │ │ ├── EfColorDal.cs │ │ │ ├── EfCreditCardDal.cs │ │ │ ├── EfCustomerDal.cs │ │ │ ├── EfRentalDal.cs │ │ │ └── EfUserDal.cs │ └── InMemory │ │ ├── InMemoryBrandDal.cs │ │ ├── InMemoryCarDal.cs │ │ └── InMemoryColorDal.cs └── DataAccess.csproj ├── Entities ├── Concrete │ ├── Brand.cs │ ├── Car.cs │ ├── CarImage.cs │ ├── Color.cs │ ├── CreditCard.cs │ ├── Customer.cs │ └── Rental.cs ├── DTOs │ ├── CarDetailDto.cs │ ├── RentalDetailDto.cs │ ├── UserForLoginDto.cs │ └── UserForRegisterDto.cs └── Entities.csproj ├── LICENSE.txt ├── README.md ├── ReCapProject.sln ├── RentACarSQLQuery.sql └── WebAPI ├── Controllers ├── AuthController.cs ├── BrandsController.cs ├── CarImagesController.cs ├── CarsController.cs ├── ColorsController.cs ├── CreditCardsController.cs ├── CustomersController.cs ├── RentalsController.cs └── UsersController.cs ├── Program.cs ├── Properties └── launchSettings.json ├── Startup.cs ├── WebAPI.csproj ├── appsettings.Development.json ├── appsettings.json ├── log4net.config └── wwwroot └── Images ├── bmw-beyaz.jpg ├── default.jpg ├── reno-mavi.jpg ├── tesla-beyaz.jpg └── tesla-mavi.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | *.vs 9 | 10 | # Build results 11 | 12 | [Dd]ebug/ 13 | [Rr]elease/ 14 | x64/ 15 | [Bb]in/ 16 | [Oo]bj/ 17 | 18 | # MSTest test Results 19 | [Tt]est[Rr]esult*/ 20 | [Bb]uild[Ll]og.* 21 | 22 | *_i.c 23 | *_p.c 24 | *_i.h 25 | *.ilk 26 | *.meta 27 | *.obj 28 | *.pch 29 | *.pdb 30 | *.pgc 31 | *.pgd 32 | *.rsp 33 | *.sbr 34 | *.tlb 35 | *.tli 36 | *.tlh 37 | *.tmp 38 | *.tmp_proj 39 | *.log 40 | *.vspscc 41 | *.vssscc 42 | .builds 43 | *.pidb 44 | *.log 45 | *.svclog 46 | *.scc 47 | 48 | # Visual C++ cache files 49 | ipch/ 50 | *.aps 51 | *.ncb 52 | *.opensdf 53 | *.sdf 54 | *.cachefile 55 | 56 | # Visual Studio profiler 57 | *.psess 58 | *.vsp 59 | *.vspx 60 | 61 | # Guidance Automation Toolkit 62 | *.gpState 63 | 64 | # ReSharper is a .NET coding add-in 65 | _ReSharper*/ 66 | *.[Rr]e[Ss]harper 67 | *.DotSettings.user 68 | 69 | # Click-Once directory 70 | publish/ 71 | 72 | # Publish Web Output 73 | *.Publish.xml 74 | *.pubxml 75 | *.azurePubxml 76 | 77 | # NuGet Packages Directory 78 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 79 | packages/ 80 | ## TODO: If the tool you use requires repositories.config, also uncomment the next line 81 | !packages/repositories.config 82 | 83 | # Windows Azure Build Output 84 | csx/ 85 | *.build.csdef 86 | 87 | # Windows Store app package directory 88 | AppPackages/ 89 | 90 | # Others 91 | sql/ 92 | *.Cache 93 | ClientBin/ 94 | [Ss]tyle[Cc]op.* 95 | ![Ss]tyle[Cc]op.targets 96 | ~$* 97 | *~ 98 | *.dbmdl 99 | *.[Pp]ublish.xml 100 | 101 | *.publishsettings 102 | 103 | # RIA/Silverlight projects 104 | Generated_Code/ 105 | 106 | # Backup & report files from converting an old project file to a newer 107 | # Visual Studio version. Backup files are not needed, because we have git ;-) 108 | _UpgradeReport_Files/ 109 | Backup*/ 110 | UpgradeLog*.XML 111 | UpgradeLog*.htm 112 | 113 | # SQL Server files 114 | App_Data/*.mdf 115 | App_Data/*.ldf 116 | 117 | # ========================= 118 | # Windows detritus 119 | # ========================= 120 | 121 | # Windows image file caches 122 | Thumbs.db 123 | ehthumbs.db 124 | 125 | # Folder config file 126 | Desktop.ini 127 | 128 | # Recycle Bin used on file shares 129 | $RECYCLE.BIN/ 130 | 131 | # Mac desktop service store files 132 | .DS_Store 133 | 134 | _NCrunch* 135 | -------------------------------------------------------------------------------- /.vs/ReCapDemo/DesignTimeBuild/.dtbcache.v2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gulceselim/re-cap-project-with-csharp/5e1ebedc22869513a00e29a4a85d83786239b94b/.vs/ReCapDemo/DesignTimeBuild/.dtbcache.v2 -------------------------------------------------------------------------------- /.vs/ReCapProject/DesignTimeBuild/.dtbcache.v2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gulceselim/re-cap-project-with-csharp/5e1ebedc22869513a00e29a4a85d83786239b94b/.vs/ReCapProject/DesignTimeBuild/.dtbcache.v2 -------------------------------------------------------------------------------- /Business/Abstract/IAuthService.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Core.Utilities.Results; 3 | using Core.Utilities.Security.JWT; 4 | using Entities.DTOs; 5 | 6 | namespace Business.Abstract 7 | { 8 | public interface IAuthService 9 | { 10 | IDataResult Register(UserForRegisterDto userForRegisterDto, string password); 11 | IDataResult Login(UserForLoginDto userForLoginDto); 12 | IResult UserExists(string email); 13 | IDataResult CreateAccessToken(User user); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Business/Abstract/IBrandService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface IBrandService 10 | { 11 | IResult Add(Brand brand); 12 | IResult Update(Brand brand); 13 | IResult Delete(Brand brand); 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int id); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Business/Abstract/ICarImageService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using Microsoft.AspNetCore.Http; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq.Expressions; 8 | using System.Text; 9 | 10 | namespace Business.Abstract 11 | { 12 | public interface ICarImageService 13 | { 14 | IResult Add(IFormFile file, CarImage carImage); 15 | IResult Update(IFormFile file, CarImage carImage); 16 | IResult Delete(CarImage carImage); 17 | IDataResult> GetAll(Expression> filter = null); 18 | IDataResult GetById(int id); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Business/Abstract/ICarService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq.Expressions; 7 | using System.Text; 8 | 9 | namespace Business.Abstract 10 | { 11 | public interface ICarService 12 | { 13 | IResult Add(Car car); 14 | IResult Update(Car car); 15 | IResult Delete(Car car); 16 | IDataResult> GetAll(); 17 | IDataResult GetById(int id); 18 | IDataResult> GetCarDetails(Expression> filter = null); 19 | 20 | IResult TransactionalOperation(Car car); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /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 id); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Business/Abstract/ICreditCardService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface ICreditCardService 10 | { 11 | IResult Add(CreditCard creditCard); 12 | IResult Update(CreditCard creditCard); 13 | IResult Delete(CreditCard creditCard); 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int id); 16 | IDataResult> GetByUserId(int userId); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Business/Abstract/ICustomerService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface ICustomerService 10 | { 11 | IResult Add(Customer customer); 12 | IResult Delete(Customer customer); 13 | IResult Update(Customer customer); 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int id); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Business/Abstract/IRentalService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq.Expressions; 7 | using System.Text; 8 | 9 | namespace Business.Abstract 10 | { 11 | public interface IRentalService 12 | { 13 | IResult Add(Rental rental); 14 | IResult Delete(Rental rental); 15 | IResult Update(Rental rental); 16 | IDataResult> GetAll(); 17 | IDataResult GetById(int id); 18 | 19 | IDataResult> GetRentalDetails(Expression> filter = null); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Business/Abstract/IUserService.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Core.Utilities.Results; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface IUserService 10 | { 11 | IResult Add(User user); 12 | IResult Delete(User user); 13 | IResult Update(User user); 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int id); 16 | List GetClaims(User user); 17 | IDataResult GetByMail(string email); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Business/Business.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Business/BusinessAspect/Autofac/SecuredOperation.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.Utilities.Interceptors; 3 | using Core.Utilities.IoC; 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.Extensions; 10 | using Business.Constants; 11 | 12 | namespace Business.BusinessAspect.Autofac 13 | { 14 | //JWT için 15 | public class SecuredOperation : MethodInterception 16 | { 17 | private string[] _roles; 18 | private IHttpContextAccessor _httpContextAccessor; // Her istek yapan kullanıcı için HttpContext ekler. 19 | 20 | public SecuredOperation(string roles) 21 | { 22 | _roles = roles.Split(','); 23 | _httpContextAccessor = ServiceTool.ServiceProvider.GetService(); 24 | 25 | } 26 | 27 | protected override void OnBefore(IInvocation invocation) 28 | { 29 | var roleClaims = _httpContextAccessor.HttpContext.User.ClaimRoles(); 30 | foreach (var role in _roles) 31 | { 32 | if (roleClaims.Contains(role)) 33 | { 34 | return; 35 | } 36 | } 37 | throw new Exception(Messages.AuthorizationDenied); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /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 | 9 | namespace Business.Concrete 10 | { 11 | public class AuthManager : IAuthService 12 | { 13 | private IUserService _userService; 14 | private ITokenHelper _tokenHelper; 15 | 16 | public AuthManager(IUserService userService, ITokenHelper tokenHelper) 17 | { 18 | _userService = userService; 19 | _tokenHelper = tokenHelper; 20 | } 21 | 22 | public IDataResult Register(UserForRegisterDto userForRegisterDto, string password) 23 | { 24 | byte[] passwordHash, passwordSalt; 25 | HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt); 26 | var user = new User 27 | { 28 | Email = userForRegisterDto.Email, 29 | FirstName = userForRegisterDto.FirstName, 30 | LastName = userForRegisterDto.LastName, 31 | PasswordHash = passwordHash, 32 | PasswordSalt = passwordSalt, 33 | Status = true 34 | }; 35 | _userService.Add(user); 36 | return new SuccessDataResult(user, Messages.UserRegistered); 37 | } 38 | 39 | public IDataResult Login(UserForLoginDto userForLoginDto) 40 | { 41 | var userToCheck = _userService.GetByMail(userForLoginDto.Email).Data; 42 | if (userToCheck == null) 43 | { 44 | return new ErrorDataResult(Messages.UserNotFound); 45 | } 46 | 47 | if (!HashingHelper.VerifyPasswordHash(userForLoginDto.Password, userToCheck.PasswordHash, userToCheck.PasswordSalt)) 48 | { 49 | return new ErrorDataResult(Messages.PasswordError); 50 | } 51 | 52 | return new SuccessDataResult(userToCheck, Messages.SuccessfulLogin); 53 | } 54 | 55 | public IResult UserExists(string email) 56 | { 57 | if (_userService.GetByMail(email).Data != null) 58 | { 59 | return new ErrorResult(Messages.UserAlreadyExists); 60 | } 61 | return new SuccessResult(); 62 | } 63 | 64 | public IDataResult CreateAccessToken(User user) 65 | { 66 | var claims = _userService.GetClaims(user); 67 | var accessToken = _tokenHelper.CreateToken(user, claims); 68 | return new SuccessDataResult(accessToken, Messages.AccessTokenCreated); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Business/Concrete/BrandManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.BusinessAspect.Autofac; 3 | using Business.Constants; 4 | using Business.ValidationRules.FluentValidation; 5 | using Core.Aspects.Autofac.Validation; 6 | using Core.CrossCuttingConcerns.Validation; 7 | using Core.Utilities.Results; 8 | using DataAccess.Abstract; 9 | using Entities.Concrete; 10 | using FluentValidation; 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Text; 14 | 15 | namespace Business.Concrete 16 | { 17 | public class BrandManager : IBrandService 18 | { 19 | IBrandDal _brandDal; 20 | 21 | public BrandManager(IBrandDal brandDal) 22 | { 23 | _brandDal = brandDal; 24 | } 25 | 26 | [SecuredOperation("admin")] 27 | [ValidationAspect(typeof(BrandValidator))] 28 | public IResult Add(Brand brand) 29 | { 30 | _brandDal.Add(brand); 31 | return new SuccessResult(Messages.AddedBrand); 32 | } 33 | [SecuredOperation("admin")] 34 | public IResult Delete(Brand brand) 35 | { 36 | _brandDal.Delete(brand); 37 | return new SuccessResult(Messages.DeletedBrand); 38 | } 39 | 40 | public IDataResult> GetAll() 41 | { 42 | return new SuccessDataResult>(_brandDal.GetAll()); 43 | } 44 | 45 | public IDataResult GetById(int id) 46 | { 47 | return new SuccessDataResult(_brandDal.Get(c => c.Id == id)); 48 | } 49 | 50 | [SecuredOperation("admin")] 51 | [ValidationAspect(typeof(BrandValidator))] 52 | public IResult Update(Brand brand) 53 | { 54 | 55 | _brandDal.Update(brand); 56 | return new SuccessResult(Messages.UpdatedBrand); 57 | 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /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.Business; 6 | using Core.Utilities.Helpers; 7 | using Core.Utilities.Results; 8 | using DataAccess.Abstract; 9 | using Entities.Concrete; 10 | using Entities.DTOs; 11 | using Microsoft.AspNetCore.Http; 12 | using System; 13 | using System.Collections.Generic; 14 | using System.IO; 15 | using System.Linq; 16 | using System.Linq.Expressions; 17 | using System.Text; 18 | 19 | namespace Business.Concrete 20 | { 21 | public class CarImageManager : ICarImageService 22 | { 23 | ICarImageDal _carImageDal; 24 | 25 | public CarImageManager(ICarImageDal carImageDal) 26 | { 27 | _carImageDal = carImageDal; 28 | } 29 | 30 | public IResult Add(IFormFile file, CarImage carImage) 31 | { 32 | var result = BusinessRules.Run(CheckCarImageLimit(carImage)); 33 | 34 | if(result != null) 35 | { 36 | return result; 37 | } 38 | 39 | carImage.ImagePath = FileHelper.AddAsync(file); 40 | carImage.CarImageDate = DateTime.Now; 41 | _carImageDal.Add(carImage); 42 | 43 | return new SuccessResult(Messages.AddedCarImage); 44 | } 45 | 46 | public IResult Delete(CarImage carImage) 47 | { 48 | var oldpath = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..\\..\\..\\wwwroot")) + _carImageDal.Get(I => I.Id == carImage.Id).ImagePath; 49 | 50 | var result = BusinessRules.Run(FileHelper.DeleteAsync(oldpath)); 51 | 52 | if(result != null) 53 | { 54 | return result; 55 | } 56 | 57 | _carImageDal.Delete(carImage); 58 | return new SuccessResult(Messages.DeletedCarImage); 59 | 60 | 61 | } 62 | 63 | public IDataResult> GetAll(Expression> filter = null) 64 | { 65 | return new SuccessDataResult>(_carImageDal.GetAll(filter)); 66 | } 67 | 68 | public IDataResult GetById(int id) 69 | { 70 | return new SuccessDataResult(_carImageDal.Get(I => I.Id == id)); 71 | } 72 | 73 | public IResult Update(IFormFile file, CarImage carImage) 74 | { 75 | var oldpath = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..\\..\\..\\wwwroot")) + _carImageDal.Get(p => p.Id == carImage.Id).ImagePath; 76 | carImage.ImagePath = FileHelper.UpdateAsync(oldpath, file); 77 | carImage.CarImageDate = DateTime.Now; 78 | _carImageDal.Update(carImage); 79 | return new SuccessResult(); 80 | 81 | } 82 | 83 | private IResult CheckCarImageLimit(CarImage carImage) 84 | { 85 | if (_carImageDal.GetAll(c => c.CarId == carImage.CarId).Count >= 5) 86 | { 87 | return new ErrorResult(Messages.FailedCarImageAdd); 88 | } 89 | 90 | return new SuccessResult(); 91 | } 92 | 93 | 94 | 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Business/Concrete/CarManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.BusinessAspect.Autofac; 3 | using Business.Constants; 4 | using Business.ValidationRules.FluentValidation; 5 | using Core.Aspects.Autofac.Caching; 6 | using Core.Aspects.Autofac.Logging; 7 | using Core.Aspects.Autofac.Performance; 8 | using Core.Aspects.Autofac.Transaction; 9 | using Core.Aspects.Autofac.Validation; 10 | using Core.CrossCuttingConcerns.Logging.Log4Net.Loggers; 11 | using Core.Utilities.Results; 12 | using DataAccess.Abstract; 13 | using Entities.Concrete; 14 | using Entities.DTOs; 15 | using System; 16 | using System.Collections.Generic; 17 | using System.Linq.Expressions; 18 | using System.Text; 19 | using System.Threading; 20 | 21 | namespace Business.Concrete 22 | { 23 | public class CarManager : ICarService 24 | { 25 | ICarDal _carDal; 26 | 27 | public CarManager(ICarDal carDal) 28 | { 29 | _carDal = carDal; 30 | } 31 | 32 | [SecuredOperation("car.add")] 33 | [ValidationAspect(typeof(CarValidator))] 34 | [CacheRemoveAspect("ICarService.Get")] 35 | public IResult Add(Car car) 36 | { 37 | _carDal.Add(car); 38 | return new SuccessResult(Messages.AddedCar); 39 | 40 | } 41 | 42 | public IResult Delete(Car car) 43 | { 44 | 45 | _carDal.Delete(car); 46 | return new SuccessResult(Messages.DeletedCar); 47 | 48 | } 49 | 50 | [CacheAspect(duration: 10)] 51 | [PerformanceAspect(1)] 52 | public IDataResult> GetAll() 53 | { 54 | return new SuccessDataResult>(_carDal.GetAll()); 55 | } 56 | 57 | public IDataResult GetById(int id) 58 | { 59 | return new SuccessDataResult(_carDal.Get(c => c.Id == id)); 60 | } 61 | 62 | public IDataResult> GetCarDetails(Expression> filter = null) 63 | { 64 | return new SuccessDataResult>(_carDal.GetCarDetails(filter)); 65 | 66 | } 67 | 68 | [ValidationAspect(typeof(CarValidator))] 69 | public IResult Update(Car car) 70 | { 71 | _carDal.Update(car); 72 | return new SuccessResult(Messages.UpdatedCar); 73 | } 74 | 75 | [TransactionScopeAspect] 76 | public IResult TransactionalOperation(Car car) 77 | { 78 | _carDal.Update(car); 79 | _carDal.Add(car); 80 | return new SuccessResult(Messages.UpdatedCar); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Business/Concrete/ColorManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.BusinessAspect.Autofac; 3 | using Business.Constants; 4 | using Business.ValidationRules.FluentValidation; 5 | using Core.Aspects.Autofac.Validation; 6 | using Core.Utilities.Results; 7 | using DataAccess.Abstract; 8 | using Entities.Concrete; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Text; 12 | 13 | namespace Business.Concrete 14 | { 15 | public class ColorManager : IColorService 16 | { 17 | IColorDal _colorDal; 18 | 19 | public ColorManager(IColorDal brandDal) 20 | { 21 | _colorDal = brandDal; 22 | } 23 | 24 | [SecuredOperation("admin")] 25 | [ValidationAspect(typeof(ColorValidator))] 26 | public IResult Add(Color entity) 27 | { 28 | _colorDal.Add(entity); 29 | return new SuccessResult(Messages.AddedColor); 30 | } 31 | 32 | [SecuredOperation("admin")] 33 | public IResult Delete(Color color) 34 | { 35 | _colorDal.Delete(color); 36 | return new SuccessResult(Messages.DeletedColor); 37 | 38 | } 39 | 40 | public IDataResult> GetAll() 41 | { 42 | return new SuccessDataResult>(_colorDal.GetAll()); 43 | 44 | } 45 | 46 | public IDataResult GetById(int id) 47 | { 48 | return new SuccessDataResult(_colorDal.Get(c => c.Id == id)); 49 | } 50 | 51 | [SecuredOperation("admin")] 52 | [ValidationAspect(typeof(ColorValidator))] 53 | public IResult Update(Color entity) 54 | { 55 | _colorDal.Update(entity); 56 | return new SuccessResult(Messages.UpdatedColor); 57 | 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Business/Concrete/CreditCardManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.BusinessAspect.Autofac; 3 | using Business.Constants; 4 | using Core.Utilities.Results; 5 | using DataAccess.Abstract; 6 | using Entities.Concrete; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | 11 | namespace Business.Concrete 12 | { 13 | public class CreditCardManager : ICreditCardService 14 | { 15 | 16 | ICreditCardDal creditCardDal; 17 | 18 | public CreditCardManager(ICreditCardDal creditCardDal) 19 | { 20 | this.creditCardDal = creditCardDal; 21 | } 22 | 23 | public IResult Add(CreditCard creditCard) 24 | { 25 | creditCardDal.Add(creditCard); 26 | return new SuccessResult(Messages.AddedCreditCard); 27 | } 28 | 29 | public IResult Delete(CreditCard creditCard) 30 | { 31 | creditCardDal.Delete(creditCard); 32 | return new SuccessResult(Messages.DeletedCreditCard); 33 | } 34 | 35 | public IDataResult> GetAll() 36 | { 37 | return new SuccessDataResult>(creditCardDal.GetAll()); 38 | } 39 | 40 | public IDataResult GetById(int id) 41 | { 42 | return new SuccessDataResult(creditCardDal.Get(c => c.Id == id)); 43 | } 44 | 45 | public IDataResult> GetByUserId(int userId) 46 | { 47 | return new SuccessDataResult>(creditCardDal.GetAll(c => c.UserId == userId)); 48 | } 49 | 50 | public IResult Update(CreditCard creditCard) 51 | { 52 | 53 | creditCardDal.Update(creditCard); 54 | return new SuccessResult(Messages.UpdatedCreditCard); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Business/Concrete/CustomerManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.BusinessAspect.Autofac; 3 | using Business.Constants; 4 | using Business.ValidationRules.FluentValidation; 5 | using Core.Aspects.Autofac.Validation; 6 | using Core.Utilities.Results; 7 | using DataAccess.Abstract; 8 | using Entities.Concrete; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Text; 12 | 13 | namespace Business.Concrete 14 | { 15 | public class CustomerManager : ICustomerService 16 | { 17 | ICustomerDal _customerDal; 18 | 19 | public CustomerManager(ICustomerDal customerDal) 20 | { 21 | _customerDal = customerDal; 22 | } 23 | 24 | [ValidationAspect(typeof(CustomerValidator))] 25 | [SecuredOperation("admin")] 26 | public IResult Add(Customer customer) 27 | { 28 | _customerDal.Add(customer); 29 | return new SuccessResult(Messages.AddedCustomer); 30 | } 31 | 32 | [SecuredOperation("admin")] 33 | public IResult Delete(Customer customer) 34 | { 35 | _customerDal.Delete(customer); 36 | return new SuccessResult(Messages.DeletedCustomer); 37 | } 38 | 39 | public IDataResult> GetAll() 40 | { 41 | return new SuccessDataResult>(_customerDal.GetAll()); 42 | } 43 | 44 | public IDataResult GetById(int id) 45 | { 46 | return new SuccessDataResult(_customerDal.Get(c => c.Id == id)); 47 | } 48 | 49 | [SecuredOperation("admin")] 50 | [ValidationAspect(typeof(CustomerValidator))] 51 | public IResult Update(Customer customer) 52 | { 53 | _customerDal.Update(customer); 54 | return new SuccessResult(Messages.UpdatedCustomer); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Business/Concrete/RentalManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.BusinessAspect.Autofac; 3 | using Business.Constants; 4 | using Business.ValidationRules.FluentValidation; 5 | using Core.Aspects.Autofac.Validation; 6 | using Core.Utilities.Business; 7 | using Core.Utilities.Results; 8 | using DataAccess.Abstract; 9 | using Entities.Concrete; 10 | using Entities.DTOs; 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Linq.Expressions; 14 | using System.Text; 15 | 16 | namespace Business.Concrete 17 | { 18 | public class RentalManager : IRentalService 19 | { 20 | IRentalDal _rentalDal; 21 | 22 | public RentalManager(IRentalDal rentalDal) 23 | { 24 | _rentalDal = rentalDal; 25 | } 26 | 27 | [ValidationAspect(typeof(RentalValidator))] 28 | public IResult Add(Rental rental) 29 | { 30 | IResult result = BusinessRules.Run(CheckCarExistInRentalList(rental)); 31 | 32 | if (result != null) 33 | { 34 | return result; 35 | } 36 | 37 | 38 | _rentalDal.Add(rental); 39 | return new SuccessResult(Messages.AddedRental); 40 | } 41 | 42 | [SecuredOperation("admin")] 43 | public IResult Delete(Rental rental) 44 | { 45 | _rentalDal.Delete(rental); 46 | return new SuccessResult(Messages.DeletedRental); 47 | } 48 | 49 | public IDataResult> GetAll() 50 | { 51 | return new SuccessDataResult>(_rentalDal.GetAll()); 52 | } 53 | 54 | public IDataResult GetById(int id) 55 | { 56 | return new SuccessDataResult(_rentalDal.Get(I => I.Id == id)); 57 | } 58 | 59 | public IDataResult> GetRentalDetails(Expression> filter = null) 60 | { 61 | return new SuccessDataResult>(_rentalDal.GetCarDetails(filter), Messages.ReturnedRental); 62 | } 63 | 64 | [ValidationAspect(typeof(RentalValidator))] 65 | public IResult Update(Rental rental) 66 | { 67 | _rentalDal.Update(rental); 68 | return new SuccessResult(Messages.UpdatedRental); 69 | } 70 | 71 | private IResult CheckCarExistInRentalList(Rental rental) 72 | { 73 | if (rental.ReturnDate > DateTime.Now && _rentalDal.GetCarDetails(I => I.CarId == rental.CarId).Count > 0) 74 | { 75 | return new ErrorResult(Messages.FailedRentalAddOrUpdate); 76 | } 77 | 78 | return new SuccessResult(); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /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 System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | 10 | namespace Business.Concrete 11 | { 12 | public class UserManager : IUserService 13 | { 14 | IUserDal _userDal; 15 | 16 | public UserManager(IUserDal userDal) 17 | { 18 | _userDal = userDal; 19 | } 20 | 21 | public IResult Add(User user) 22 | { 23 | _userDal.Add(user); 24 | return new SuccessResult(Messages.AddedUser); 25 | } 26 | 27 | public IResult Delete(User user) 28 | { 29 | _userDal.Delete(user); 30 | return new SuccessResult(Messages.DeletedUser); 31 | } 32 | 33 | public IDataResult> GetAll() 34 | { 35 | return new SuccessDataResult>(_userDal.GetAll()); 36 | } 37 | 38 | public IDataResult GetById(int id) 39 | { 40 | return new SuccessDataResult(_userDal.Get(I => I.Id == id)); 41 | } 42 | 43 | public IDataResult GetByMail(string email) 44 | { 45 | return new SuccessDataResult(_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.UpdatedUser); 57 | } 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Business/Constants/Messages.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Business.Constants 7 | { 8 | public static class Messages 9 | { 10 | public static string AddedBrand = "Marka başarıyla eklendi."; 11 | public static string DeletedBrand = "Marka başarıyla silindi."; 12 | public static string UpdatedBrand = "Marka başarıyla güncellendi."; 13 | public static string FailedBrandAddOrUpdate = "Lütfen marka isminin uzunluğunu 2 karakterden fazla giriniz."; 14 | 15 | public static string AddedCar = "Araba başarıyla eklendi."; 16 | public static string DeletedCar = "Araba başarıyla silindi."; 17 | public static string UpdatedCar = "Araba başarıyla güncellendi."; 18 | public static string FailedCarAddOrUpdate = "Lütfen günlük fiyat kısmını 0'dan büyük giriniz."; 19 | 20 | public static string AddedColor = "Renk başarıyla eklendi."; 21 | public static string DeletedColor = "Renk başarıyla silindi."; 22 | public static string UpdatedColor = "Renk başarıyla güncellendi."; 23 | 24 | public static string AddedCustomer = "Müşteri başarıyla eklendi."; 25 | public static string DeletedCustomer = "Müşteri başarıyla silindi."; 26 | public static string UpdatedCustomer = "Müşteri başarıyla güncellendi."; 27 | 28 | 29 | public static string AddedUser = "Kullanıcı başarıyla eklendi."; 30 | public static string DeletedUser = "Kullanıcı başarıyla silindi."; 31 | public static string UpdatedUser = "Kullanıcı başarıyla güncellendi."; 32 | 33 | 34 | public static string AddedRental = "Araba Kiralama işlemi baraşıyla gerçekleşti."; 35 | public static string DeletedRental = "Araba Kiralama işlemi iptal edildi."; 36 | public static string UpdatedRental = "Araba Kiralama işlemi güncellendi."; 37 | public static string FailedRentalAddOrUpdate = "Bu araba henüz teslim edilmediği için kiralayamazsınız."; 38 | public static string ReturnedRental = "Kiraladığınız araç teslim edildi."; 39 | 40 | public static string AddedCarImage = "Araba için yüklenilen resim başarıyla eklendi."; 41 | public static string DeletedCarImage = "Arabanın resmi başarıyla silindi."; 42 | public static string UpdatedCarImage = "Araba için yüklenilen resim başarıyla güncellendi."; 43 | public static string FailedCarImageAdd = "Bir araba 5'den fazla resme sahip olamaz."; 44 | 45 | public static string AuthorizationDenied = "Yetkiniz yok."; 46 | public static string UserRegistered = "Kayıt oldu."; 47 | 48 | public static string UserNotFound = "Kullanıcı bulunamadı."; 49 | public static string SuccessfulLogin = "Baraşıyla giriş yapıldı"; 50 | public static string PasswordError = "Parola hatası!"; 51 | public static string UserAlreadyExists = "Kullanıcı mevcut!"; 52 | public static string AccessTokenCreated = "Token oluşturuldu."; 53 | 54 | public static string AddedCreditCard = "Kredi Kartı başarıyla eklendi."; 55 | public static string DeletedCreditCard = "Kredi Kartı başarıyla silindi."; 56 | public static string UpdatedCreditCard = "Kredi Kartı başarıyla güncellendi."; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Business/DependencyResolvers/Autofac/AutofacBusinessModule.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Extras.DynamicProxy; 3 | using Business.Abstract; 4 | using Business.Concrete; 5 | using Castle.DynamicProxy; 6 | using Core.Utilities.Interceptors; 7 | using Core.Utilities.Security.JWT; 8 | using DataAccess.Abstract; 9 | using DataAccess.Concrete.EntityFramework.Repository; 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Text; 13 | 14 | namespace Business.DependencyResolvers.Autofac 15 | { 16 | public class AutofacBusinessModule : Module 17 | { 18 | protected override void Load(ContainerBuilder builder) 19 | { 20 | builder.RegisterType().As().SingleInstance(); 21 | builder.RegisterType().As().SingleInstance(); 22 | 23 | builder.RegisterType().As().SingleInstance(); 24 | builder.RegisterType().As().SingleInstance(); 25 | 26 | builder.RegisterType().As().SingleInstance(); 27 | builder.RegisterType().As().SingleInstance(); 28 | 29 | builder.RegisterType().As().SingleInstance(); 30 | builder.RegisterType().As().SingleInstance(); 31 | 32 | builder.RegisterType().As().SingleInstance(); 33 | builder.RegisterType().As().SingleInstance(); 34 | 35 | builder.RegisterType().As().SingleInstance(); 36 | builder.RegisterType().As().SingleInstance(); 37 | 38 | builder.RegisterType().As().SingleInstance(); 39 | builder.RegisterType().As().SingleInstance(); 40 | 41 | 42 | builder.RegisterType().As().SingleInstance(); 43 | builder.RegisterType().As().SingleInstance(); 44 | 45 | 46 | builder.RegisterType().As(); 47 | builder.RegisterType().As(); 48 | 49 | var assembly = System.Reflection.Assembly.GetExecutingAssembly(); 50 | 51 | builder.RegisterAssemblyTypes(assembly).AsImplementedInterfaces() 52 | .EnableInterfaceInterceptors(new ProxyGenerationOptions() 53 | { 54 | Selector = new AspectInterceptorSelector() 55 | }).SingleInstance(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/BrandValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class BrandValidator : AbstractValidator 10 | { 11 | public BrandValidator() 12 | { 13 | RuleFor(b => b.BrandName).NotEmpty(); 14 | RuleFor(b => b.BrandName).MinimumLength(2); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/CarImageValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class CarImageValidator : AbstractValidator 10 | { 11 | public CarImageValidator() 12 | { 13 | RuleFor(I => I.CarId).NotEmpty(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/CarValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class CarValidator : AbstractValidator 10 | { 11 | public CarValidator() 12 | { 13 | RuleFor(c => c.BrandId).NotEmpty(); 14 | RuleFor(c => c.ColorId).NotEmpty(); 15 | RuleFor(c => c.DailyPrice).NotEmpty(); 16 | RuleFor(c => c.DailyPrice).GreaterThan(0); 17 | RuleFor(c => c.Descriptions).NotEmpty(); 18 | RuleFor(c => c.ModelYear).NotEmpty(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/ColorValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class ColorValidator : AbstractValidator 10 | { 11 | public ColorValidator() 12 | { 13 | RuleFor(c => c.ColorName).NotEmpty(); 14 | RuleFor(c => c.ColorName).MinimumLength(3); 15 | 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/CustomerValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class CustomerValidator : AbstractValidator 10 | { 11 | public CustomerValidator() 12 | { 13 | RuleFor(c => c.CustomerName).NotEmpty(); 14 | RuleFor(c => c.CustomerName).MinimumLength(3); 15 | RuleFor(c => c.UserId).NotEmpty(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/RentalValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class RentalValidator : AbstractValidator 10 | { 11 | public RentalValidator() 12 | { 13 | RuleFor(r => r.CarId).NotEmpty(); 14 | RuleFor(r => r.CustomerId).NotEmpty(); 15 | RuleFor(r => r.RentDate).NotEmpty(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/UserValidator.cs: -------------------------------------------------------------------------------- 1 | using Core.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 UserValidator : AbstractValidator 10 | { 11 | public UserValidator() 12 | { 13 | RuleFor(u => u.FirstName).NotEmpty(); 14 | RuleFor(u => u.FirstName).MinimumLength(2); 15 | RuleFor(u => u.LastName).NotEmpty(); 16 | RuleFor(u => u.LastName).MinimumLength(2); 17 | RuleFor(u => u.Email).NotEmpty(); 18 | RuleFor(u => u.Email).EmailAddress(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ConsoleUI/ConsoleUI.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /ConsoleUI/Program.cs: -------------------------------------------------------------------------------- 1 | using Business.Concrete; 2 | using Core.Entities.Concrete; 3 | using DataAccess.Concrete.EntityFramework; 4 | using DataAccess.Concrete.EntityFramework.Repository; 5 | using DataAccess.Concrete.InMemory; 6 | using Entities.Concrete; 7 | using System; 8 | using System.Collections.Generic; 9 | 10 | namespace ConsoleUI 11 | { 12 | class Program 13 | { 14 | static void Main(string[] args) 15 | { 16 | CarManager carManager = new CarManager(new EfCarDal()); 17 | BrandManager brandManager = new BrandManager(new EfBrandDal()); 18 | ColorManager colorManager = new ColorManager(new EfColorDal()); 19 | CustomerManager customerManager = new CustomerManager(new EfCustomerDal()); 20 | UserManager userManager = new UserManager(new EfUserDal()); 21 | RentalManager rentalManager = new RentalManager(new EfRentalDal()); 22 | 23 | bool cikis = true; 24 | 25 | while (cikis) 26 | { 27 | Console.WriteLine( 28 | "Rent A Car \n---------------------------------------------------------------" + 29 | "\n\n1.Araba Ekleme\n" + 30 | "2.Araba Silme\n" + 31 | "3.Araba Güncelleme\n" + 32 | "4.Arabaların Listelenmesi\n" + 33 | "5.Arabaların detaylı bir şekilde Listelenmesi\n" + 34 | "6.Arabaların Marka Id'sine göre Listelenmesi\n" + 35 | "7.Arabaların Renk Id'sine göre Listelenmesi\n" + 36 | "8.Araba Id'sine göre Listeleme\n" + 37 | "9.Arabaların fiyat aralığına göre Listelenmesi\n" + 38 | "10.Arabaların model yılına göre Listelenmesi\n" + 39 | "11.Müşteri Ekleme\n" + 40 | "12.Müşterilerin Listelenmesi\n" + 41 | "13.Kullanıcı Ekleme\n" + 42 | "14.Kullanıcıların Listelenmesi\n" + 43 | "15.Araba Kiralama\n" + 44 | "16.Araba Teslim Etme\n" + 45 | "17.Araba Kiralama Listesi\n" + 46 | "18.Çıkış\n" + 47 | "Yukarıdakilerden hangi işlemi gerçekleştirmek istiyorsunuz ?" 48 | ); 49 | 50 | int number = Convert.ToInt32(Console.ReadLine()); 51 | Console.WriteLine("\n---------------------------------------------------------------\n"); 52 | switch (number) 53 | { 54 | case 1: 55 | CarAddition(carManager, brandManager, colorManager); 56 | break; 57 | case 2: 58 | GetAllCarDetails(carManager); 59 | CarDeletion(carManager); 60 | break; 61 | case 3: 62 | GetAllCarDetails(carManager); 63 | CarUpdate(carManager); 64 | break; 65 | case 4: 66 | GetAllCar(carManager); 67 | break; 68 | case 5: 69 | GetAllCarDetails(carManager); 70 | break; 71 | case 6: 72 | GetAllBrand(brandManager); 73 | CarListByBrand(carManager); 74 | break; 75 | case 7: 76 | GetAllColor(colorManager); 77 | CarListByColor(carManager); 78 | break; 79 | case 8: 80 | GetAllCarDetails(carManager); 81 | CarById(carManager, brandManager, colorManager); 82 | break; 83 | case 9: 84 | CarByDailyPrice(carManager, brandManager, colorManager); 85 | break; 86 | case 10: 87 | GetAllCarDetails(carManager); 88 | CarByModelYear(carManager, brandManager, colorManager); 89 | break; 90 | case 11: 91 | GetAllUserList(userManager); 92 | CustomerAddition(customerManager); 93 | break; 94 | case 12: 95 | GetAllCustomerList(customerManager); 96 | break; 97 | case 13: 98 | UserAddition(userManager); 99 | break; 100 | case 14: 101 | GetAllUserList(userManager); 102 | break; 103 | case 15: 104 | GetAllCarDetails(carManager); 105 | GetAllCustomerList(customerManager); 106 | RentalAddition(rentalManager); 107 | break; 108 | case 16: 109 | ReturnRental(rentalManager); 110 | break; 111 | case 17: 112 | GetAllRentalDetailList(rentalManager); 113 | break; 114 | case 18: 115 | cikis = false; 116 | Console.WriteLine("Çıkış işlemi gerçekleşti."); 117 | break; 118 | } 119 | } 120 | } 121 | 122 | private static void GetAllRentalDetailList(RentalManager rentalManager) 123 | { 124 | Console.WriteLine("Kiralanan Arabalar Listesi: \nId\tCar Name\tCustomer Name\tRent Date\tReturn Date"); 125 | foreach (var rental in rentalManager.GetRentalDetails().Data) 126 | { 127 | Console.WriteLine($"{rental.RentalId}\t{rental.CarName}\t{rental.CustomerName}\t{rental.RentDate}\t{rental.ReturnDate}"); 128 | } 129 | } 130 | 131 | private static void ReturnRental(RentalManager rentalManager) 132 | { 133 | Console.WriteLine("Kiraladığınız araba hangi Car Id'ye sahip?"); 134 | int carId = Convert.ToInt32(Console.ReadLine()); 135 | var returnedRental = rentalManager.GetRentalDetails(I => I.CarId == carId); 136 | foreach (var rental in returnedRental.Data) 137 | { 138 | rental.ReturnDate = DateTime.Now; 139 | Console.WriteLine(returnedRental.Message); 140 | } 141 | } 142 | 143 | private static void RentalAddition(RentalManager rentalManager) 144 | { 145 | Console.WriteLine("Car Id: "); 146 | int carIdForAdd = Convert.ToInt32(Console.ReadLine()); 147 | Console.WriteLine("Customer Id: "); 148 | int customerIdForAdd = Convert.ToInt32(Console.ReadLine()); 149 | 150 | Rental rentalForAdd = new Rental 151 | { 152 | CarId = carIdForAdd, 153 | CustomerId = customerIdForAdd, 154 | RentDate = DateTime.Now, 155 | ReturnDate = null, 156 | }; 157 | Console.WriteLine(rentalManager.Add(rentalForAdd).Message); 158 | 159 | } 160 | 161 | private static void UserAddition(UserManager userManager) 162 | { 163 | Console.WriteLine("First Name: "); 164 | string userNameForAdd = Console.ReadLine(); 165 | Console.WriteLine("Last Name: "); 166 | string userSurnameForAdd = Console.ReadLine(); 167 | Console.WriteLine("Email Name: "); 168 | string userEmailForAdd = Console.ReadLine(); 169 | Console.WriteLine("Password Name: "); 170 | string userPasswordForAdd = Console.ReadLine(); 171 | 172 | 173 | User userForAdd = new User 174 | { 175 | FirstName = userNameForAdd, 176 | LastName = userSurnameForAdd, 177 | Email = userEmailForAdd, 178 | 179 | }; 180 | userManager.Add(userForAdd); 181 | } 182 | 183 | private static void GetAllCustomerList(CustomerManager customerManager) 184 | { 185 | Console.WriteLine("Müşterilerin Listesi: \nId\tKullanıcı Id\tCustomer Name"); 186 | foreach (var customer in customerManager.GetAll().Data) 187 | { 188 | Console.WriteLine($"{customer.Id}\t{customer.UserId}\t{customer.CustomerName}"); 189 | } 190 | } 191 | 192 | private static void CustomerAddition(CustomerManager customerManager) 193 | { 194 | Console.WriteLine("User Id: "); 195 | int userIdForAdd = Convert.ToInt32(Console.ReadLine()); 196 | 197 | Console.WriteLine("Customer Name: "); 198 | string customerNameForAdd = Console.ReadLine(); 199 | 200 | Customer customerForAdd = new Customer 201 | { 202 | UserId = userIdForAdd, 203 | CustomerName = customerNameForAdd 204 | }; 205 | customerManager.Add(customerForAdd); 206 | } 207 | 208 | private static void GetAllUserList(UserManager userManager) 209 | { 210 | Console.WriteLine("Kullanıcı Listesi: \nId\tFirst Name\tLast Name\tEmail\tPassword"); 211 | foreach (var user in userManager.GetAll().Data) 212 | { 213 | // Console.WriteLine($"{user.Id}\t{user.FirstName}\t{user.LastName}\t{user.Password}"); 214 | } 215 | } 216 | 217 | private static void CarByModelYear(CarManager carManager, BrandManager brandManager, ColorManager colorManager) 218 | { 219 | Console.WriteLine("Hangi model yılına sahip arabayı görmek istiyorsunuz? Lütfen yıl değeri giriniz."); 220 | string modelYearForCarList = Console.ReadLine(); 221 | Console.WriteLine($"\n\nColor Id'si {modelYearForCarList} olan arabalar: \nId\tColor Name\tBrand Name\tModel Year\tDaily Price\tDescriptions"); 222 | foreach (var car in carManager.GetCarDetails(I => I.ModelYear == modelYearForCarList).Data) 223 | { 224 | Console.WriteLine($"{car.CarId}\t{car.ColorName}\t\t{car.BrandName}\t\t{car.ModelYear}\t\t{car.DailyPrice}\t\t{car.Descriptions}"); 225 | } 226 | } 227 | 228 | private static void CarByDailyPrice(CarManager carManager, BrandManager brandManager, ColorManager colorManager) 229 | { 230 | decimal min = Convert.ToDecimal(Console.ReadLine()); 231 | decimal max = Convert.ToDecimal(Console.ReadLine()); 232 | 233 | Console.WriteLine($"\n\nGünlük fiyat aralığı {min} ile {max} olan arabalar: \nId\tColor Name\tBrand Name\tModel Year\tDaily Price\tDescriptions"); 234 | foreach (var car in carManager.GetCarDetails(I => I.DailyPrice >= min & I.DailyPrice <= max).Data) 235 | { 236 | Console.WriteLine($"{car.CarId}\t{car.ColorName}\t\t{car.BrandName}\t\t{car.ModelYear}\t\t{car.DailyPrice}\t\t{car.Descriptions}"); 237 | } 238 | } 239 | 240 | private static void CarById(CarManager carManager, BrandManager brandManager, ColorManager colorManager) 241 | { 242 | Console.WriteLine("Hangi arabayı görmek istiyorsunuz? Lütfen bir Id numarası yazınız."); 243 | int carId = Convert.ToInt32(Console.ReadLine()); 244 | Console.WriteLine($"\n\nId'si {carId} olan araba: \nId\tColor Name\tBrand Name\tModel Year\tDaily Price\tDescriptions"); 245 | Car carById = carManager.GetById(carId).Data; 246 | Console.WriteLine($"{carById.Id}\t{colorManager.GetById(carById.ColorId).Data.ColorName}\t\t{brandManager.GetById(carById.BrandId).Data.BrandName}\t\t{carById.ModelYear}\t\t{carById.DailyPrice}\t\t{carById.Descriptions}"); 247 | } 248 | 249 | private static void CarListByColor(CarManager carManager) 250 | { 251 | Console.WriteLine("Hangi renge sahip arabayı görmek istiyorsunuz? Lütfen bir Id numarası yazınız."); 252 | int colorIdForCarList = Convert.ToInt32(Console.ReadLine()); 253 | Console.WriteLine($"\n\nColor Id'si {colorIdForCarList} olan arabalar: \nId\tColor Name\tBrand Name\tModel Year\tDaily Price\tDescriptions"); 254 | foreach (var car in carManager.GetCarDetails(I => I.ColorId == colorIdForCarList).Data) 255 | { 256 | Console.WriteLine($"{car.CarId}\t{car.ColorName}\t\t{car.BrandName}\t\t{car.ModelYear}\t\t{car.DailyPrice}\t\t{car.Descriptions}"); 257 | } 258 | } 259 | 260 | private static void CarListByBrand(CarManager carManager) 261 | { 262 | Console.WriteLine("Hangi markaya sahip arabayı görmek istiyorsunuz? Lütfen bir Id numarası yazınız."); 263 | int brandIdForCarList = Convert.ToInt32(Console.ReadLine()); 264 | Console.WriteLine($"\n\nBrand Id'si {brandIdForCarList} olan arabalar: \nId\tColor Name\tBrand Name\tModel Year\tDaily Price\tDescriptions"); 265 | foreach (var car in carManager.GetCarDetails(I => I.BrandId == brandIdForCarList).Data) 266 | { 267 | Console.WriteLine($"{car.CarId}\t{car.ColorName}\t\t{car.BrandName}\t\t{car.ModelYear}\t\t{car.DailyPrice}\t\t{car.Descriptions}"); 268 | } 269 | } 270 | 271 | private static void CarUpdate(CarManager carManager) 272 | { 273 | Console.WriteLine("Car Id: "); 274 | int carIdForUpdate = Convert.ToInt32(Console.ReadLine()); 275 | 276 | Console.WriteLine("Brand Id: "); 277 | int brandIdForUpdate = Convert.ToInt32(Console.ReadLine()); 278 | 279 | Console.WriteLine("Color Id: "); 280 | int colorIdForUpdate = Convert.ToInt32(Console.ReadLine()); 281 | 282 | Console.WriteLine("Daily Price: "); 283 | decimal dailyPriceForUpdate = Convert.ToDecimal(Console.ReadLine()); 284 | 285 | Console.WriteLine("Description : "); 286 | string descriptionForUpdate = Console.ReadLine(); 287 | 288 | Console.WriteLine("Model Year: "); 289 | string modelYearForUpdate = Console.ReadLine(); 290 | 291 | Car carForUpdate = new Car { Id = carIdForUpdate, BrandId = brandIdForUpdate, ColorId = colorIdForUpdate, DailyPrice = dailyPriceForUpdate, Descriptions = descriptionForUpdate, ModelYear = modelYearForUpdate }; 292 | carManager.Update(carForUpdate); 293 | } 294 | 295 | private static void CarDeletion(CarManager carManager) 296 | { 297 | Console.WriteLine("Hangi Id'ye sahip arabayı silmek istiyorsunuz? "); 298 | int carIdForDelete = Convert.ToInt32(Console.ReadLine()); 299 | carManager.Delete(carManager.GetById(carIdForDelete).Data); 300 | } 301 | 302 | private static void CarAddition(CarManager carManager, BrandManager brandManager, ColorManager colorManager) 303 | { 304 | Console.WriteLine("Color Listesi"); 305 | GetAllColor(colorManager); 306 | 307 | Console.WriteLine("Brand Listesi"); 308 | GetAllBrand(brandManager); 309 | 310 | Console.WriteLine("\nBrand Id: "); 311 | int brandIdForAdd = Convert.ToInt32(Console.ReadLine()); 312 | 313 | Console.WriteLine("Color Id: "); 314 | int colorIdForAdd = Convert.ToInt32(Console.ReadLine()); 315 | 316 | Console.WriteLine("Daily Price: "); 317 | decimal dailyPriceForAdd = Convert.ToDecimal(Console.ReadLine()); 318 | 319 | Console.WriteLine("Description : "); 320 | string descriptionForAdd = Console.ReadLine(); 321 | 322 | Console.WriteLine("Model Year: "); 323 | string modelYearForAdd = Console.ReadLine(); 324 | 325 | Car carForAdd = new Car { BrandId = brandIdForAdd, ColorId = colorIdForAdd, DailyPrice = dailyPriceForAdd, Descriptions = descriptionForAdd, ModelYear = modelYearForAdd }; 326 | carManager.Add(carForAdd); 327 | } 328 | 329 | private static void GetAllCarDetails(CarManager carManager) 330 | { 331 | Console.WriteLine("Arabaların detaylı listesi: \nId\tColor Name\tBrand Name\tModel Year\tDaily Price\tDescriptions"); 332 | foreach (var car in carManager.GetCarDetails().Data) 333 | { 334 | Console.WriteLine($"{car.CarId}\t{car.ColorName}\t\t{car.BrandName}\t\t{car.ModelYear}\t\t{car.DailyPrice}\t\t{car.Descriptions}"); 335 | } 336 | } 337 | 338 | private static void GetAllCar(CarManager carManager) 339 | { 340 | Console.WriteLine("Arabaların Listesi: \nId\tColor Name\tBrand Name\tModel Year\tDaily Price\tDescriptions"); 341 | foreach (var car in carManager.GetAll().Data) 342 | { 343 | Console.WriteLine($"{car.Id}\t{car.ColorId}\t\t{car.BrandId}\t\t{car.ModelYear}\t\t{car.DailyPrice}\t\t{car.Descriptions}"); 344 | } 345 | } 346 | 347 | private static void GetAllBrand(BrandManager brandManager) 348 | { 349 | foreach (var brand in brandManager.GetAll().Data) 350 | { 351 | Console.WriteLine($"{brand.Id}\t{brand.BrandName}"); 352 | } 353 | } 354 | 355 | private static void GetAllColor(ColorManager colorManager) 356 | { 357 | foreach (var color in colorManager.GetAll().Data) 358 | { 359 | Console.WriteLine($"{color.Id}\t{color.ColorName}"); 360 | } 361 | } 362 | } 363 | } 364 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Caching/CacheAspect.cs: -------------------------------------------------------------------------------- 1 | using Core.CrossCuttingConcerns.Caching; 2 | using Core.Utilities.Interceptors; 3 | using Core.Utilities.IoC; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using Castle.DynamicProxy; 9 | using System.Linq; 10 | 11 | namespace Core.Aspects.Autofac.Caching 12 | { 13 | public class CacheAspect : MethodInterception 14 | { 15 | private int _duration; 16 | private ICacheManager _cacheManager; 17 | 18 | public CacheAspect(int duration = 60) 19 | { 20 | _duration = duration; 21 | _cacheManager = ServiceTool.ServiceProvider.GetService(); 22 | } 23 | 24 | public override void Intercept(IInvocation invocation) 25 | { 26 | var methodName = string.Format($"{invocation.Method.ReflectedType.FullName}.{invocation.Method.Name}"); 27 | var arguments = invocation.Arguments.ToList(); 28 | var key = $"{methodName}({string.Join(",", arguments.Select(x => x?.ToString() ?? ""))})"; 29 | 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 Microsoft.Extensions.DependencyInjection; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 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/Exception/ExceptionLogAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.CrossCuttingConcerns.Logging; 3 | using Core.CrossCuttingConcerns.Logging.Log4Net; 4 | using Core.Utilities.Interceptors; 5 | using Core.Utilities.Messages; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | 10 | namespace Core.Aspects.Autofac.Exception 11 | { 12 | public class ExceptionLogAspect : MethodInterception 13 | { 14 | private LoggerServiceBase _loggerServiceBase; 15 | 16 | public ExceptionLogAspect(Type loggerService) 17 | { 18 | if (loggerService.BaseType != typeof(LoggerServiceBase)) 19 | { 20 | throw new System.Exception(AspectMessages.WrongLoggerType); 21 | } 22 | 23 | _loggerServiceBase = (LoggerServiceBase)Activator.CreateInstance(loggerService); 24 | } 25 | protected override void OnException(IInvocation invocation, System.Exception e) 26 | { 27 | LogDetailWithException logDetailWithException = GetLogDetail(invocation); 28 | logDetailWithException.ExceptionMessage = e.Message; 29 | _loggerServiceBase.Error(logDetailWithException); 30 | } 31 | 32 | private LogDetailWithException GetLogDetail(IInvocation invocation) 33 | { 34 | var logParameters = new List(); 35 | 36 | for (int i = 0; i < invocation.Arguments.Length; i++) 37 | { 38 | logParameters.Add(new LogParameter 39 | { 40 | Name = invocation.GetConcreteMethod().GetParameters()[i].Name, 41 | Value = invocation.Arguments[i], 42 | Type = invocation.Arguments[i].GetType().Name 43 | }); 44 | } 45 | 46 | var logDetailWithException = new LogDetailWithException 47 | { 48 | MethodName = invocation.Method.Name, 49 | LogParameters = logParameters 50 | }; 51 | 52 | return logDetailWithException; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Logging/LogAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.CrossCuttingConcerns.Logging; 3 | using Core.CrossCuttingConcerns.Logging.Log4Net; 4 | using Core.Utilities.Interceptors; 5 | using Core.Utilities.Messages; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | 10 | namespace Core.Aspects.Autofac.Logging 11 | { 12 | public class LogAspect : MethodInterception 13 | { 14 | private LoggerServiceBase _loggerServiceBase; 15 | 16 | public LogAspect(Type loggerService) 17 | { 18 | if (loggerService.BaseType != typeof(LoggerServiceBase)) 19 | { 20 | throw new System.Exception(AspectMessages.WrongLoggerType); 21 | } 22 | 23 | _loggerServiceBase = (LoggerServiceBase)Activator.CreateInstance(loggerService); 24 | } 25 | 26 | protected override void OnBefore(IInvocation invocation) 27 | { 28 | _loggerServiceBase.Info(GetLogDetail(invocation)); 29 | } 30 | 31 | private LogDetail GetLogDetail(IInvocation invocation) 32 | { 33 | var logParameters = new List(); 34 | for (int i = 0; i < invocation.Arguments.Length; i++) 35 | { 36 | logParameters.Add(new LogParameter 37 | { 38 | Name = invocation.GetConcreteMethod().GetParameters()[i].Name, 39 | Value = invocation.Arguments[i], 40 | Type = invocation.Arguments[i].GetType().Name 41 | }); 42 | } 43 | 44 | var logDetail = new LogDetail 45 | { 46 | MethodName = invocation.Method.Name, 47 | LogParameters = logParameters 48 | }; 49 | 50 | return logDetail; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Performance/PerformanceAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.Utilities.Interceptors; 3 | using Core.Utilities.IoC; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Diagnostics; 8 | using System.Text; 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 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Caching/ICacheManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Caching 6 | { 7 | public interface ICacheManager 8 | { 9 | T Get(string key); 10 | object Get(string key); 11 | void Add(string key, object value, int duration); 12 | bool IsAdd(string key); 13 | void Remove(string key); 14 | void RemoveByPattern(string pattern); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Caching/Microsoft/MemoryCacheManager.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.IoC; 2 | using Microsoft.Extensions.Caching.Memory; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using Microsoft.Extensions.DependencyInjection; 7 | using System.Text.RegularExpressions; 8 | using System.Linq; 9 | 10 | namespace Core.CrossCuttingConcerns.Caching.Microsoft 11 | { 12 | public class MemoryCacheManager : ICacheManager 13 | { 14 | //Adapter Pattern 15 | IMemoryCache _memoryCache; 16 | 17 | public MemoryCacheManager() 18 | { 19 | _memoryCache = ServiceTool.ServiceProvider.GetService(); 20 | } 21 | 22 | public void Add(string key, object value, int duration) 23 | { 24 | _memoryCache.Set(key, value, TimeSpan.FromMinutes(duration)); 25 | } 26 | 27 | public T Get(string key) 28 | { 29 | return _memoryCache.Get(key); 30 | } 31 | 32 | public object Get(string key) 33 | { 34 | return _memoryCache.Get(key); 35 | } 36 | 37 | public bool IsAdd(string key) 38 | { 39 | return _memoryCache.TryGetValue(key, out _); 40 | } 41 | 42 | public void Remove(string key) 43 | { 44 | _memoryCache.Remove(key); 45 | } 46 | 47 | public void RemoveByPattern(string pattern) 48 | { 49 | var cacheEntriesCollectionDefinition = typeof(MemoryCache).GetProperty("EntriesCollection", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); 50 | var cacheEntriesCollection = cacheEntriesCollectionDefinition.GetValue(_memoryCache) as dynamic; 51 | List cacheCollectionValues = new List(); 52 | 53 | foreach (var cacheItem in cacheEntriesCollection) 54 | { 55 | ICacheEntry cacheItemValue = cacheItem.GetType().GetProperty("Value").GetValue(cacheItem, null); 56 | cacheCollectionValues.Add(cacheItemValue); 57 | } 58 | 59 | var regex = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase); 60 | var keysToRemove = cacheCollectionValues.Where(d => regex.IsMatch(d.Key.ToString())).Select(d => d.Key).ToList(); 61 | 62 | foreach (var key in keysToRemove) 63 | { 64 | _memoryCache.Remove(key); 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Logging/Log4Net/Layouts/JsonLayout.cs: -------------------------------------------------------------------------------- 1 | using log4net.Core; 2 | using log4net.Layout; 3 | using Newtonsoft.Json; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.IO; 7 | using System.Text; 8 | using System.Xml; 9 | 10 | namespace Core.CrossCuttingConcerns.Logging.Log4Net.Layouts 11 | { 12 | public class JsonLayout : LayoutSkeleton 13 | { 14 | public override void ActivateOptions() 15 | { 16 | 17 | } 18 | 19 | public override void Format(TextWriter writer, LoggingEvent loggingEvent) 20 | { 21 | var logEvent = new SerializableLogEvent(loggingEvent); 22 | var json = JsonConvert.SerializeObject(logEvent, Newtonsoft.Json.Formatting.Indented); 23 | writer.WriteLine(json); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Logging/Log4Net/LoggerServiceBase.cs: -------------------------------------------------------------------------------- 1 | using log4net; 2 | using log4net.Repository; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Reflection; 7 | using System.Text; 8 | using System.Xml; 9 | 10 | namespace Core.CrossCuttingConcerns.Logging.Log4Net 11 | { 12 | public class LoggerServiceBase 13 | { 14 | private ILog _log; 15 | public LoggerServiceBase(string name) 16 | { 17 | XmlDocument xmlDocument = new XmlDocument(); 18 | xmlDocument.Load(File.OpenRead("log4net.config")); 19 | 20 | ILoggerRepository loggerRepository = LogManager.CreateRepository(Assembly.GetEntryAssembly(), 21 | typeof(log4net.Repository.Hierarchy.Hierarchy)); 22 | log4net.Config.XmlConfigurator.Configure(loggerRepository, xmlDocument["log4net"]); 23 | 24 | _log = LogManager.GetLogger(loggerRepository.Name, name); 25 | 26 | 27 | } 28 | 29 | public bool IsInfoEnabled => _log.IsInfoEnabled; 30 | public bool IsDebugEnabled => _log.IsDebugEnabled; 31 | public bool IsWarnEnabled => _log.IsWarnEnabled; 32 | public bool IsFatalEnabled => _log.IsFatalEnabled; 33 | public bool IsErrorEnabled => _log.IsErrorEnabled; 34 | 35 | public void Info(object logMessage) 36 | { 37 | if (IsInfoEnabled) 38 | _log.Info(logMessage); 39 | } 40 | 41 | public void Debug(object logMessage) 42 | { 43 | if (IsDebugEnabled) 44 | _log.Debug(logMessage); 45 | } 46 | 47 | public void Warn(object logMessage) 48 | { 49 | if (IsWarnEnabled) 50 | _log.Warn(logMessage); 51 | } 52 | 53 | public void Fatal(object logMessage) 54 | { 55 | if (IsFatalEnabled) 56 | _log.Fatal(logMessage); 57 | } 58 | 59 | public void Error(object logMessage) 60 | { 61 | if (IsErrorEnabled) 62 | _log.Error(logMessage); 63 | } 64 | 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Logging/Log4Net/Loggers/FileLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Logging.Log4Net.Loggers 6 | { 7 | public class FileLogger : LoggerServiceBase 8 | { 9 | public FileLogger() : base("JsonFileLogger") 10 | { 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Logging/Log4Net/SerializableLogEvent.cs: -------------------------------------------------------------------------------- 1 | using log4net.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.CrossCuttingConcerns.Logging.Log4Net 7 | { 8 | [Serializable] 9 | public class SerializableLogEvent 10 | { 11 | private LoggingEvent _loggingEvent; 12 | 13 | public SerializableLogEvent(LoggingEvent loggingEvent) 14 | { 15 | _loggingEvent = loggingEvent; 16 | } 17 | 18 | public object Message => _loggingEvent.MessageObject; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Logging/LogDetail.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Logging 6 | { 7 | public class LogDetail 8 | { 9 | public string MethodName { get; set; } 10 | public List LogParameters { get; set; } 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Logging/LogDetailWithException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Logging 6 | { 7 | public class LogDetailWithException : LogDetail 8 | { 9 | public string ExceptionMessage { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Logging/LogParameter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Logging 6 | { 7 | public class LogParameter 8 | { 9 | public string Name { get; set; } 10 | public object Value { get; set; } 11 | public string Type { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Validation/ValidationTool.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.CrossCuttingConcerns.Validation 7 | { 8 | public static class ValidationTool 9 | { 10 | public static void Validate(IValidator validator, object entity) 11 | { 12 | var context = new ValidationContext(entity); 13 | var result = validator.Validate(context); 14 | if (!result.IsValid) 15 | { 16 | throw new ValidationException(result.Errors); 17 | } 18 | 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Core/DataAccess/EntityFramework/EfEntityRepositoryBase.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using Microsoft.EntityFrameworkCore; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Linq.Expressions; 7 | using System.Text; 8 | 9 | namespace Core.DataAccess.EntityFramework 10 | { 11 | public class EfEntityRepositoryBase : IEntityRepository 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 Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq.Expressions; 5 | using System.Text; 6 | 7 | namespace Core.DataAccess 8 | { 9 | public interface IEntityRepository where T : class, IEntity, new() 10 | { 11 | void Add(T entity); 12 | void Update(T entity); 13 | void Delete(T entity); 14 | List GetAll(Expression> filter = null); 15 | T Get(Expression> filter); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Core/DependencyResolvers/CoreModule.cs: -------------------------------------------------------------------------------- 1 | using Core.CrossCuttingConcerns.Caching; 2 | using Core.CrossCuttingConcerns.Caching.Microsoft; 3 | using Core.Utilities.IoC; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Diagnostics; 9 | using System.Text; 10 | 11 | namespace Core.DependencyResolvers 12 | { 13 | public class CoreModule : ICoreModule 14 | { 15 | public void Load(IServiceCollection serviceCollection) 16 | { 17 | serviceCollection.AddMemoryCache(); 18 | serviceCollection.AddSingleton(); 19 | serviceCollection.AddSingleton(); 20 | serviceCollection.AddSingleton(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/OperationClaim.cs: -------------------------------------------------------------------------------- 1 | namespace Core.Entities.Concrete 2 | { 3 | public class OperationClaim : IEntity 4 | { 5 | public int Id { get; set; } 6 | public string Name { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities.Concrete 6 | { 7 | public class User : IEntity 8 | { 9 | public int Id { get; set; } 10 | public string FirstName { get; set; } 11 | public string LastName { get; set; } 12 | public string Email { get; set; } 13 | public byte[] PasswordSalt { get; set; } 14 | public byte[] PasswordHash { get; set; } 15 | public bool Status { get; set; } 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/UserOperationClaim.cs: -------------------------------------------------------------------------------- 1 | namespace Core.Entities.Concrete 2 | { 3 | public class UserOperationClaim : IEntity 4 | { 5 | public int Id { get; set; } 6 | public int UserId { get; set; } 7 | public int OperationClaimId { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Core/Entities/IDto.cs: -------------------------------------------------------------------------------- 1 | namespace Core 2 | { 3 | public interface IDto 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /Core/Entities/IEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities 6 | { 7 | public interface IEntity 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Core/Extensions/ClaimExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IdentityModel.Tokens.Jwt; 4 | using System.Linq; 5 | using System.Security.Claims; 6 | using System.Text; 7 | 8 | namespace Core.Extensions 9 | { 10 | public static class ClaimExtensions 11 | { 12 | public static void AddEmail(this ICollection claims, string email) 13 | { 14 | claims.Add(new Claim(JwtRegisteredClaimNames.Email, email)); 15 | } 16 | 17 | public static void AddName(this ICollection claims, string name) 18 | { 19 | claims.Add(new Claim(ClaimTypes.Name, name)); 20 | } 21 | 22 | public static void AddNameIdentifier(this ICollection claims, string nameIdentifier) 23 | { 24 | claims.Add(new Claim(ClaimTypes.NameIdentifier, nameIdentifier)); 25 | } 26 | 27 | public static void AddRoles(this ICollection claims, string[] roles) 28 | { 29 | roles.ToList().ForEach(role => claims.Add(new Claim(ClaimTypes.Role, role))); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Core/Extensions/ClaimsPrincipalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Claims; 5 | using System.Text; 6 | 7 | namespace Core.Extensions 8 | { 9 | public static class ClaimsPrincipalExtensions 10 | { 11 | public static List Claims(this ClaimsPrincipal claimsPrincipal, string claimType) 12 | { 13 | var result = claimsPrincipal?.FindAll(claimType)?.Select(x => x.Value).ToList(); 14 | return result; 15 | } 16 | 17 | public static List ClaimRoles(this ClaimsPrincipal claimsPrincipal) 18 | { 19 | return claimsPrincipal?.Claims(ClaimTypes.Role); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Extensions/ErrorDetails.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation.Results; 2 | using Newtonsoft.Json; 3 | using System.Collections.Generic; 4 | 5 | namespace Core.Extensions 6 | { 7 | public class ErrorDetails 8 | { 9 | public string Message { get; set; } 10 | public int StatusCode { get; set; } 11 | 12 | public override string ToString() 13 | { 14 | return JsonConvert.SerializeObject(this); 15 | } 16 | } 17 | 18 | public class ValidationErrorDetails : ErrorDetails 19 | { 20 | public IEnumerable ValidationErrors { get; set; } 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Core/Extensions/ExceptionMiddleware.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | using FluentValidation.Results; 3 | using Microsoft.AspNetCore.Http; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Net; 7 | using System.Security.Authentication; 8 | using System.Threading.Tasks; 9 | 10 | namespace Core.Extensions 11 | { 12 | public class ExceptionMiddleware 13 | { 14 | private RequestDelegate _next; 15 | 16 | public ExceptionMiddleware(RequestDelegate next) 17 | { 18 | _next = next; 19 | } 20 | 21 | public async Task InvokeAsync(HttpContext httpContext) 22 | { 23 | try 24 | { 25 | await _next(httpContext); 26 | } 27 | catch (Exception e) 28 | { 29 | await HandleExceptionAsync(httpContext, e); 30 | } 31 | } 32 | 33 | private Task HandleExceptionAsync(HttpContext httpContext, Exception e) 34 | { 35 | httpContext.Response.ContentType = "application/json"; 36 | httpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; 37 | 38 | string message = "Internal Server Error"; 39 | IEnumerable errors; 40 | 41 | if (e.GetType() == typeof(ValidationException)) 42 | { 43 | message = e.Message; 44 | errors = ((ValidationException)e).Errors; 45 | httpContext.Response.StatusCode = 400; 46 | 47 | return httpContext.Response.WriteAsync(new ValidationErrorDetails 48 | { 49 | StatusCode = 400, 50 | Message = message, 51 | ValidationErrors = errors 52 | }.ToString()); 53 | } 54 | else if (e.Message == "Yetkiniz yok.") 55 | { 56 | message = e.Message; 57 | httpContext.Response.StatusCode = 401; 58 | 59 | return httpContext.Response.WriteAsync(new ErrorDetails 60 | { 61 | StatusCode = 401, 62 | Message = message, 63 | }.ToString()); 64 | } 65 | 66 | return httpContext.Response.WriteAsync(new ErrorDetails 67 | { 68 | StatusCode = httpContext.Response.StatusCode, 69 | Message = message 70 | }.ToString()); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Core/Extensions/ExceptionMiddlewareExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | 3 | namespace Core.Extensions 4 | { 5 | public static class ExceptionMiddlewareExtensions 6 | { 7 | public static void ConfigureCustomExceptionMiddleware(this IApplicationBuilder app) 8 | { 9 | app.UseMiddleware(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Extensions/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.IoC; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Core.Extensions 8 | { 9 | public static class ServiceCollectionExtensions 10 | { 11 | public static IServiceCollection AddDependencyResolvers 12 | (this IServiceCollection serviceCollection, ICoreModule[] modules) 13 | { 14 | foreach (var module in modules) 15 | { 16 | module.Load(serviceCollection); 17 | } 18 | 19 | return ServiceTool.Create(serviceCollection); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /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 | 20 | return null; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Core/Utilities/Helpers/FileHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using System; 3 | using System.IO; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using Core.Utilities.Results; 7 | 8 | namespace Core.Utilities.Helpers 9 | { 10 | public class FileHelper 11 | { 12 | public static string AddAsync(IFormFile file) 13 | { 14 | var result = newPath(file); 15 | try 16 | { 17 | var sourcepath = Path.GetTempFileName(); 18 | if (file.Length > 0) 19 | using (var stream = new FileStream(sourcepath, FileMode.Create)) 20 | file.CopyTo(stream); 21 | 22 | File.Move(sourcepath, result.newPath); 23 | } 24 | catch (Exception exception) 25 | { 26 | 27 | return exception.Message; 28 | } 29 | 30 | return result.Path2.Replace("\\", "/"); 31 | } 32 | 33 | public static string UpdateAsync(string sourcePath, IFormFile file) 34 | { 35 | var result = newPath(file); 36 | 37 | try 38 | { 39 | //File.Copy(sourcePath,result); 40 | 41 | if (sourcePath.Length > 0) 42 | { 43 | using (var stream = new FileStream(result.newPath, FileMode.Create)) 44 | { 45 | file.CopyTo(stream); 46 | } 47 | } 48 | 49 | File.Delete(sourcePath); 50 | } 51 | catch (Exception excepiton) 52 | { 53 | return excepiton.Message; 54 | } 55 | 56 | return result.Path2.Replace("\\","/"); 57 | } 58 | 59 | public static IResult DeleteAsync(string path) 60 | { 61 | try 62 | { 63 | File.Delete(path); 64 | } 65 | catch (Exception exception) 66 | { 67 | return new ErrorResult(exception.Message); 68 | } 69 | 70 | return new SuccessResult(); 71 | } 72 | 73 | public static (string newPath, string Path2) newPath(IFormFile file) 74 | { 75 | FileInfo ff = new FileInfo(file.FileName); 76 | string fileExtension = ff.Extension; 77 | 78 | var creatingUniqueFilename = Guid.NewGuid().ToString("N") 79 | + "_" + DateTime.Now.Month + "_" 80 | + DateTime.Now.Day + "_" 81 | + DateTime.Now.Year + fileExtension; 82 | 83 | 84 | string path = Environment.CurrentDirectory + @"\wwwroot\Images"; 85 | 86 | string result = $@"{path}\{creatingUniqueFilename}"; 87 | 88 | return (result, $"\\Images\\{creatingUniqueFilename}"); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/AspectInterceptorSelector.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.Aspects.Autofac.Exception; 3 | using Core.CrossCuttingConcerns.Logging.Log4Net.Loggers; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Reflection; 8 | using System.Text; 9 | 10 | namespace Core.Utilities.Interceptors 11 | { 12 | public class AspectInterceptorSelector : IInterceptorSelector 13 | { 14 | public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) 15 | { 16 | var classAttributes = type.GetCustomAttributes 17 | (true).ToList(); 18 | var methodAttributes = type.GetMethod(method.Name) 19 | .GetCustomAttributes(true); 20 | classAttributes.AddRange(methodAttributes); 21 | classAttributes.Add(new ExceptionLogAspect(typeof(FileLogger))); 22 | 23 | return classAttributes.OrderBy(x => x.Priority).ToArray(); 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/MethodInterception.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | 4 | namespace Core.Utilities.Interceptors 5 | { 6 | 7 | public abstract class MethodInterception : MethodInterceptionBaseAttribute 8 | { 9 | protected virtual void OnBefore(IInvocation invocation) { } 10 | protected virtual void OnAfter(IInvocation invocation) { } 11 | protected virtual void OnException(IInvocation invocation, System.Exception e) { } 12 | protected virtual void OnSuccess(IInvocation invocation) { } 13 | public override void Intercept(IInvocation invocation) 14 | { 15 | var isSuccess = true; 16 | OnBefore(invocation); 17 | try 18 | { 19 | invocation.Proceed(); 20 | } 21 | catch (Exception e) 22 | { 23 | isSuccess = false; 24 | OnException(invocation, e); 25 | throw; 26 | } 27 | finally 28 | { 29 | if (isSuccess) 30 | { 31 | OnSuccess(invocation); 32 | } 33 | } 34 | OnAfter(invocation); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /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 | } 18 | -------------------------------------------------------------------------------- /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/Messages/AspectMessages.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Messages 6 | { 7 | public static class AspectMessages 8 | { 9 | public static string WrongValidationType = "Wrong Validation Type"; 10 | public static string WrongLoggerType = "Wrong Logger Type"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Utilities/Results/DataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class DataResult : Result, IDataResult 8 | { 9 | public DataResult(T data, bool success, string message) : base(success, message) 10 | { 11 | Data = data; 12 | } 13 | 14 | public DataResult(T data, bool success) : base(success) 15 | { 16 | Data = data; 17 | 18 | } 19 | 20 | public T Data { get; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Utilities/Results/ErrorDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class ErrorDataResult : DataResult 8 | { 9 | public ErrorDataResult(T data) : base(data, false) 10 | { 11 | } 12 | 13 | public ErrorDataResult(T data, string message) : base(data, false, message) 14 | { 15 | } 16 | 17 | public ErrorDataResult(string message) : base(default, false, message) 18 | { 19 | 20 | } 21 | public ErrorDataResult() : base(default, false) 22 | { 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Core/Utilities/Results/ErrorResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class ErrorResult : Result 8 | { 9 | public ErrorResult(string message) : base(false, message) 10 | { 11 | } 12 | public ErrorResult() : base(false) 13 | { 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /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 | } 14 | -------------------------------------------------------------------------------- /Core/Utilities/Results/Result.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class Result : IResult 8 | { 9 | 10 | public Result(bool success, string message) : this(success) 11 | { 12 | Message = message; 13 | } 14 | 15 | public Result(bool success) 16 | { 17 | Success = success; 18 | } 19 | 20 | public bool Success { get; } 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) : base(data, true) 10 | { 11 | } 12 | 13 | public SuccessDataResult(T data, string message) : base(data, true, message) 14 | { 15 | } 16 | 17 | public SuccessDataResult(string message) : base(default, true, message) 18 | { 19 | 20 | } 21 | public SuccessDataResult() : base(default,true) 22 | { 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Core/Utilities/Results/SuccessResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class SuccessResult : Result 8 | { 9 | public SuccessResult(string message):base(true, message) 10 | { 11 | 12 | } 13 | 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 | 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 | 32 | return true; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /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 | //Kullanıcı giriş yaptıktan sonra token veriyoruz. 8 | public class AccessToken 9 | { 10 | public string Token { get; set; } 11 | public DateTime Expiration { get; set; } 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /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 | //Token üretiyor. 9 | public interface ITokenHelper 10 | { 11 | AccessToken CreateToken(User user, List operationClaims); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /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; } //ASP Web API appsetting.json dosyasını okumaya yarıyor. 18 | private TokenOptions _tokenOptions; 19 | private DateTime _accessTokenExpiration; 20 | public JwtHelper(IConfiguration configuration) 21 | { 22 | Configuration = configuration; 23 | _tokenOptions = Configuration.GetSection("TokenOptions").Get(); 24 | 25 | } 26 | public AccessToken CreateToken(User user, List operationClaims) 27 | { 28 | _accessTokenExpiration = DateTime.Now.AddMinutes(_tokenOptions.AccessTokenExpiration); //Bu token ne zaman bitecek 29 | var securityKey = SecurityKeyHelper.CreateSecurityKey(_tokenOptions.SecurityKey); 30 | var signingCredentials = SigningCredentialsHelper.CreateSigningCredentials(securityKey); 31 | var jwt = CreateJwtSecurityToken(_tokenOptions, user, signingCredentials, operationClaims); 32 | var jwtSecurityTokenHandler = new JwtSecurityTokenHandler(); 33 | var token = jwtSecurityTokenHandler.WriteToken(jwt); 34 | 35 | return new AccessToken 36 | { 37 | Token = token, 38 | Expiration = _accessTokenExpiration 39 | }; 40 | 41 | } 42 | 43 | public JwtSecurityToken CreateJwtSecurityToken(TokenOptions tokenOptions, User user, 44 | SigningCredentials signingCredentials, List operationClaims) 45 | { 46 | var jwt = new JwtSecurityToken( 47 | issuer: tokenOptions.Issuer, 48 | audience: tokenOptions.Audience, 49 | expires: _accessTokenExpiration, 50 | notBefore: DateTime.Now, 51 | claims: SetClaims(user, operationClaims), 52 | signingCredentials: signingCredentials 53 | ); 54 | return jwt; 55 | } 56 | 57 | private IEnumerable SetClaims(User user, List operationClaims) 58 | { 59 | var claims = new List(); 60 | claims.AddNameIdentifier(user.Id.ToString()); 61 | claims.AddEmail(user.Email); 62 | claims.AddName($"{user.FirstName} {user.LastName}"); 63 | claims.AddRoles(operationClaims.Select(c => c.Name).ToArray()); 64 | 65 | return claims; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/TokenOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Security.JWT 6 | { 7 | public class TokenOptions 8 | { 9 | public string Audience { get; set; } 10 | public string Issuer { get; set; } 11 | public int AccessTokenExpiration { get; set; } 12 | public string SecurityKey { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Abstract/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 | 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICarDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq.Expressions; 7 | using System.Text; 8 | 9 | namespace DataAccess.Abstract 10 | { 11 | public interface ICarDal : IEntityRepository 12 | { 13 | 14 | List GetCarDetails(Expression> filter = null); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /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 | } 14 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICreditCardDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface ICreditCardDal : IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICustomerDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface ICustomerDal : IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IRentalDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq.Expressions; 7 | using System.Text; 8 | 9 | namespace DataAccess.Abstract 10 | { 11 | public interface IRentalDal : IEntityRepository 12 | { 13 | List GetCarDetails(Expression> filter = null); 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IUserDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Core.Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface IUserDal : IEntityRepository 10 | { 11 | List GetClaims(User user); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/Context/RentACarContext.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.Linq.Expressions; 7 | using System.Text; 8 | 9 | namespace DataAccess.Concrete.EntityFramework.Context 10 | { 11 | public class RentACarContext : DbContext 12 | { 13 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 14 | { 15 | optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb; Database=RentACar; Trusted_Connection = true"); 16 | } 17 | 18 | public DbSet Cars { get; set; } 19 | public DbSet Brands { get; set; } 20 | public DbSet Colors { get; set; } 21 | public DbSet Users { get; set; } 22 | public DbSet Customers { get; set; } 23 | public DbSet Rentals { get; set; } 24 | public DbSet CarImages { get; set; } 25 | public DbSet OperationClaims { get; set; } 26 | public DbSet UserOperationClaims { get; set; } 27 | public DbSet CreditCards { get; set; } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/Repository/EfBrandDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using DataAccess.Concrete.EntityFramework.Context; 4 | using Entities.Concrete; 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.Repository 13 | { 14 | public class EfBrandDal : EfEntityRepositoryBase, IBrandDal 15 | { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/Repository/EfCarDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using DataAccess.Concrete.EntityFramework.Context; 4 | using Entities.Concrete; 5 | using Entities.DTOs; 6 | using Microsoft.EntityFrameworkCore; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using System.Linq.Expressions; 11 | using System.Text; 12 | 13 | namespace DataAccess.Concrete.EntityFramework.Repository 14 | { 15 | public class EfCarDal : EfEntityRepositoryBase, ICarDal 16 | { 17 | public List GetCarDetails(Expression> filter = null) 18 | { 19 | using (RentACarContext context = new RentACarContext()) 20 | { 21 | var result = from c in filter == null ? context.Cars : context.Cars.Where(filter) 22 | join co in context.Colors 23 | on c.ColorId equals co.Id 24 | join b in context.Brands 25 | on c.BrandId equals b.Id 26 | join ci in context.CarImages 27 | on c.Id equals ci.CarId 28 | select new CarDetailDto 29 | { 30 | CarId = c.Id, 31 | BrandName = b.BrandName, 32 | ColorName = co.ColorName, 33 | DailyPrice = c.DailyPrice, 34 | Descriptions = c.Descriptions, 35 | ModelYear = c.ModelYear, 36 | CarImageDate = ci.CarImageDate, 37 | ImagePath = ci.ImagePath 38 | }; 39 | return result.ToList(); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/Repository/EfCarImageDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using DataAccess.Concrete.EntityFramework.Context; 4 | using Entities.Concrete; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace DataAccess.Concrete.EntityFramework.Repository 10 | { 11 | public class EfCarImageDal : EfEntityRepositoryBase, ICarImageDal 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/Repository/EfColorDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using DataAccess.Concrete.EntityFramework.Context; 4 | using Entities.Concrete; 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.Repository 13 | { 14 | public class EfColorDal : EfEntityRepositoryBase, IColorDal 15 | { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/Repository/EfCreditCardDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using DataAccess.Concrete.EntityFramework.Context; 4 | using Entities.Concrete; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace DataAccess.Concrete.EntityFramework.Repository 10 | { 11 | public class EfCreditCardDal : EfEntityRepositoryBase, ICreditCardDal 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/Repository/EfCustomerDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using DataAccess.Concrete.EntityFramework.Context; 4 | using Entities.Concrete; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace DataAccess.Concrete.EntityFramework.Repository 10 | { 11 | public class EfCustomerDal : EfEntityRepositoryBase, ICustomerDal 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/Repository/EfRentalDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using DataAccess.Concrete.EntityFramework.Context; 4 | using Entities.Concrete; 5 | using Entities.DTOs; 6 | using System; 7 | using System.Linq; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | using System.Linq.Expressions; 11 | 12 | namespace DataAccess.Concrete.EntityFramework.Repository 13 | { 14 | public class EfRentalDal : EfEntityRepositoryBase, IRentalDal 15 | { 16 | public List GetCarDetails(Expression> filter = null) 17 | { 18 | using (RentACarContext context = new RentACarContext()) 19 | { 20 | var result = from r in filter == null ? context.Rentals : context.Rentals.Where(filter) 21 | join c in context.Cars 22 | on r.CarId equals c.Id 23 | join cu in context.Customers 24 | on r.CustomerId equals cu.Id 25 | join b in context.Brands 26 | on c.BrandId equals b.Id 27 | join u in context.Users 28 | on cu.UserId equals u.Id 29 | select new RentalDetailDto 30 | { 31 | RentalId = r.Id, 32 | CarName = b.BrandName, 33 | CustomerName = u.FirstName + " " + u.LastName, 34 | UserName = u.FirstName + " " + u.LastName, 35 | RentDate = r.RentDate, 36 | ReturnDate = r.ReturnDate, 37 | TotalPrice = Convert.ToDecimal(r.ReturnDate.Value.Day - r.RentDate.Day) * c.DailyPrice 38 | }; 39 | return result.ToList(); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/Repository/EfUserDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using Core.Entities.Concrete; 3 | using DataAccess.Abstract; 4 | using DataAccess.Concrete.EntityFramework.Context; 5 | using Entities.Concrete; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | using System.Linq; 10 | 11 | namespace DataAccess.Concrete.EntityFramework.Repository 12 | { 13 | public class EfUserDal : EfEntityRepositoryBase, IUserDal 14 | { 15 | public List GetClaims(User user) 16 | { 17 | using (var context = new RentACarContext()) 18 | { 19 | var result = from operationClaim in context.OperationClaims 20 | join userOperationClaim in context.UserOperationClaims 21 | on operationClaim.Id equals userOperationClaim.OperationClaimId 22 | where userOperationClaim.UserId == user.Id 23 | select new OperationClaim { Id = operationClaim.Id, Name = operationClaim.Name }; 24 | return result.ToList(); 25 | 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /DataAccess/Concrete/InMemory/InMemoryBrandDal.cs: -------------------------------------------------------------------------------- 1 | using DataAccess.Abstract; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.InMemory 9 | { 10 | //public class InMemoryBrandDal : IBrandDal 11 | public class InMemoryBrandDal 12 | { 13 | //List _brands; 14 | 15 | //public InMemoryBrandDal() 16 | //{ 17 | // _brands = new List() 18 | // { 19 | // new Brand(){ Id = 1, BrandName = "Mercedes"}, 20 | // new Brand(){ Id = 2, BrandName = "BMW"}, 21 | // new Brand(){ Id = 3, BrandName = "Volvo"}, 22 | // }; 23 | //} 24 | 25 | //public void Add(Brand entity) 26 | //{ 27 | // _brands.Add(entity); 28 | //} 29 | 30 | //public void Delete(int id) 31 | //{ 32 | // var brandToDelete = _brands.SingleOrDefault(b => b.Id == id); 33 | // _brands.Remove(brandToDelete); 34 | //} 35 | 36 | //public List GetAll() 37 | //{ 38 | // return _brands; 39 | //} 40 | 41 | //public void Update(Brand entity) 42 | //{ 43 | // var brandToUpdate = _brands.SingleOrDefault(b => b.Id == entity.Id); 44 | // brandToUpdate.BrandName = entity.BrandName; 45 | //} 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /DataAccess/Concrete/InMemory/InMemoryCarDal.cs: -------------------------------------------------------------------------------- 1 | using DataAccess.Abstract; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.InMemory 9 | { 10 | //public class InMemoryCarDal : ICarDal 11 | public class InMemoryCarDal 12 | { 13 | //List _cars; 14 | 15 | //public InMemoryCarDal() 16 | //{ 17 | // _cars = new List() 18 | // { 19 | // new Car{Id= 1, BrandId = 1, ColorId = 1, DailyPrice = 200, ModelYear = "2012", Descriptions = "Otomatik Dizel" }, 20 | // new Car{Id= 2, BrandId = 2, ColorId = 2, DailyPrice = 50, ModelYear = "2010", Descriptions = "Manuel Benzin" }, 21 | // new Car{Id= 3, BrandId = 2, ColorId = 1, DailyPrice = 100, ModelYear = "2019", Descriptions = "Manuel Dizel" }, 22 | // new Car{Id= 4, BrandId = 3, ColorId = 2, DailyPrice = 150, ModelYear = "2018", Descriptions = "Otomatik Benzin" }, 23 | // }; 24 | //} 25 | 26 | //public void Add(Car car) 27 | //{ 28 | // _cars.Add(car); 29 | //} 30 | 31 | //public void Delete(int id) 32 | //{ 33 | // Car carToDelete = _cars.SingleOrDefault(c => c.Id == id); 34 | // _cars.Remove(carToDelete); 35 | //} 36 | 37 | //public List GetAll() 38 | //{ 39 | // return _cars; 40 | //} 41 | 42 | //public List GetAllByBrand(int brandId) 43 | //{ 44 | // return _cars.Where(c => c.BrandId == brandId).ToList(); 45 | //} 46 | 47 | //public List GetAllByColor(int colorId) 48 | //{ 49 | // return _cars.Where(c => c.ColorId == colorId).ToList(); 50 | //} 51 | 52 | //public Car GetById(int id) 53 | //{ 54 | // return _cars.SingleOrDefault(c => c.Id == id); 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.DailyPrice = car.DailyPrice; 63 | // carToUpdate.ModelYear = car.ModelYear; 64 | // carToUpdate.Descriptions = car.Descriptions; 65 | //} 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /DataAccess/Concrete/InMemory/InMemoryColorDal.cs: -------------------------------------------------------------------------------- 1 | using DataAccess.Abstract; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.InMemory 9 | { 10 | //public class InMemoryColorDal : IColorDal 11 | public class InMemoryColorDal 12 | { 13 | //List _colors; 14 | 15 | //public InMemoryColorDal() 16 | //{ 17 | // _colors = new List() 18 | // { 19 | // new Color(){ Id = 1, ColorName = "Siyah"}, 20 | // new Color(){ Id = 2, ColorName = "Beyaz"}, 21 | // new Color(){ Id = 3, ColorName = "Mavi"}, 22 | // }; 23 | //} 24 | 25 | //public void Add(Color entity) 26 | //{ 27 | // _colors.Add(entity); 28 | //} 29 | 30 | //public void Delete(int id) 31 | //{ 32 | // var colorToDelete = _colors.SingleOrDefault(b => b.Id == id); 33 | // _colors.Remove(colorToDelete); 34 | //} 35 | 36 | //public List GetAll() 37 | //{ 38 | // return _colors; 39 | //} 40 | 41 | //public void Update(Color entity) 42 | //{ 43 | // var colorToUpdate = _colors.SingleOrDefault(b => b.Id == entity.Id); 44 | // colorToUpdate.ColorName = entity.ColorName; 45 | //} 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /DataAccess/DataAccess.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Entities/Concrete/Brand.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Brand : IEntity 9 | { 10 | public int Id { 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 string ModelYear { get; set; } 12 | public decimal DailyPrice { get; set; } 13 | public string Descriptions { get; set; } 14 | public int BrandId { get; set; } 15 | public int ColorId { 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 DateTime CarImageDate { get; set; } 13 | public string ImagePath { 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 Id { get; set; } 11 | public string ColorName { get; set; } 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Entities/Concrete/CreditCard.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class CreditCard : IEntity 9 | { 10 | public int Id { get; set; } 11 | public int UserId { get; set; } 12 | public string CardNumber { get; set; } 13 | public string FullName { get; set; } 14 | public string Ccv { get; set; } 15 | public string ExpirationMonth { get; set; } 16 | public string ExpirationYear { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Entities/Concrete/Customer.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Customer : IEntity 9 | { 10 | public int Id { get; set; } 11 | public int UserId { get; set; } 12 | public string CustomerName { 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 Id { get; set; } 11 | public int CarId { get; set; } 12 | public int CustomerId { get; set; } 13 | public DateTime RentDate { get; set; } 14 | public DateTime? ReturnDate { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Entities/DTOs/CarDetailDto.cs: -------------------------------------------------------------------------------- 1 | using Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class CarDetailDto : IDto 9 | { 10 | public int CarId { get; set; } 11 | public string BrandName { get; set; } 12 | public string ColorName { get; set; } 13 | public decimal DailyPrice { get; set; } 14 | public string ModelYear { get; set; } 15 | public string Descriptions { get; set; } 16 | 17 | public DateTime CarImageDate { get; set; } 18 | public string ImagePath { get; set; } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Entities/DTOs/RentalDetailDto.cs: -------------------------------------------------------------------------------- 1 | using Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class RentalDetailDto : IDto 9 | { 10 | public int RentalId { get; set; } 11 | public string CarName { get; set; } 12 | public string UserName { get; set; } 13 | public string CustomerName { get; set; } 14 | public DateTime RentDate { get; set; } 15 | public DateTime? ReturnDate { get; set; } 16 | 17 | public decimal TotalPrice { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Entities/DTOs/UserForLoginDto.cs: -------------------------------------------------------------------------------- 1 | using Core; 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; 2 | 3 | namespace Entities.DTOs 4 | { 5 | public class UserForRegisterDto : IDto 6 | { 7 | public string Email { get; set; } 8 | public string Password { get; set; } 9 | public string FirstName { get; set; } 10 | public string LastName { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Entities/Entities.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | Library 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Selim Gulce 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![GitHub License](https://img.shields.io/github/license/gulceselim/re-cap-project-with-csharp?color=green)](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/LICENSE.txt) 2 | ![GitHub Repo stars](https://img.shields.io/github/stars/gulceselim/re-cap-project-with-csharp?color=yellow) 3 | ![GitHub repo size](https://img.shields.io/github/repo-size/gulceselim/re-cap-project-with-csharp) 4 | 5 |

ReCap Project : Araba Kiralama Sistemi

6 | 7 |

8 | Rent A Car 9 |

10 | 11 | ## ⭐ Introduction 12 | - **Entities, DataAccess, Business, Core ve WebAPI katmanlarından oluşan araba kiralama projesidir. Bu projede Katmanlı mimari yapısı ve SOLID prensiplerine dikkate alınarak yazılmıştır. JWT entegrasyonu; Transaction, Cache, Validation ve Performance aspect'lerinin implementasyonu gerçekleştirilmiştir.** 13 | - **Validation için FluentValidation desteği, IoC için ise Autofac desteği eklenmiştir.** 14 | - **[Sql query](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/RentACarSQLQuery.sql) dosyamı da ekledim isteyen varsa faydalanabilir.** 15 | 16 | 17 | ## Recent Changes 18 | ✔ Caching, Transaction ve Performance aspectleri eklendi.
19 | ✔ CarManager class'ına ait olan GetAll metoduna Logging aspect'i eklendi.
20 | ✔ Car nesnesinin GetAll metodu performance ile test edildi.
21 | ✔ Çalıştırılan metodlar log4net.config ile log.json dosyasına yazıldı.
22 | 23 | ## Table of Contents 24 | - [Recent Changes](#recent-changes) 25 | - [Installation](#installation) 26 | - [Usage](#usage) 27 | - [Layers](#layers) 28 | - [SQL Query](#sql-query) 29 | - [Tables in Database](#tables-in-database) 30 | - [Output](#output) 31 | - [Files](#files) 32 | - [License](#license) 33 | 34 | 35 | ## Installation 36 | ```bash 37 | # Clone to repository 38 | $ git clone https://github.com/gulceselim/re-cap-project-with-csharp.git 39 | 40 | # Go to the folder you cloned 41 | $ cd re-cap-project-with-csharp 42 | 43 | # Install dependencies 44 | $ dotnet restore 45 | ``` 46 | 47 | ## Usage 48 | Aşağıda görmüş olduğunuz resimdeki işlemi gerçekleştirdikten sonra Ctrl+F5 ile uygulamayı çalıştırabilirsiniz. Daha sonrasında Postman uygulaması aracılığıyla projeye isteklerde bulunabilirsiniz. 49 | 50 | ![Image for Usage](https://user-images.githubusercontent.com/43720773/110237438-28e15f00-7f4d-11eb-9305-4c9257a06e72.jpg) 51 | 52 | 53 | ## Layers 54 | 🗃 **``Entities Layer``**
55 |     📂 ``Concrete``
56 |          📃 [Brand.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Entities/Concrete/Brand.cs)
57 |          📃 [Car.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Entities/Concrete/Car.cs)
58 |          📃 [CarImage.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Entities/Concrete/CarImage.cs)
59 |          📃 [Color.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Entities/Concrete/Color.cs)
60 |          📃 [CreditCard.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Entities/Concrete/CreditCard.cs)
61 |          📃 [Customer.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Entities/Concrete/Customer.cs)
62 |          📃 [Rental.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Entities/Concrete/Rental.cs)
63 | 64 |     📂 ``DTOs``
65 |          📃 [CarDetailDto.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Entities/DTOs/CarDetailDto.cs)
66 |          📃 [RentalDetailDto.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Entities/DTOs/RentalDetailDto.cs)
67 |          📃 [UserForLoginDto.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Entities/DTOs/UserForLoginDto.cs)
68 |          📃 [UserForRegisterDto.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Entities/DTOs/UserForRegisterDto.cs)

69 | 70 | 🗃 **``Business Layer``**
71 |      📂 ``Abstract``
72 |          📃 [IAuthService.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Abstract/IAuthService.cs)
73 |          📃 [IBrandService.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Abstract/IBrandService.cs)
74 |          📃 [ICarImageService.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Abstract/ICarImageService.cs)
75 |          📃 [ICarService.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Abstract/ICarService.cs)
76 |          📃 [IColorService.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Abstract/IColorService.cs)
77 |          📃 [ICreditCardService.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Abstract/ICreditCardService.cs)
78 |          📃 [ICustomerService.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Abstract/ICustomerService.cs)
79 |          📃 [IRentalService.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Abstract/IRentalService.cs)
80 |          📃 [IUserService.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Abstract/IUserService.cs)
81 | 82 |     📂 ``BusinessAspect``
83 |         📂 ``Autofac``
84 |              📃 [SecuredOperation.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/BusinessAspect/Autofac/SecuredOperation.cs)
85 | 86 |     📂 ``Concrete``
87 |          📃 [AuthManager.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Concrete/AuthManager.cs)
88 |          📃 [BrandManager.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Concrete/BrandManager.cs)
89 |          📃 [CarImageManager.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Concrete/CarImageManager.cs)
90 |          📃 [CarManager.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Concrete/CarManager.cs)
91 |          📃 [ColorManager.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Concrete/ColorManager.cs)
92 |          📃 [CreditCardManager.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Concrete/CreditCardManager.cs)
93 |          📃 [CustomerManager.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Concrete/CustomerManager.cs)
94 |          📃 [RentalManager.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Concrete/RentalManager.cs)
95 |          📃 [UserManager.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Concrete/UserManager.cs)
96 | 97 |      📂 ``Constants``
98 |          📃 [Messages.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/Constants/Messages.cs)
99 | 100 |      📂 ``DependencyResolvers``
101 |          📂 ``Autofac``
102 |              📃 [AutofacBusinessModule.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/DependencyResolvers/Autofac/AutofacBusinessModule.cs)
103 | 104 |      📂 ``ValidationRules``
105 |          📂 ``FluentValidation``
106 |              📃 [BrandValidator.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/ValidationRules/FluentValidation/BrandValidator.cs)
107 |              📃 [CarValidator.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/ValidationRules/FluentValidation/CarValidator.cs)
108 |              📃 [ColorValidator.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/ValidationRules/FluentValidation/ColorValidator.cs)
109 |              📃 [CustomerValidator.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/ValidationRules/FluentValidation/CustomerValidator.cs)
110 |              📃 [RentalValidator.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/ValidationRules/FluentValidation/RentalValidator.cs)
111 |              📃 [UserValidator.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Business/ValidationRules/FluentValidation/UserValidator.cs)

112 | 113 | 114 | 🗃 **``Data Access Layer``**
115 |     📂 ``Abstract``
116 |          📃 [IBrandDal.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/DataAccess/Abstract/IBrandDal.cs)
117 |          📃 [ICarImageDal.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/DataAccess/Abstract/ICarImageDal.cs)
118 |          📃 [ICarDal.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/DataAccess/Abstract/ICarDal.cs)
119 |          📃 [IColorDal.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/DataAccess/Abstract/IColorDal.cs)
120 |          📃 [ICreditCardDal.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/DataAccess/Abstract/ICreditCardDal.cs)
121 |          📃 [ICustomerDal.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/DataAccess/Abstract/ICustomerDal.cs)
122 |          📃 [IRentalDal.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/DataAccess/Abstract/IRentalDal.cs)
123 |          📃 [IUserDal.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/DataAccess/Abstract/IUserDal.cs)
124 | 125 |      📂 ``Concrete``
126 |          📂 ``EntityFramework``
127 |              📂 ``Context``
128 |                  📃 [RentACarContext.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/DataAccess/Concrete/EntityFramework/Context/RentACarContext.cs)
129 |              📂 ``Repository``
130 |                  📃 [EfBrandDal.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/DataAccess/Concrete/EntityFramework/Repository/EfBrandDal.cs)
131 |                  📃 [EfCarImageDal.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/DataAccess/Concrete/EntityFramework/Repository/EfCarImageDal.cs)
132 |                  📃 [EfCarDal.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/DataAccess/Concrete/EntityFramework/Repository/EfCarDal.cs)
133 |                  📃 [EfColorDal.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/DataAccess/Concrete/EntityFramework/Repository/EfColorDal.cs)
134 |                  📃 [EfCreditCardDal.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/DataAccess/Concrete/EntityFramework/Repository/EfColorDal.cs)
135 |                  📃 [EfCustomerDal.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/DataAccess/Concrete/EntityFramework/Repository/EfCustomerDal.cs)
136 |                  📃 [EfRentalDal.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/DataAccess/Concrete/EntityFramework/Repository/EfRentalDal.cs)
137 |                  📃 [EfUserDal.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/DataAccess/Concrete/EntityFramework/Repository/EfUserDal.cs)

138 | 139 | 140 | 🗃 **``Core Layer``**
141 |     📂 ``Aspect``
142 |         📂 ``Autofac``
143 |             📂 ``Caching``
144 |                  📃 [CacheAspect.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Aspects/Autofac/Caching/CacheAspect.cs)
145 |                  📃 [CacheRemoveAspect.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Aspects/Autofac/Caching/CacheRemoveAspect.cs)
146 |             📂 ``Expection``
147 |                  📃 [ExceptionLogAspect.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Aspects/Autofac/Expection/ExceptionLogAspect.cs)
148 |             📂 ``Logging``
149 |                  📃 [LogAspect.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Aspects/Autofac/Logging/LogAspect.cs)
150 |             📂 ``Performance``
151 |                  📃 [PerformanceAspect.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Aspects/Autofac/Performance/PerformanceAspect.cs)
152 |             📂 ``Transaction``
153 |                  📃 [TransactionScopeAscpect.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Aspects/Autofac/Transaction/TransactionScopeAscpect.cs)
154 |             📂 ``Validation``
155 |                  📃 [ValidationAspect.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Aspects/Autofac/Validation/ValidationAspect.cs)
156 | 157 |     📂 ``CrossCuttingConcerns``
158 |         📂 ``Caching``
159 |             📃 [ICacheManager.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/CrossCuttingConcerns/Caching/ICacheManager.cs)
160 |             📂 ``Microsoft``
161 |                 📃 [MemoryCacheManager.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/CrossCuttingConcerns/Caching/Microsoft/MemoryCacheManager.cs)
162 |         📂 ``Logging``
163 |             📃 [LogDetail.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/CrossCuttingConcerns/Logging/LogDetail.cs)
164 |             📃 [LogDetailWithException.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/CrossCuttingConcerns/Logging/LogDetailWithException.cs)
165 |             📃 [LogParameter.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/CrossCuttingConcerns/Logging/LogParameter.cs)
166 |             📂 ``Log4Net``
167 |                 📃 [LoggerServiceBase.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/CrossCuttingConcerns/Logging/Log4Net/LoggerServiceBase.cs)
168 |                 📃 [SerializableLogEvent.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/CrossCuttingConcerns/Logging/Log4Net/SerializableLogEvent.cs)
169 |                 📂 ``Layouts``
170 |                     📃 [JsonLayout.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/CrossCuttingConcerns/Logging/Log4Net/Layouts/JsonLayout.cs)
171 |                 📂 ``Loggers``
172 |                     📃 [FileLogger.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/CrossCuttingConcerns/Logging/Log4Net/Loggers/FileLogger.cs)
173 |         📂 ``Validation``
174 |             📃 [ValidationTool.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/CrossCuttingConcerns/Validation/ValidationTool.cs)
175 | 176 |     📂 ``DataAccess``
177 |          📃 [IEntityRepository.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/DataAccess/IEntityRepository.cs)
178 |         📂 ``EntityFramework``
179 |              📃 [EfEntityRepositoryBase.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/DataAccess/EntityFramework/EfEntityRepositoryBase.cs)
180 | 181 |     📂 ``DependencyResolvers``
182 |          📃 [CoreModule.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/DependencyResolvers/CoreModule.cs)
183 | 184 |     📂 ``Entities``
185 |          📃 [IDto.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Entities/IDto.cs)
186 |          📃 [IEntity.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Entities/IEntity.cs)
187 |         📂 ``Concrete``
188 |              📃 [OperationClaim.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Entities/Concrete/OperationClaim.cs)
189 |              📃 [User.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Entities/Concrete/User.cs)
190 |              📃 [UserOperationClaim.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Entities/Concrete/UserOperationClaim.cs)
191 | 192 |     📂 ``Extensions``
193 |          📃 [ClaimExtensions.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Extensions/ClaimExtensions.cs)
194 |          📃 [ClaimsPrincipalExtensions.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Extensions/ClaimsPrincipalExtensions.cs)
195 |          📃 [ErrorDetails.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Extensions/ErrorDetails.cs)
196 |          📃 [ExceptionMiddleware.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Extensions/ExceptionMiddleware.cs)
197 |          📃 [ExceptionMiddlewareExtensions.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Extensions/ExceptionMiddlewareExtensions.cs)
198 |          📃 [ServiceCollectionExtensions.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Extensions/ServiceCollectionExtensions.cs)
199 | 200 |     📂 ``Utilities``
201 |         📂 ``Business``
202 |              📃 [BusinessRules.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Business/BusinessRules.cs)
203 |         📂 ``Helpers``
204 |              📃 [FileHelper.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Helpers/FileHelper.cs)
205 |         📂 ``Interceptors``
206 |              📃 [AspectInterceptorSelector.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Interceptors/AspectInterceptorSelector.cs)
207 |              📃 [MethodInterception.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Interceptors/MethodInterception.cs)
208 |              📃 [MethodInterceptionBaseAttribute.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Interceptors/MethodInterceptionBaseAttribute.cs)
209 |         📂 ``IoC``
210 |              📃 [ICoreModule.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/IoC/ICoreModule.cs)
211 |              📃 [ServiceTool.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/IoC/ServiceTool.cs)
212 |         📂 ``Messages``
213 |              📃 [AspectMessages.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Messages/AspectMessages.cs)
214 |         📂 ``Results``
215 |              📃 [IDataResult.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Results/IDataResult.cs)
216 |              📃 [DataResult.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Results/DataResult.cs)
217 |              📃 [SuccessDataResult.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Results/SuccessDataResult.cs)
218 |              📃 [ErrorDataResult.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Results/ErrorDataResult.cs)
219 |              📃 [IResult.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Results/IResult.cs)
220 |              📃 [Result.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Results/Result.cs)
221 |              📃 [SuccessResult.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Results/SuccessResult.cs)
222 |              📃 [ErrorResult.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Results/ErrorResult.cs)
223 |         📂 ``Security``
224 |             📂 ``Encryption``
225 |                  📃 [SecurityKeyHelper.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Security/Encryption/ErrorResult.cs)
226 |                  📃 [SigningCredentialsHelper.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Security/Encryption/ErrorResult.cs)
227 |             📂 ``Hashing``
228 |                  📃 [HashingHelper.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Security/Hashing/HashingHelper.cs)
229 |             📂 ``JWT``
230 |                  📃 [AccessToken.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Security/JWT/AccessToken.cs)
231 |                  📃 [ITokenHelper.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Security/JWT/ITokenHelper.cs)
232 |                  📃 [JwtHelper.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Security/JWT/JwtHelper.cs)
233 |                  📃 [TokenOptions.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/Core/Utilities/Security/JWT/TokenOptions.cs)

234 | 235 | 🗃 **``Presentation Layer``**
236 |      📃 [Program.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/ConsoleUI/Program.cs)

237 | 238 | 🗃 **``WebAPI Layer``**
239 |     📃 [Startup.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/WebAPI/Startup.cs)
240 |     📂 ``Controllers``
241 |          📃 [AuthController.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/WebAPI/Controllers/AuthController.cs)
242 |          📃 [BrandsController.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/WebAPI/Controllers/BrandsController.cs)
243 |          📃 [CarImagesController.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/WebAPI/Controllers/CarImagesController.cs)
244 |          📃 [CarsController.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/WebAPI/Controllers/CarsController.cs)
245 |          📃 [ColorsController.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/WebAPI/Controllers/ColorsController.cs)
246 |          📃 [CreditCardsController.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/WebAPI/Controllers/CreditCardsController.cs)
247 |          📃 [CustomersController.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/WebAPI/Controllers/CustomersController.cs)
248 |          📃 [RentalsController.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/WebAPI/Controllers/RentalsController.cs)
249 |          📃 [UsersController.cs](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/WebAPI/Controllers/UsersController.cs)

250 | 251 | ## SQL Query 252 |      📃 [RentACarSQLQuery.sql](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/RentACarSQLQuery.sql) 253 | 254 | 255 | ## Tables in Database 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 278 | 288 | 301 | 309 | 319 | 328 | 339 | 348 | 361 | 362 |
BrandsCarImagesCarsColorsCustomersOperationClaimsRentalsUserOperationClaimsUsers
270 | 271 | Variable Name | Data Type 272 | ------------ | ------------- 273 | Id | INT 274 | BrandName | NVARCHAR(25) 275 | 276 | 277 | 279 | 280 | Variable Name | Data Type 281 | ------------ | ------------- 282 | Id | INT 283 | CarId | INT 284 | CarImagesDate | DATETIME 285 | ImagePath | NVARCHAR(MAX) 286 | 287 | 289 | 290 | Variable Name | Data Type 291 | ------------ | ------------- 292 | Id | INT 293 | BrandId | INT 294 | ColorId | INT 295 | ModelYear | NVARCHAR(25) 296 | DailyPrice | DECIMAL 297 | Description | NVARCHAR(25) 298 | 299 | 300 | 302 | 303 | Variable Name | Data Type 304 | ------------ | ------------- 305 | Id | INT 306 | ColorName | NVARCHAR(25) 307 | 308 | 310 | 311 | 312 | Variable Name | Data Type 313 | ------------ | ------------- 314 | Id | INT 315 | UserId | INT 316 | CustomerName | NVARCHAR(25) 317 | 318 | 320 | 321 | 322 | Variable Name | Data Type 323 | ------------ | ------------- 324 | Id | INT 325 | Name | VARCHAR(250) 326 | 327 | 329 | 330 | Variable Name | Data Type 331 | ------------ | ------------- 332 | Id | INT 333 | CarId | INT 334 | CustomerId | INT 335 | RentDate | DATETIME 336 | ReturnDate | DATETIME 337 | 338 | 340 | 341 | Variable Name | Data Type 342 | ------------ | ------------- 343 | Id | INT 344 | UserId | INT 345 | OperationId | INT 346 | 347 | 349 | 350 | Variable Name | Data Type 351 | ------------ | ------------- 352 | Id | INT 353 | FirstName | VARCHAR(50) 354 | LastName | VARCHAR(50) 355 | Email | VARCHAR(50) 356 | PasswordHash | VARBINARY (500) 357 | PasswordSalt | VARBINARY (500) 358 | Status | BIT 359 | 360 |
363 | 364 | ## Output 365 | Console Output 366 | 367 | 368 | ## Files 369 | 370 | ![business](https://user-images.githubusercontent.com/43720773/114262894-14c8cb80-99eb-11eb-958b-c03af94b6de7.jpg) 371 | 372 | ![core](https://user-images.githubusercontent.com/43720773/114262895-15616200-99eb-11eb-9bdc-2f1ab4c7f1f4.jpg) 373 | 374 | ![core2](https://user-images.githubusercontent.com/43720773/114262896-15f9f880-99eb-11eb-8453-9e150fb0bf05.jpg) 375 | 376 | ![data_access](https://user-images.githubusercontent.com/43720773/114262897-16928f00-99eb-11eb-8b42-ba5340c8c84d.jpg) 377 | 378 | ![entities](https://user-images.githubusercontent.com/43720773/114262898-172b2580-99eb-11eb-9f06-b3ace4d13e07.jpg) 379 | 380 | ![web_api](https://user-images.githubusercontent.com/43720773/114262899-172b2580-99eb-11eb-9707-b7a5492e23d9.jpg) 381 | 382 | 383 | ## License 384 | [MIT © Selim Gülce](https://github.com/gulceselim/re-cap-project-with-csharp/blob/main/LICENSE.txt) 385 | -------------------------------------------------------------------------------- /ReCapProject.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30717.126 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAccess", "DataAccess\DataAccess.csproj", "{0FDB449A-49D9-4877-96D2-F500ACA2D4FE}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Business", "Business\Business.csproj", "{41E31728-8063-4028-9D5D-CC2C28A104A8}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "Entities\Entities.csproj", "{AB01EFC2-FD9A-487B-AD81-0CF0A646FCEB}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleUI", "ConsoleUI\ConsoleUI.csproj", "{4CA6DD34-4BF6-4D37-AAF8-7AD96F168411}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{B043DE4B-A20B-4236-877D-DB4D6471555E}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPI", "WebAPI\WebAPI.csproj", "{B105AF2B-43E9-42D7-AF90-74E367359567}" 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 | {0FDB449A-49D9-4877-96D2-F500ACA2D4FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {0FDB449A-49D9-4877-96D2-F500ACA2D4FE}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {0FDB449A-49D9-4877-96D2-F500ACA2D4FE}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {0FDB449A-49D9-4877-96D2-F500ACA2D4FE}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {41E31728-8063-4028-9D5D-CC2C28A104A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {41E31728-8063-4028-9D5D-CC2C28A104A8}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {41E31728-8063-4028-9D5D-CC2C28A104A8}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {41E31728-8063-4028-9D5D-CC2C28A104A8}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {AB01EFC2-FD9A-487B-AD81-0CF0A646FCEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {AB01EFC2-FD9A-487B-AD81-0CF0A646FCEB}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {AB01EFC2-FD9A-487B-AD81-0CF0A646FCEB}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {AB01EFC2-FD9A-487B-AD81-0CF0A646FCEB}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {4CA6DD34-4BF6-4D37-AAF8-7AD96F168411}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {4CA6DD34-4BF6-4D37-AAF8-7AD96F168411}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {4CA6DD34-4BF6-4D37-AAF8-7AD96F168411}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {4CA6DD34-4BF6-4D37-AAF8-7AD96F168411}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {B043DE4B-A20B-4236-877D-DB4D6471555E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {B043DE4B-A20B-4236-877D-DB4D6471555E}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {B043DE4B-A20B-4236-877D-DB4D6471555E}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {B043DE4B-A20B-4236-877D-DB4D6471555E}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {B105AF2B-43E9-42D7-AF90-74E367359567}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {B105AF2B-43E9-42D7-AF90-74E367359567}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {B105AF2B-43E9-42D7-AF90-74E367359567}.Release|Any CPU.ActiveCfg = Release|Any CPU 47 | {B105AF2B-43E9-42D7-AF90-74E367359567}.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 = {0B1C474B-41AF-4D3A-9732-813899B8799B} 54 | EndGlobalSection 55 | EndGlobal 56 | -------------------------------------------------------------------------------- /RentACarSQLQuery.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [dbo].[Brands] ( 2 | [Id] INT IDENTITY (1, 1) NOT NULL, 3 | [BrandName] NVARCHAR (25) NULL, 4 | PRIMARY KEY CLUSTERED ([Id] ASC) 5 | ); 6 | 7 | CREATE TABLE [dbo].[CarImages] ( 8 | [Id] INT IDENTITY (1, 1) NOT NULL, 9 | [CarId] INT NULL, 10 | [ImagePath] NVARCHAR (MAX) NULL, 11 | [CarImageDate] DATETIME NULL, 12 | PRIMARY KEY CLUSTERED ([Id] ASC), 13 | FOREIGN KEY ([CarId]) REFERENCES [dbo].[Cars] ([Id]) 14 | ); 15 | 16 | CREATE TABLE [dbo].[Cars] ( 17 | [Id] INT IDENTITY (1, 1) NOT NULL, 18 | [BrandId] INT NULL, 19 | [ColorId] INT NULL, 20 | [ModelYear] NVARCHAR (25) NULL, 21 | [DailyPrice] DECIMAL (18) NULL, 22 | [Descriptions] NVARCHAR (25) NULL, 23 | PRIMARY KEY CLUSTERED ([Id] ASC), 24 | FOREIGN KEY ([ColorId]) REFERENCES [dbo].[Colors] ([Id]), 25 | FOREIGN KEY ([BrandId]) REFERENCES [dbo].[Brands] ([Id]) 26 | ); 27 | 28 | CREATE TABLE [dbo].[Colors] ( 29 | [Id] INT IDENTITY (1, 1) NOT NULL, 30 | [ColorName] NVARCHAR (25) NULL, 31 | PRIMARY KEY CLUSTERED ([Id] ASC) 32 | ); 33 | 34 | CREATE TABLE [dbo].[Customers] ( 35 | [Id] INT IDENTITY (1, 1) NOT NULL, 36 | [UserId] INT NULL, 37 | [CustomerName] NVARCHAR (25) NULL, 38 | PRIMARY KEY CLUSTERED ([Id] ASC), 39 | FOREIGN KEY ([UserId]) REFERENCES [dbo].[Users] ([Id]) 40 | ); 41 | 42 | CREATE TABLE [dbo].[OperationClaims] ( 43 | [Id] INT IDENTITY (1, 1) NOT NULL, 44 | [Name] VARCHAR (250) NOT NULL, 45 | PRIMARY KEY CLUSTERED ([Id] ASC) 46 | ); 47 | 48 | CREATE TABLE [dbo].[Rentals] ( 49 | [Id] INT IDENTITY (1, 1) NOT NULL, 50 | [CarId] INT NULL, 51 | [CustomerID] INT NULL, 52 | [RentDate] DATETIME NULL, 53 | [ReturnDate] DATETIME NULL, 54 | PRIMARY KEY CLUSTERED ([Id] ASC), 55 | FOREIGN KEY ([CarId]) REFERENCES [dbo].[Cars] ([Id]), 56 | FOREIGN KEY ([CustomerID]) REFERENCES [dbo].[Customers] ([Id]) 57 | ); 58 | 59 | CREATE TABLE [dbo].[UserOperationClaims] ( 60 | [Id] INT IDENTITY (1, 1) NOT NULL, 61 | [UserId] INT NOT NULL, 62 | [OperationClaimId] INT NOT NULL, 63 | PRIMARY KEY CLUSTERED ([Id] ASC) 64 | ); 65 | 66 | CREATE TABLE [dbo].[Users] ( 67 | [Id] INT IDENTITY (1, 1) NOT NULL, 68 | [FirstName] VARCHAR (50) NOT NULL, 69 | [LastName] VARCHAR (50) NOT NULL, 70 | [Email] VARCHAR (50) NOT NULL, 71 | [PasswordHash] VARBINARY (500) NOT NULL, 72 | [PasswordSalt] VARBINARY (500) NOT NULL, 73 | [Status] BIT NOT NULL, 74 | PRIMARY KEY CLUSTERED ([Id] ASC) 75 | ); 76 | 77 | 78 | 79 | INSERT INTO Cars(BrandId,ColorId,ModelYear,DailyPrice,Descriptions) 80 | VALUES 81 | ('1','2','2012','100','Manuel Benzin'), 82 | ('1','3','2015','150','Otomatik Dizel'), 83 | ('2','1','2017','200','Otomatik Hybrid'), 84 | ('3','3','2014','125','Manuel Dizel'); 85 | 86 | INSERT INTO Colors(ColorName) 87 | VALUES 88 | ('Beyaz'), 89 | ('Siyah'), 90 | ('Mavi'); 91 | 92 | 93 | INSERT INTO Brands(BrandName) 94 | VALUES 95 | ('Tesla'), 96 | ('BMW'), 97 | ('Renault'); 98 | 99 | -------------------------------------------------------------------------------- /WebAPI/Controllers/AuthController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.DTOs; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class AuthController : Controller 15 | { 16 | private IAuthService _authService; 17 | 18 | public AuthController(IAuthService authService) 19 | { 20 | _authService = authService; 21 | } 22 | 23 | [HttpPost("login")] 24 | public ActionResult Login(UserForLoginDto userForLoginDto) 25 | { 26 | var userToLogin = _authService.Login(userForLoginDto); 27 | if (!userToLogin.Success) 28 | { 29 | return BadRequest(userToLogin.Message); 30 | } 31 | 32 | var result = _authService.CreateAccessToken(userToLogin.Data); 33 | if (result.Success) 34 | { 35 | return Ok(result); 36 | } 37 | 38 | return BadRequest(result.Message); 39 | } 40 | 41 | [HttpPost("register")] 42 | public ActionResult Register(UserForRegisterDto userForRegisterDto) 43 | { 44 | var userExists = _authService.UserExists(userForRegisterDto.Email); 45 | if (!userExists.Success) 46 | { 47 | return BadRequest(userExists.Message); 48 | } 49 | 50 | var registerResult = _authService.Register(userForRegisterDto, userForRegisterDto.Password); 51 | var result = _authService.CreateAccessToken(registerResult.Data); 52 | if (result.Success) 53 | { 54 | return Ok(result.Data); 55 | } 56 | 57 | return BadRequest(result.Message); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /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 | [HttpPost("add")] 24 | public IActionResult Add(Brand brand) 25 | { 26 | var result = _brandService.Add(brand); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result); 32 | } 33 | 34 | [HttpPost("update")] 35 | public IActionResult Update(Brand brand) 36 | { 37 | var result = _brandService.Update(brand); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result); 43 | } 44 | 45 | [HttpPost("delete")] 46 | public IActionResult Delete(Brand brand) 47 | { 48 | var result = _brandService.Delete(brand); 49 | if (result.Success) 50 | { 51 | return Ok(result); 52 | } 53 | return BadRequest(result); 54 | } 55 | 56 | [HttpGet("getall")] 57 | public IActionResult GetAll() 58 | { 59 | var result = _brandService.GetAll(); 60 | if (result.Success) 61 | { 62 | return Ok(result); 63 | } 64 | return BadRequest(result); 65 | } 66 | 67 | [HttpGet("getbyid")] 68 | public IActionResult GetById(int id) 69 | { 70 | var result = _brandService.GetById(id); 71 | if (result.Success) 72 | { 73 | return Ok(result); 74 | } 75 | return BadRequest(result); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CarImagesController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class CarImagesController : ControllerBase 15 | { 16 | ICarImageService _carImageService; 17 | 18 | public CarImagesController(ICarImageService carImageService) 19 | { 20 | _carImageService = carImageService; 21 | } 22 | 23 | [HttpPost("add")] 24 | public IActionResult Add([FromForm(Name = "Image")] IFormFile file, [FromForm] CarImage carImage) 25 | { 26 | var result = _carImageService.Add(file, carImage); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result); 32 | } 33 | 34 | [HttpPost("update")] 35 | public IActionResult Update([FromForm(Name = "Image")] IFormFile file, [FromForm] CarImage carImage) 36 | { 37 | var result = _carImageService.Update(file, carImage); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result); 43 | } 44 | 45 | [HttpPost("delete")] 46 | public IActionResult Delete(CarImage carImage) 47 | { 48 | var result = _carImageService.Delete(carImage); 49 | if (result.Success) 50 | { 51 | return Ok(result); 52 | } 53 | return BadRequest(result); 54 | } 55 | 56 | 57 | 58 | [HttpGet("getall")] 59 | public IActionResult GetAll() 60 | { 61 | var result = _carImageService.GetAll(); 62 | if (result.Success) 63 | { 64 | return Ok(result); 65 | } 66 | return BadRequest(result); 67 | } 68 | 69 | [HttpGet("getbyid")] 70 | public IActionResult GetById(int id) 71 | { 72 | var result = _carImageService.GetById(id); 73 | if (result.Success) 74 | { 75 | return Ok(result); 76 | } 77 | return BadRequest(result); 78 | } 79 | 80 | [HttpGet("getbycar")] 81 | public IActionResult GetByCar(int id) 82 | { 83 | var result = _carImageService.GetAll(I => I.CarId == id); 84 | if (result.Success) 85 | { 86 | return Ok(result); 87 | } 88 | return BadRequest(result); 89 | } 90 | 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CarsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 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.Linq.Expressions; 10 | using System.Threading.Tasks; 11 | 12 | namespace WebAPI.Controllers 13 | { 14 | [Route("api/[controller]")] 15 | [ApiController] 16 | public class CarsController : ControllerBase 17 | { 18 | ICarService _carService; 19 | 20 | public CarsController(ICarService carService) 21 | { 22 | _carService = carService; 23 | } 24 | 25 | [HttpPost("add")] 26 | public IActionResult Add(Car car) 27 | { 28 | var result = _carService.Add(car); 29 | if (result.Success) 30 | { 31 | return Ok(result); 32 | } 33 | return BadRequest(result); 34 | } 35 | 36 | [HttpPost("update")] 37 | public IActionResult Update(Car car) 38 | { 39 | var result = _carService.Update(car); 40 | if (result.Success) 41 | { 42 | return Ok(result); 43 | } 44 | return BadRequest(result); 45 | } 46 | 47 | [HttpPost("delete")] 48 | public IActionResult Delete(Car car) 49 | { 50 | var result = _carService.Delete(car); 51 | if (result.Success) 52 | { 53 | return Ok(result); 54 | } 55 | return BadRequest(result); 56 | } 57 | 58 | [HttpGet("getall")] 59 | public IActionResult GetAll() 60 | { 61 | var result = _carService.GetAll(); 62 | if (result.Success) 63 | { 64 | return Ok(result); 65 | } 66 | return BadRequest(result); 67 | } 68 | 69 | [HttpGet("getbyid")] 70 | public IActionResult GetById(int id) 71 | { 72 | var result = _carService.GetById(id); 73 | if (result.Success) 74 | { 75 | return Ok(result); 76 | } 77 | return BadRequest(result); 78 | } 79 | 80 | [HttpGet("getallcardetails")] 81 | public IActionResult GetAllCarDetails() 82 | { 83 | var result = _carService.GetCarDetails(); 84 | if (result.Success) 85 | { 86 | return Ok(result); 87 | } 88 | return BadRequest(result); 89 | } 90 | 91 | [HttpGet("getcardetail")] 92 | public IActionResult GetCarDetails(int carId) 93 | { 94 | var result = _carService.GetCarDetails(I => I.Id == carId); 95 | if (result.Success) 96 | { 97 | return Ok(result); 98 | } 99 | return BadRequest(result); 100 | } 101 | 102 | 103 | [HttpGet("getcarbycolor")] 104 | public IActionResult GetCarByColor(int colorId) 105 | { 106 | 107 | var result = _carService.GetCarDetails(I => I.ColorId == colorId); 108 | if (result.Success) 109 | { 110 | return Ok(result); 111 | } 112 | return BadRequest(result); 113 | } 114 | 115 | [HttpGet("getcarbybrand")] 116 | public IActionResult GetCarByBrand(int brandId) 117 | { 118 | 119 | var result = _carService.GetCarDetails(I => I.BrandId == brandId); 120 | if (result.Success) 121 | { 122 | return Ok(result); 123 | } 124 | return BadRequest(result); 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /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 | [HttpPost("add")] 24 | public IActionResult Add(Color color) 25 | { 26 | var result = _colorService.Add(color); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result); 32 | } 33 | 34 | [HttpPost("update")] 35 | public IActionResult Update(Color color) 36 | { 37 | var result = _colorService.Update(color); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result); 43 | } 44 | 45 | [HttpPost("delete")] 46 | public IActionResult Delete(Color color) 47 | { 48 | var result = _colorService.Delete(color); 49 | if (result.Success) 50 | { 51 | return Ok(result); 52 | } 53 | return BadRequest(result); 54 | } 55 | 56 | [HttpGet("getall")] 57 | public IActionResult GetAll() 58 | { 59 | var result = _colorService.GetAll(); 60 | if (result.Success) 61 | { 62 | return Ok(result); 63 | } 64 | return BadRequest(result); 65 | } 66 | 67 | [HttpGet("getbyid")] 68 | public IActionResult GetById(int id) 69 | { 70 | var result = _colorService.GetById(id); 71 | if (result.Success) 72 | { 73 | return Ok(result); 74 | } 75 | return BadRequest(result); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CreditCardsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class CreditCardsController : ControllerBase 15 | { 16 | ICreditCardService _creditCardService; 17 | 18 | public CreditCardsController(ICreditCardService creditCardService) 19 | { 20 | _creditCardService = creditCardService; 21 | } 22 | 23 | [HttpPost("add")] 24 | public IActionResult Add(CreditCard creditCard) 25 | { 26 | var result = _creditCardService.Add(creditCard); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result); 32 | } 33 | 34 | [HttpPost("update")] 35 | public IActionResult Update(CreditCard creditCard) 36 | { 37 | var result = _creditCardService.Update(creditCard); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result); 43 | } 44 | 45 | [HttpPost("delete")] 46 | public IActionResult Delete(CreditCard creditCard) 47 | { 48 | var result = _creditCardService.Delete(creditCard); 49 | if (result.Success) 50 | { 51 | return Ok(result); 52 | } 53 | return BadRequest(result); 54 | } 55 | 56 | [HttpGet("getall")] 57 | public IActionResult GetAll() 58 | { 59 | var result = _creditCardService.GetAll(); 60 | if (result.Success) 61 | { 62 | return Ok(result); 63 | } 64 | return BadRequest(result); 65 | } 66 | 67 | [HttpGet("getbyid")] 68 | public IActionResult GetById(int id) 69 | { 70 | var result = _creditCardService.GetById(id); 71 | if (result.Success) 72 | { 73 | return Ok(result); 74 | } 75 | return BadRequest(result); 76 | } 77 | 78 | [HttpGet("getallbyuserid")] 79 | public IActionResult GetAllByUserId(int userId) 80 | { 81 | var result = _creditCardService.GetByUserId(userId); 82 | if (result.Success) 83 | { 84 | return Ok(result); 85 | } 86 | return BadRequest(result); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CustomersController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class CustomersController : ControllerBase 15 | { 16 | ICustomerService _customerService; 17 | 18 | public CustomersController(ICustomerService customerService) 19 | { 20 | _customerService = customerService; 21 | } 22 | 23 | [HttpPost("add")] 24 | public IActionResult Add(Customer customer) 25 | { 26 | var result = _customerService.Add(customer); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result); 32 | } 33 | 34 | [HttpPost("update")] 35 | public IActionResult Update(Customer customer) 36 | { 37 | var result = _customerService.Update(customer); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result); 43 | } 44 | 45 | [HttpPost("delete")] 46 | public IActionResult Delete(Customer customer) 47 | { 48 | var result = _customerService.Delete(customer); 49 | if (result.Success) 50 | { 51 | return Ok(result); 52 | } 53 | return BadRequest(result); 54 | } 55 | 56 | [HttpGet("getall")] 57 | public IActionResult GetAll() 58 | { 59 | var result = _customerService.GetAll(); 60 | if (result.Success) 61 | { 62 | return Ok(result); 63 | } 64 | return BadRequest(result); 65 | } 66 | 67 | [HttpGet("getbyid")] 68 | public IActionResult GetById(int id) 69 | { 70 | var result = _customerService.GetById(id); 71 | if (result.Success) 72 | { 73 | return Ok(result); 74 | } 75 | return BadRequest(result); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /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 | [HttpPost("add")] 24 | public IActionResult Add(Rental rental) 25 | { 26 | var result = _rentalService.Add(rental); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result); 32 | } 33 | 34 | [HttpPost("update")] 35 | public IActionResult Update(Rental rental) 36 | { 37 | var result = _rentalService.Update(rental); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result); 43 | } 44 | 45 | [HttpPost("delete")] 46 | public IActionResult Delete(Rental rental) 47 | { 48 | var result = _rentalService.Delete(rental); 49 | if (result.Success) 50 | { 51 | return Ok(result); 52 | } 53 | return BadRequest(result); 54 | } 55 | 56 | [HttpGet("getall")] 57 | public IActionResult GetAll() 58 | { 59 | var result = _rentalService.GetAll(); 60 | if (result.Success) 61 | { 62 | return Ok(result); 63 | } 64 | return BadRequest(result); 65 | } 66 | 67 | [HttpGet("getbyid")] 68 | public IActionResult GetById(int id) 69 | { 70 | var result = _rentalService.GetById(id); 71 | if (result.Success) 72 | { 73 | return Ok(result); 74 | } 75 | return BadRequest(result); 76 | } 77 | 78 | [HttpGet("getallrentaldetails")] 79 | public IActionResult GetAllCarDetails() 80 | { 81 | var result = _rentalService.GetRentalDetails(); 82 | if (result.Success) 83 | { 84 | return Ok(result); 85 | } 86 | return BadRequest(result); 87 | } 88 | 89 | 90 | [HttpGet("getrentalbycar")] 91 | public IActionResult GetCarByColor(int id) 92 | { 93 | 94 | var result = _rentalService.GetRentalDetails(I => I.CarId == id); 95 | if (result.Success) 96 | { 97 | return Ok(result); 98 | } 99 | return BadRequest(result); 100 | } 101 | 102 | [HttpGet("getrentalbycustomer")] 103 | public IActionResult GetCarByBrand(int id) 104 | { 105 | 106 | var result = _rentalService.GetRentalDetails(I => I.CustomerId == id); 107 | if (result.Success) 108 | { 109 | return Ok(result); 110 | } 111 | return BadRequest(result); 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /WebAPI/Controllers/UsersController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Core.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 UsersController : ControllerBase 15 | { 16 | IUserService _userService; 17 | 18 | public UsersController(IUserService userService) 19 | { 20 | _userService = userService; 21 | } 22 | 23 | [HttpPost("add")] 24 | public IActionResult Add(User user) 25 | { 26 | var result = _userService.Add(user); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result); 32 | } 33 | 34 | [HttpPost("update")] 35 | public IActionResult Update(User user) 36 | { 37 | var result = _userService.Update(user); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result); 43 | } 44 | 45 | [HttpPost("delete")] 46 | public IActionResult Delete(User user) 47 | { 48 | var result = _userService.Delete(user); 49 | if (result.Success) 50 | { 51 | return Ok(result); 52 | } 53 | return BadRequest(result); 54 | } 55 | 56 | [HttpGet("getall")] 57 | public IActionResult GetAll() 58 | { 59 | var result = _userService.GetAll(); 60 | if (result.Success) 61 | { 62 | return Ok(result); 63 | } 64 | return BadRequest(result); 65 | } 66 | 67 | [HttpGet("getbyid")] 68 | public IActionResult GetById(int id) 69 | { 70 | var result = _userService.GetById(id); 71 | if (result.Success) 72 | { 73 | return Ok(result); 74 | } 75 | return BadRequest(result); 76 | } 77 | 78 | [HttpGet("getbyemail")] 79 | public IActionResult GetByEmail(string email) 80 | { 81 | var result = _userService.GetByMail(email); 82 | if (result.Success) 83 | { 84 | return Ok(result); 85 | } 86 | return BadRequest(result); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /WebAPI/Program.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Extensions.DependencyInjection; 3 | using Business.DependencyResolvers.Autofac; 4 | using Microsoft.AspNetCore.Hosting; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.Extensions.Hosting; 7 | using Microsoft.Extensions.Logging; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | using System.Threading.Tasks; 12 | 13 | namespace WebAPI 14 | { 15 | public class Program 16 | { 17 | public static void Main(string[] args) 18 | { 19 | CreateHostBuilder(args).Build().Run(); 20 | } 21 | 22 | public static IHostBuilder CreateHostBuilder(string[] args) => 23 | Host.CreateDefaultBuilder(args) 24 | .UseServiceProviderFactory(new AutofacServiceProviderFactory()) 25 | .ConfigureContainer(builder => { 26 | builder.RegisterModule(new AutofacBusinessModule()); 27 | }) 28 | .ConfigureWebHostDefaults(webBuilder => 29 | { 30 | webBuilder.UseStartup(); 31 | }); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /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:52030", 8 | "sslPort": 44397 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "weatherforecast", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "WebAPI": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "weatherforecast", 24 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /WebAPI/Startup.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Concrete; 3 | using Core.DependencyResolvers; 4 | using Core.Extensions; 5 | using Core.Utilities.IoC; 6 | using Core.Utilities.Security.Encryption; 7 | using Core.Utilities.Security.JWT; 8 | using DataAccess.Abstract; 9 | using DataAccess.Concrete.EntityFramework.Repository; 10 | using Microsoft.AspNetCore.Authentication.JwtBearer; 11 | using Microsoft.AspNetCore.Builder; 12 | using Microsoft.AspNetCore.Hosting; 13 | using Microsoft.AspNetCore.Http; 14 | using Microsoft.AspNetCore.HttpsPolicy; 15 | using Microsoft.AspNetCore.Mvc; 16 | using Microsoft.Extensions.Configuration; 17 | using Microsoft.Extensions.DependencyInjection; 18 | using Microsoft.Extensions.Hosting; 19 | using Microsoft.Extensions.Logging; 20 | using Microsoft.IdentityModel.Tokens; 21 | using System; 22 | using System.Collections.Generic; 23 | using System.Linq; 24 | using System.Threading.Tasks; 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 | var tokenOptions = Configuration.GetSection("TokenOptions").Get(); 45 | 46 | services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) 47 | .AddJwtBearer(options => 48 | { 49 | options.TokenValidationParameters = new TokenValidationParameters 50 | { 51 | ValidateIssuer = true, 52 | ValidateAudience = true, 53 | ValidateLifetime = true, 54 | ValidIssuer = tokenOptions.Issuer, 55 | ValidAudience = tokenOptions.Audience, 56 | ValidateIssuerSigningKey = true, 57 | IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) 58 | }; 59 | }); 60 | 61 | services.AddDependencyResolvers(new ICoreModule[] { 62 | new CoreModule() 63 | }); 64 | } 65 | 66 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 67 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 68 | { 69 | if (env.IsDevelopment()) 70 | { 71 | app.UseDeveloperExceptionPage(); 72 | } 73 | 74 | app.ConfigureCustomExceptionMiddleware(); 75 | 76 | app.UseCors(builder => builder.WithOrigins("http://localhost:4200").AllowAnyHeader()); 77 | 78 | app.UseHttpsRedirection(); 79 | 80 | app.UseRouting(); 81 | 82 | app.UseStaticFiles(); 83 | 84 | app.UseAuthentication(); 85 | 86 | app.UseAuthorization(); 87 | 88 | app.UseEndpoints(endpoints => 89 | { 90 | endpoints.MapControllers(); 91 | }); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /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": "gulceselim6@gmail.com", 4 | "Issuer": "gulceselim6@gmail.com", 5 | "AccessTokenExpiration": 10, 6 | "SecurityKey": "mysupersecretkeymysupersecretkey" 7 | }, 8 | "Logging": { 9 | "LogLevel": { 10 | "Default": "Information", 11 | "Microsoft": "Warning", 12 | "Microsoft.Hosting.Lifetime": "Information" 13 | } 14 | }, 15 | "AllowedHosts": "*" 16 | } 17 | -------------------------------------------------------------------------------- /WebAPI/log4net.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/bmw-beyaz.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gulceselim/re-cap-project-with-csharp/5e1ebedc22869513a00e29a4a85d83786239b94b/WebAPI/wwwroot/Images/bmw-beyaz.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gulceselim/re-cap-project-with-csharp/5e1ebedc22869513a00e29a4a85d83786239b94b/WebAPI/wwwroot/Images/default.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/reno-mavi.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gulceselim/re-cap-project-with-csharp/5e1ebedc22869513a00e29a4a85d83786239b94b/WebAPI/wwwroot/Images/reno-mavi.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/tesla-beyaz.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gulceselim/re-cap-project-with-csharp/5e1ebedc22869513a00e29a4a85d83786239b94b/WebAPI/wwwroot/Images/tesla-beyaz.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/tesla-mavi.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gulceselim/re-cap-project-with-csharp/5e1ebedc22869513a00e29a4a85d83786239b94b/WebAPI/wwwroot/Images/tesla-mavi.jpg --------------------------------------------------------------------------------