├── WebAPI ├── Startup.cs ├── wwwroot │ └── images │ │ ├── default.png │ │ ├── 0c29e3b1-c03a-4925-af4d-035628e3bc2c.PNG │ │ ├── 0d724c7a-4d5e-4138-a874-b336636e6ce9.PNG │ │ ├── 1609e351-6926-45b6-acc0-9db2ca5fd485.PNG │ │ ├── 23c1d135-f312-44ab-9eda-0f55dd4288e4.PNG │ │ ├── 26f5b046-518a-410b-8ff0-277f1d78e7ce.PNG │ │ ├── 2c65f562-cac3-4201-941a-94d1d41204dc.jpg │ │ ├── 30c496cb-4f1d-4175-af57-a82ba64f07f3.PNG │ │ ├── 35c4cb62-0ce7-4772-a6be-6fc9af2be3e7.jpg │ │ ├── 641d1399-1346-4fc7-8e72-3ff0e9e7b956.PNG │ │ ├── 92819fa5-7027-4383-8263-20b872801ce8.jpg │ │ ├── aad1e140-caa1-4058-82ba-49b1bc2bd447.jpg │ │ ├── d37f8f2d-ab67-451e-be91-b80e0079baec.jpg │ │ ├── d69a0605-7c36-4b21-8da1-d71bb4f04527.jpg │ │ ├── da566870-338d-417d-968f-141815017fec.PNG │ │ ├── e56e1f71-cdc0-44cc-979c-3df0fa8b378c.PNG │ │ ├── ed573ec0-5418-4862-a7dc-5c9f835c3619.jpg │ │ ├── f14c8310-2209-4307-8674-5f0be6235a2f.PNG │ │ └── fe4160e3-b46f-41b4-a744-ed62fe3161a1.png ├── appsettings.Development.json ├── WeatherForecast.cs ├── appsettings.json ├── WebAPI.csproj ├── Properties │ └── launchSettings.json ├── Program.cs └── Controllers │ ├── WeatherForecastController.cs │ ├── AuthController.cs │ ├── ColorsController.cs │ ├── PaymentsController.cs │ ├── CustomersController.cs │ ├── UsersController.cs │ ├── BrandsController.cs │ ├── CarImagesController.cs │ ├── RentalsController.cs │ └── CarsController.cs ├── README.md ├── Core ├── Entities │ ├── IDto.cs │ ├── IEntity.cs │ └── Concrete │ │ ├── OperationClaim.cs │ │ ├── UserOperationClaim.cs │ │ └── User.cs ├── Utilities │ ├── Results │ │ ├── IDataResult.cs │ │ ├── IResult.cs │ │ ├── ErrorResult.cs │ │ ├── SuccessResult.cs │ │ ├── DataResult.cs │ │ ├── Result.cs │ │ ├── ErrorDataResult.cs │ │ └── SuccessDataResult.cs │ ├── IoC │ │ ├── ICoreModule.cs │ │ └── ServiceTool.cs │ ├── Security │ │ ├── JWT │ │ │ ├── ITokenHelper.cs │ │ │ ├── TokenOptions.cs │ │ │ ├── AccessToken.cs │ │ │ └── JwtHelper.cs │ │ ├── Encryption │ │ │ ├── SecurityKeyHelper.cs │ │ │ └── SigningCredentialsHelper.cs │ │ └── Hashing │ │ │ └── HashingHelper.cs │ ├── Interceptors │ │ ├── MethodInterceptionBaseAttribute.cs │ │ ├── AspectInterceptorSelector.cs │ │ └── MethodInterception.cs │ ├── Business │ │ └── BusinessRules.cs │ └── Helpers │ │ ├── IFileHelper.cs │ │ └── FileHelper.cs ├── Extensions │ ├── ExceptionMiddlewareExtensions.cs │ ├── ErrorDetails.cs │ ├── ServiceCollectionExtensions.cs │ ├── ClaimsPrincipalExtensions.cs │ ├── ClaimExtensions.cs │ └── ExceptionMiddleware.cs ├── CrossCuttingConcerns │ ├── Caching │ │ ├── ICacheManager.cs │ │ └── Microsoft │ │ │ └── MemoryCacheManager.cs │ └── Validation │ │ └── ValidationTool.cs ├── DataAccess │ ├── IEntityRepository.cs │ └── EntityFramework │ │ └── EfEntityRepositoryBase.cs ├── DependencyResolvers │ └── CoreModule.cs ├── Aspects │ └── Autofac │ │ ├── Caching │ │ ├── CacheRemoveAspect.cs │ │ └── CacheAspect.cs │ │ ├── Transaction │ │ └── TransactionScopeAspect.cs │ │ ├── Performance │ │ └── PerformanceAspect.cs │ │ └── Validation │ │ └── ValidationAspect.cs └── Core.csproj ├── Business ├── CrossCuttingConcers │ ├── DatabaseLogger.cs │ ├── ILogger.cs │ └── FileLogger.cs ├── ValidationsRules │ └── FluentValidation │ │ ├── PaymentValidator.cs │ │ ├── RentalValidator.cs │ │ ├── CustomerValidator.cs │ │ ├── ColorValidator.cs │ │ ├── BrandValidator.cs │ │ ├── CarValidator.cs │ │ └── UserValidator.cs ├── Abstract │ ├── IColorService.cs │ ├── ICustomerService.cs │ ├── IPaymentService.cs │ ├── IBrandService.cs │ ├── IAuthService.cs │ ├── ICarImageService.cs │ ├── IRentalService.cs │ ├── IUserService.cs │ └── ICarService.cs ├── Business.csproj ├── BusinessAspects │ └── Autofac │ │ └── SecuredOperation.cs ├── Concrete │ ├── PaymentManager.cs │ ├── CustomerManager.cs │ ├── UserManager.cs │ ├── ColorManager.cs │ ├── AuthManager.cs │ ├── BrandManager.cs │ ├── CarManager.cs │ ├── RentalManager.cs │ └── CarImageManager.cs ├── DependencyResolvers │ └── Autofac │ │ └── AutofacBusinessModule.cs └── Constraints │ └── Messages.cs ├── ConsoleUI ├── ConsoleUI.csproj └── Program.cs ├── DataAccess ├── Abstract │ ├── IBrandDal.cs │ ├── IColorDal.cs │ ├── IPaymentDal.cs │ ├── ICustomerDal.cs │ ├── ICarImageDal.cs │ ├── IRentalDal.cs │ ├── IUserDal.cs │ └── ICarDal.cs ├── Concrete │ ├── EntityFramework │ │ ├── EfCarImageDal.cs │ │ ├── EfCustomerDal.cs │ │ ├── EfPaymentDal.cs │ │ ├── EfBrandDal.cs │ │ ├── EfColorDal.cs │ │ ├── EfUserDal.cs │ │ ├── RentACarContext.cs │ │ ├── EfRentalDal.cs │ │ └── EfCarDal.cs │ └── InMemory │ │ └── InMemoryCarDal.cs └── DataAccess.csproj ├── Entity ├── DTOs │ ├── UserForRegisterDto.cs │ ├── UserForLoginDto.cs │ ├── UserForUpdateDto.cs │ ├── RentalDetailDto.cs │ └── CarDetailDto.cs ├── Entity.csproj └── Concrete │ ├── Brand.cs │ ├── Color.cs │ ├── CarImage.cs │ ├── Customer.cs │ ├── Rental.cs │ ├── Payment.cs │ └── Car.cs ├── .gitattributes ├── RentACarProject.sln └── .gitignore /WebAPI/Startup.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/Startup.cs -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/default.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RentACarProject 2 | ## CSharp Bootcamp ile birlikte yürütülen bitirme projesidir. 3 | ## This is a graduation project carried out with bootcamp. 4 | -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/0c29e3b1-c03a-4925-af4d-035628e3bc2c.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/0c29e3b1-c03a-4925-af4d-035628e3bc2c.PNG -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/0d724c7a-4d5e-4138-a874-b336636e6ce9.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/0d724c7a-4d5e-4138-a874-b336636e6ce9.PNG -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/1609e351-6926-45b6-acc0-9db2ca5fd485.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/1609e351-6926-45b6-acc0-9db2ca5fd485.PNG -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/23c1d135-f312-44ab-9eda-0f55dd4288e4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/23c1d135-f312-44ab-9eda-0f55dd4288e4.PNG -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/26f5b046-518a-410b-8ff0-277f1d78e7ce.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/26f5b046-518a-410b-8ff0-277f1d78e7ce.PNG -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/2c65f562-cac3-4201-941a-94d1d41204dc.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/2c65f562-cac3-4201-941a-94d1d41204dc.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/30c496cb-4f1d-4175-af57-a82ba64f07f3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/30c496cb-4f1d-4175-af57-a82ba64f07f3.PNG -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/35c4cb62-0ce7-4772-a6be-6fc9af2be3e7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/35c4cb62-0ce7-4772-a6be-6fc9af2be3e7.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/641d1399-1346-4fc7-8e72-3ff0e9e7b956.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/641d1399-1346-4fc7-8e72-3ff0e9e7b956.PNG -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/92819fa5-7027-4383-8263-20b872801ce8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/92819fa5-7027-4383-8263-20b872801ce8.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/aad1e140-caa1-4058-82ba-49b1bc2bd447.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/aad1e140-caa1-4058-82ba-49b1bc2bd447.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/d37f8f2d-ab67-451e-be91-b80e0079baec.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/d37f8f2d-ab67-451e-be91-b80e0079baec.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/d69a0605-7c36-4b21-8da1-d71bb4f04527.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/d69a0605-7c36-4b21-8da1-d71bb4f04527.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/da566870-338d-417d-968f-141815017fec.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/da566870-338d-417d-968f-141815017fec.PNG -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/e56e1f71-cdc0-44cc-979c-3df0fa8b378c.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/e56e1f71-cdc0-44cc-979c-3df0fa8b378c.PNG -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/ed573ec0-5418-4862-a7dc-5c9f835c3619.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/ed573ec0-5418-4862-a7dc-5c9f835c3619.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/f14c8310-2209-4307-8674-5f0be6235a2f.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/f14c8310-2209-4307-8674-5f0be6235a2f.PNG -------------------------------------------------------------------------------- /WebAPI/wwwroot/images/fe4160e3-b46f-41b4-a744-ed62fe3161a1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UlasMuezzinoglu/RentACarProject/HEAD/WebAPI/wwwroot/images/fe4160e3-b46f-41b4-a744-ed62fe3161a1.png -------------------------------------------------------------------------------- /WebAPI/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Core/Entities/IDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Core.Entities 8 | { 9 | public interface IDto 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Entities/IEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Core.Entities 8 | { 9 | public interface IEntity 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/OperationClaim.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | 3 | namespace Core.Entities.Concrete 4 | { 5 | public class OperationClaim : IEntity 6 | { 7 | public int Id { get; set; } 8 | public string Name { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Business/CrossCuttingConcers/DatabaseLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Business.CrossCuttingConcers 4 | { 5 | public class DatabaseLogger : ILogger 6 | { 7 | public void Log() 8 | { 9 | Console.WriteLine("Veritabanına Loglandı"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Business/CrossCuttingConcers/ILogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Business.CrossCuttingConcers 8 | { 9 | public interface ILogger 10 | { 11 | void Log(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/Utilities/Results/IDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Core.Utilities.Results 8 | { 9 | public interface IDataResult:IResult 10 | { 11 | T Data { get; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ConsoleUI/ConsoleUI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/UserOperationClaim.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | 3 | namespace Core.Entities.Concrete 4 | { 5 | public class UserOperationClaim : IEntity 6 | { 7 | public int Id { get; set; } 8 | public int UserId { get; set; } 9 | public int OperationClaimId { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IBrandDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entity.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace DataAccess.Abstract 10 | { 11 | public interface IBrandDal : IEntityRepository 12 | { 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IColorDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entity.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace DataAccess.Abstract 10 | { 11 | public interface IColorDal : IEntityRepository 12 | { 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IPaymentDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entity.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace DataAccess.Abstract 10 | { 11 | public interface IPaymentDal : IEntityRepository 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Entity/DTOs/UserForRegisterDto.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | 3 | namespace Entity.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 | -------------------------------------------------------------------------------- /Entity/Entity.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICustomerDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entity.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace DataAccess.Abstract 10 | { 11 | public interface ICustomerDal : IEntityRepository 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICarImageDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entity.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace DataAccess.Abstract 10 | { 11 | public interface ICarImageDal : IEntityRepository 12 | { 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WebAPI/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebAPI 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Entity/Concrete/Brand.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Entity.Concrete 9 | { 10 | public class Brand : IEntity 11 | { 12 | public int Id { get; set; } 13 | public string Name { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Entity/Concrete/Color.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Entity.Concrete 9 | { 10 | public class Color :IEntity 11 | { 12 | public int Id { get; set; } 13 | public string Name { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Core/Utilities/IoC/ICoreModule.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Core.Utilities.IoC 9 | { 10 | public interface ICoreModule 11 | { 12 | void Load(IServiceCollection serviceCollction); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Core/Utilities/Results/IResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Core.Utilities.Results 8 | { 9 | //Temel voidler için başlangıç 10 | public interface IResult 11 | { 12 | bool Success { get; } 13 | string Message { get; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Entity/DTOs/UserForLoginDto.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Entity.DTOs 9 | { 10 | public class UserForLoginDto : IDto 11 | { 12 | public string Email { get; set; } 13 | public string Password { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Entity/DTOs/UserForUpdateDto.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Entity.DTOs 9 | { 10 | public class UserForUpdateDto 11 | { 12 | public User User { get; set; } 13 | public string Password { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Business/CrossCuttingConcers/FileLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Business.CrossCuttingConcers 8 | { 9 | public class FileLogger : ILogger 10 | { 11 | public void Log() 12 | { 13 | Console.WriteLine("Dosyaya Loglandı"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/ITokenHelper.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | 9 | namespace Core.Utilities.Security.JWT 10 | { 11 | public interface ITokenHelper 12 | { 13 | AccessToken CreateToken(User user, List operationClaims); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IRentalDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entity.Concrete; 3 | using Entity.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace DataAccess.Abstract 11 | { 12 | public interface IRentalDal : IEntityRepository 13 | { 14 | List GetRentalDetails(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IUserDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Core.Entities.Concrete; 3 | using Entity.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace DataAccess.Abstract 11 | { 12 | public interface IUserDal : IEntityRepository 13 | { 14 | List GetClaims(User user); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Core/Utilities/Results/ErrorResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Core.Utilities.Results 8 | { 9 | public class ErrorResult : Result 10 | { 11 | public ErrorResult( string message) : base(false, message) 12 | { 13 | } 14 | public ErrorResult() : base(false) 15 | { 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WebAPI/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "TokenOptions": { 3 | "Audience": "martulas5252@gmail.com", 4 | "Issuer": "martulas5252@gmail.com", 5 | "AccessTokenExpiration": 10, 6 | "SecurityKey": "mysupersecretkeymysupersecretkey" 7 | 8 | }, 9 | "Logging": { 10 | "LogLevel": { 11 | "Default": "Information", 12 | "Microsoft": "Warning", 13 | "Microsoft.Hosting.Lifetime": "Information" 14 | } 15 | }, 16 | "AllowedHosts": "*" 17 | } 18 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCarImageDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entity.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace DataAccess.Concrete.EntityFramework 11 | { 12 | public class EfCarImageDal : EfEntityRepositoryBase, ICarImageDal 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCustomerDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entity.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace DataAccess.Concrete.EntityFramework 11 | { 12 | public class EfCustomerDal : EfEntityRepositoryBase, ICustomerDal 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfPaymentDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entity.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace DataAccess.Concrete.EntityFramework 11 | { 12 | public class EfPaymentDal : EfEntityRepositoryBase, IPaymentDal 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Entity/Concrete/CarImage.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Entity.Concrete 9 | { 10 | public class CarImage : IEntity 11 | { 12 | public int Id { get; set; } 13 | public int CarId { get; set; } 14 | public string ImagePath { get; set; } 15 | public DateTime Date { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Core/Utilities/Results/SuccessResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Core.Utilities.Results 8 | { 9 | public class SuccessResult : Result 10 | { 11 | public SuccessResult(string message) : base(true, message) 12 | { 13 | 14 | } 15 | public SuccessResult() : base(true) 16 | { 17 | 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Business/ValidationsRules/FluentValidation/PaymentValidator.cs: -------------------------------------------------------------------------------- 1 | using Entity.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Business.ValidationsRules.FluentValidation 10 | { 11 | public class PaymentValidator : AbstractValidator 12 | { 13 | public PaymentValidator() 14 | { 15 | 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DataAccess/DataAccess.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/TokenOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Core.Utilities.Security.JWT 8 | { 9 | public class TokenOptions 10 | { 11 | public string Audience { get; set; } 12 | public string Issuer { get; set; } 13 | public int AccessTokenExpiration { get; set; } 14 | public string SecurityKey { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Entity/Concrete/Customer.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using Core.Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Entity.Concrete 10 | { 11 | public class Customer : IEntity 12 | { 13 | public int Id { get; set; } 14 | public int UserId { get; set; } 15 | public string CompanyName { get; set; } 16 | 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Business/ValidationsRules/FluentValidation/RentalValidator.cs: -------------------------------------------------------------------------------- 1 | using Entity.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Business.ValidationsRules.FluentValidation 10 | { 11 | public class RentalValidator : AbstractValidator 12 | { 13 | public RentalValidator() 14 | { 15 | 16 | } 17 | 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Core/Extensions/ExceptionMiddlewareExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Core.Extensions 9 | { 10 | public static class ExceptionMiddlewareExtensions 11 | { 12 | public static void ConfigureCustomExceptionMiddleware(this IApplicationBuilder app) 13 | { 14 | app.UseMiddleware(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/AccessToken.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Core.Utilities.Security.JWT 8 | { 9 | public class AccessToken 10 | { 11 | public string Token { get; set; } 12 | public DateTime Expiration { get; set; } 13 | public int UserId { get; set; } 14 | public string FirstName { get; set; } 15 | public string LastName { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Encryption/SecurityKeyHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IdentityModel.Tokens; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Core.Utilities.Security.Encryption 9 | { 10 | public class SecurityKeyHelper 11 | { 12 | public static SecurityKey CreateSecurityKey(string securityKey) 13 | { 14 | return new SymmetricSecurityKey(Encoding.UTF8.GetBytes(securityKey)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfBrandDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entity.Concrete; 4 | using Microsoft.EntityFrameworkCore; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Linq.Expressions; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | 12 | namespace DataAccess.Concrete.EntityFramework 13 | { 14 | public class EfBrandDal : EfEntityRepositoryBase ,IBrandDal 15 | { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfColorDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entity.Concrete; 4 | using Microsoft.EntityFrameworkCore; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Linq.Expressions; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | 12 | namespace DataAccess.Concrete.EntityFramework 13 | { 14 | public class EfColorDal : EfEntityRepositoryBase, IColorDal 15 | { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Business/Abstract/IColorService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entity.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Business.Abstract 10 | { 11 | public interface IColorService 12 | { 13 | IDataResult> GetAll(); 14 | IDataResult GetById(int id); 15 | IResult Add(Color color); 16 | IResult Delete(Color color); 17 | IResult Update(Color color); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Business/ValidationsRules/FluentValidation/CustomerValidator.cs: -------------------------------------------------------------------------------- 1 | using Entity.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Business.ValidationsRules.FluentValidation 10 | { 11 | public class CustomerValidator : AbstractValidator 12 | { 13 | public CustomerValidator() 14 | { 15 | RuleFor(customer => customer.CompanyName).MinimumLength(2); 16 | 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Caching/ICacheManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Core.CrossCuttingConcerns.Caching 8 | { 9 | public interface ICacheManager 10 | { 11 | T Get(string key); 12 | object Get(string key); 13 | void Add(string key, object value, int duration); 14 | bool IsAdd(string key); 15 | void Remove(string key); 16 | void RemoveByPattern(string pattern); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Entity/Concrete/Rental.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Entity.Concrete 9 | { 10 | public class Rental : IEntity 11 | { 12 | public int Id { get; set; } 13 | public int CarId { get; set; } 14 | public int UserId { get; set; } 15 | public DateTime RentDate { get; set; } 16 | public DateTime ReturnDate { get; set; } 17 | //public int BrandId { get; set; } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Business/Abstract/ICustomerService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entity.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Business.Abstract 10 | { 11 | public interface ICustomerService 12 | { 13 | IResult Add(Customer customer); 14 | IResult Update(Customer customer); 15 | IResult Delete(Customer customer); 16 | 17 | IDataResult> GetAll(); 18 | IDataResult GetByUserId(int id); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Business/ValidationsRules/FluentValidation/ColorValidator.cs: -------------------------------------------------------------------------------- 1 | using Entity.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Business.ValidationsRules.FluentValidation 10 | { 11 | public class ColorValidator : AbstractValidator 12 | { 13 | public ColorValidator() 14 | { 15 | RuleFor(color => color.Name).NotEmpty(); 16 | RuleFor(color => color.Name).MinimumLength(2); 17 | 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Entity/Concrete/Payment.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Entity.Concrete 9 | { 10 | public class Payment : IEntity 11 | { 12 | public int Id { get; set; } 13 | public int UserId { get; set; } 14 | public string CreditCardNumber { get; set; } 15 | public string ExpirationMonth { get; set; } 16 | public string ExpirationYear { get; set; } 17 | public string SecurityCode { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Business/Abstract/IPaymentService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entity.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Business.Abstract 10 | { 11 | public interface IPaymentService 12 | { 13 | IDataResult GetById(int id); 14 | IDataResult> GetAll(); 15 | IDataResult> GetAllByUserId(int userId); 16 | 17 | IResult Add(Payment payment); 18 | 19 | IResult Delete(Payment payment); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Encryption/SigningCredentialsHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IdentityModel.Tokens; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Core.Utilities.Security.Encryption 9 | { 10 | public class SigningCredentialsHelper 11 | { 12 | public static SigningCredentials CreateSigningCredentials 13 | (SecurityKey securityKey) 14 | { 15 | return new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha512Signature); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Entity/Concrete/Car.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Entity.Concrete 9 | { 10 | public class Car:IEntity 11 | { 12 | public int Id { get; set; } 13 | public int BrandId { get; set; } 14 | public int ColorId { get; set; } 15 | public string Model { get; set; } 16 | public int ModelYear { get; set; } 17 | public decimal DailyPrice { get; set; } 18 | public string Description { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Core/Utilities/Results/DataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Core.Utilities.Results 8 | { 9 | public class DataResult : Result, IDataResult 10 | { 11 | public DataResult(T data,bool success, string message):base(success,message) 12 | { 13 | Data = data; 14 | } 15 | public DataResult(T data, bool success): base(success) 16 | { 17 | Data = data; 18 | } 19 | 20 | public T Data { get; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Utilities/IoC/ServiceTool.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Core.Utilities.IoC 9 | { 10 | public static class ServiceTool 11 | { 12 | public static IServiceProvider ServiceProvider { get; private set; } 13 | 14 | public static IServiceCollection Create(IServiceCollection services) 15 | { 16 | ServiceProvider = services.BuildServiceProvider(); 17 | return services; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Business/Abstract/IBrandService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entity.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Business.Abstract 10 | { 11 | public interface IBrandService 12 | { 13 | IDataResult> GetAll(); 14 | 15 | IDataResult GetById(int id); 16 | 17 | IResult Add(Brand brand); 18 | IResult Delete(Brand brand); 19 | IResult Update(Brand brand); 20 | 21 | IResult AddTransactionalTest(Brand brand); 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/MethodInterceptionBaseAttribute.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Core.Utilities.Interceptors 8 | { 9 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] 10 | public abstract class MethodInterceptionBaseAttribute : Attribute, IInterceptor 11 | { 12 | public int Priority { get; set; } 13 | 14 | public virtual void Intercept(IInvocation invocation) 15 | { 16 | 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICarDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entity.Concrete; 3 | using Entity.DTOs; 4 | using System.Collections.Generic; 5 | 6 | namespace DataAccess.Abstract 7 | { 8 | public interface ICarDal : IEntityRepository 9 | { 10 | List GetCarDetails(); 11 | List GetCarDetailsDtoWithCarId(int carId); 12 | 13 | List GetCarDetailDtosWithBrandId(int id); 14 | List GetCarDetailDtosWithColorId(int id); 15 | 16 | List GetCarDetailDtosWithColorIdAndBrandId(int colorId, int brandId); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/User.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Core.Entities.Concrete 9 | { 10 | public class User: IEntity 11 | { 12 | public int Id { get; set; } 13 | public string FirstName { get; set; } 14 | public string LastName { get; set; } 15 | public string Email { get; set; } 16 | public byte[] PasswordSalt { get; set; } 17 | public byte[] PasswordHash { get; set; } 18 | public bool Status { get; set; } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Business/ValidationsRules/FluentValidation/BrandValidator.cs: -------------------------------------------------------------------------------- 1 | using Entity.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Business.ValidationsRules.FluentValidation 10 | { 11 | public class BrandValidator : AbstractValidator 12 | { 13 | public BrandValidator() 14 | { 15 | RuleFor(brand => brand.Name).NotEmpty(); 16 | RuleFor(brand => brand.Name).MinimumLength(2); 17 | RuleFor(brand => brand.Name).Length(1, 19); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Core/Utilities/Business/BusinessRules.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Core.Utilities.Business 9 | { 10 | public class BusinessRules 11 | { 12 | public static IResult Run(params IResult[] logics) 13 | { 14 | foreach (var logic in logics) 15 | { 16 | if (!logic.Success) 17 | { 18 | return logic; 19 | } 20 | } 21 | return null; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Core/DataAccess/IEntityRepository.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Linq.Expressions; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Core.DataAccess 10 | { 11 | //generic constraint -- jenerik kısıt 12 | public interface IEntityRepository where T : class, IEntity, new() 13 | { 14 | List GetAll(Expression> filter = null); 15 | 16 | T Get(Expression> filter); 17 | void Add(T entity); 18 | void Update(T entity); 19 | void Delete(T entity); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Core/Utilities/Results/Result.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Core.Utilities.Results 8 | { 9 | public class Result : IResult 10 | { 11 | 12 | public Result(bool success, string message) : this(success) 13 | { 14 | 15 | this.Message = message; 16 | } 17 | public Result(bool success) 18 | { 19 | this.Success = success; 20 | 21 | } 22 | 23 | public bool Success { get; } 24 | 25 | public string Message { get; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Business/Abstract/IAuthService.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Core.Utilities.Results; 3 | using Core.Utilities.Security.JWT; 4 | using Entity.DTOs; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace Business.Abstract 12 | { 13 | public interface IAuthService 14 | { 15 | IDataResult Register(UserForRegisterDto userForRegisterDto, string password); 16 | IDataResult Login(UserForLoginDto userForLoginDto); 17 | IResult UserExists(string email); 18 | IDataResult CreateAccessToken(User user); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Entity/DTOs/RentalDetailDto.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Entity.DTOs 9 | { 10 | public class RentalDetailDto : IDto 11 | { 12 | public int Id { get; set; } 13 | public string BrandName { get; set; } 14 | public string FirstName { get; set; } 15 | public string LastName { get; set; } 16 | public int ModelYear { get; set; } 17 | public decimal DailyPrice { get; set; } 18 | public DateTime RentDate { get; set; } 19 | public DateTime ReturnDate { get; set; } 20 | 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Validation/ValidationTool.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Core.CrossCuttingConcerns.Validation 9 | { 10 | public static class ValidationTool 11 | { 12 | public static void Validate(IValidator validator, object entity) 13 | { 14 | var context = new ValidationContext(entity); 15 | var result = validator.Validate(context); 16 | if (!result.IsValid) 17 | { 18 | throw new ValidationException(result.Errors); 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Extensions/ErrorDetails.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation.Results; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Core.Extensions 10 | { 11 | public class ErrorDetails 12 | { 13 | public string Message { get; set; } 14 | public int StatusCode { get; set; } 15 | 16 | public override string ToString() 17 | { 18 | return JsonConvert.SerializeObject(this); 19 | } 20 | } 21 | public class ValidationErrorDetails : ErrorDetails 22 | { 23 | public IEnumerable Errors { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Business/Abstract/ICarImageService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entity.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Business.Abstract 11 | { 12 | public interface ICarImageService 13 | { 14 | IDataResult> GetAll(); 15 | 16 | IDataResult GetById(int id); 17 | IDataResult > GetByCarId(int carId); 18 | 19 | IResult Add(CarImage carImage, IFormFile file); 20 | IResult Delete(CarImage carImage); 21 | IResult Update(CarImage carImage,IFormFile file); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Core/Utilities/Results/ErrorDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Core.Utilities.Results 8 | { 9 | public class ErrorDataResult : DataResult 10 | { 11 | public ErrorDataResult(T data, string message) : base(data, false, message) 12 | { 13 | 14 | } 15 | public ErrorDataResult(T data) : base(data, false) 16 | { 17 | 18 | } 19 | 20 | public ErrorDataResult(string message) : base(default, false, message) 21 | { 22 | 23 | } 24 | public ErrorDataResult() : base(default, false) 25 | { 26 | 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Business/Abstract/IRentalService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entity.Concrete; 3 | using Entity.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Business.Abstract 11 | { 12 | public interface IRentalService 13 | { 14 | IDataResult> GetAll(); 15 | 16 | IDataResult GetByCustomerId(int id); 17 | 18 | IResult Add(Rental rental); 19 | 20 | IResult AddMultiple(Rental[] rentals); 21 | 22 | IResult Delete(Rental rental); 23 | IResult Update(Rental rental); 24 | 25 | IDataResult> GetRentalDetails(); 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Core/Utilities/Results/SuccessDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Core.Utilities.Results 8 | { 9 | public class SuccessDataResult : DataResult 10 | { 11 | public SuccessDataResult(T data, string message): base(data,true,message) 12 | { 13 | 14 | } 15 | public SuccessDataResult(T data) : base(data,true) 16 | { 17 | 18 | } 19 | 20 | public SuccessDataResult(string message):base(default,true,message) 21 | { 22 | 23 | } 24 | public SuccessDataResult() : base(default, true) 25 | { 26 | 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /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.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Core.Extensions 10 | { 11 | public static class ServiceCollectionExtensions 12 | { 13 | public static IServiceCollection AddDependencyResolvers(this IServiceCollection serviceCollection, 14 | ICoreModule[] modules) 15 | { 16 | foreach (var module in modules) 17 | { 18 | module.Load(serviceCollection); 19 | } 20 | return ServiceTool.Create(serviceCollection); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /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 | using System.Threading.Tasks; 7 | 8 | namespace Core.Extensions 9 | { 10 | public static class ClaimsPrincipalExtensions 11 | { 12 | public static List Claims(this ClaimsPrincipal claimsPrincipal, string claimType) 13 | { 14 | var result = claimsPrincipal?.FindAll(claimType)?.Select(x => x.Value).ToList(); 15 | return result; 16 | } 17 | 18 | public static List ClaimRoles(this ClaimsPrincipal claimsPrincipal) 19 | { 20 | return claimsPrincipal?.Claims(ClaimTypes.Role); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Core/Utilities/Helpers/IFileHelper.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Microsoft.AspNetCore.Http; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Core.Utilities.Helpers 10 | { 11 | public interface IFileHelper 12 | { 13 | void DeleteOldFile(string directory); 14 | void CreateFile(string directory, IFormFile file); 15 | void CheckDirectoryExist(string directory); 16 | IResult CheckFileTypeValid(string type); 17 | IResult CheckFileExist(IFormFile file); 18 | IResult Upload(IFormFile file); 19 | IResult Update(IFormFile file, string imagePath); 20 | IResult Delete(string path); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Business/Abstract/IUserService.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Core.Utilities.Results; 3 | using Entity.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Business.Abstract 11 | { 12 | public interface IUserService 13 | { 14 | 15 | List GetClaims(User user); 16 | void Add(User user); 17 | 18 | IResult Update(User user, string password); 19 | IDataResult GetByUserId(int userId); 20 | IDataResult> GetAll(); 21 | IDataResult GetById(int id); 22 | User GetByMail(string email); 23 | 24 | IDataResult GetByEmail(string email); 25 | 26 | 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Business/ValidationsRules/FluentValidation/CarValidator.cs: -------------------------------------------------------------------------------- 1 | using Entity.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Business.ValidationsRules.FluentValidation 10 | { 11 | public class CarValidator : AbstractValidator 12 | { 13 | public CarValidator() 14 | { 15 | RuleFor(car => car.DailyPrice).NotEmpty(); 16 | RuleFor(car => car.DailyPrice).GreaterThan(0); 17 | RuleFor(car => car.ModelYear).GreaterThan(2000); 18 | RuleFor(car => car.ModelYear).NotEmpty(); 19 | RuleFor(car => car.Description).Length(1, 350); 20 | 21 | 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /WebAPI/WebAPI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/AspectInterceptorSelector.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | using System.Linq; 4 | using System.Reflection; 5 | 6 | namespace Core.Utilities.Interceptors 7 | { 8 | public class AspectInterceptorSelector : IInterceptorSelector 9 | { 10 | public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) 11 | { 12 | var classAttributes = type.GetCustomAttributes 13 | (true).ToList(); 14 | var methodAttributes = type.GetMethod(method.Name) 15 | .GetCustomAttributes(true); 16 | classAttributes.AddRange(methodAttributes); 17 | 18 | return classAttributes.OrderBy(x => x.Priority).ToArray(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /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.Linq; 10 | using System.Text; 11 | using System.Threading.Tasks; 12 | 13 | namespace Core.DependencyResolvers 14 | { 15 | public class CoreModule : ICoreModule 16 | { 17 | public void Load(IServiceCollection serviceCollction) 18 | { 19 | serviceCollction.AddMemoryCache(); 20 | serviceCollction.AddSingleton(); 21 | serviceCollction.AddSingleton(); 22 | serviceCollction.AddSingleton(); 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Entity/DTOs/CarDetailDto.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Entity.DTOs 9 | { 10 | public class CarDetailDto : IDto 11 | { 12 | //public int Id { get; set; } 13 | //public string BrandName { get; set; } 14 | //public string ColorName { get; set; } 15 | 16 | //public decimal DailyPrice { get; set; } 17 | public int Id { get; set; } 18 | public string BrandName { get; set; } 19 | public string ColorName { get; set; } 20 | public int ModelYear { get; set; } 21 | public string Model { get; set; } 22 | public decimal DailyPrice { get; set; } 23 | public string Description { get; set; } 24 | public string ImagePath { get; set; } 25 | public string ReturnDate { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /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:28075", 8 | "sslPort": 44341 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "WebAPI": { 21 | "commandName": "Project", 22 | "dotnetRunMessages": "true", 23 | "launchBrowser": true, 24 | "launchUrl": "swagger", 25 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Business/Business.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Caching/CacheRemoveAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.CrossCuttingConcerns.Caching; 3 | using Core.Utilities.Interceptors; 4 | using Core.Utilities.IoC; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using Microsoft.Extensions.DependencyInjection; 11 | 12 | namespace Core.Aspects.Autofac.Caching 13 | { 14 | public class CacheRemoveAspect : MethodInterception 15 | { 16 | private string _pattern; 17 | private ICacheManager _cacheManager; 18 | 19 | public CacheRemoveAspect(string pattern) 20 | { 21 | _pattern = pattern; 22 | _cacheManager = ServiceTool.ServiceProvider.GetService(); 23 | } 24 | 25 | protected override void OnSuccess(IInvocation invocation) 26 | { 27 | _cacheManager.RemoveByPattern(_pattern); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /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.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Transactions; 9 | 10 | namespace Core.Aspects.Autofac.Transaction 11 | { 12 | public class TransactionScopeAspect : MethodInterception 13 | { 14 | public override void Intercept(IInvocation invocation) 15 | { 16 | using (TransactionScope transactionScope = new TransactionScope()) 17 | { 18 | try 19 | { 20 | invocation.Proceed(); 21 | transactionScope.Complete(); 22 | } 23 | catch (Exception) 24 | { 25 | transactionScope.Dispose(); 26 | throw; 27 | } 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Business/ValidationsRules/FluentValidation/UserValidator.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Entity.Concrete; 3 | using FluentValidation; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Business.ValidationsRules.FluentValidation 11 | { 12 | public class UserValidator : AbstractValidator 13 | { 14 | public UserValidator() 15 | { 16 | RuleFor(user => user.FirstName).MinimumLength(2); 17 | RuleFor(user => user.FirstName).NotEmpty(); 18 | RuleFor(user => user.LastName).MinimumLength(2); 19 | RuleFor(user => user.LastName).NotEmpty(); 20 | //RuleFor(user => user.Password).MinimumLength(8); 21 | //RuleFor(user => user.Password).NotEmpty(); 22 | RuleFor(user => user.Email).EmailAddress(); 23 | RuleFor(user => user.Email).NotEmpty(); 24 | 25 | 26 | 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Core/Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Business/Abstract/ICarService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entity.Concrete; 3 | using Entity.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Business.Abstract 11 | { 12 | public interface ICarService 13 | { 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int id); 16 | //IDataResult> GetCarsByBrandId(int id); 17 | IDataResult> GetCarsByBrandId(int id); 18 | //IDataResult> GetCarsByColorId(int id); 19 | IDataResult> GetCarsByColorId(int id); 20 | 21 | IDataResult> GetCarsDetailDtoByCarId(int id); 22 | 23 | 24 | 25 | IDataResult> GetCarsDetailDtoByBrandAndColorId(int brandId,int colorId); 26 | 27 | 28 | 29 | IDataResult> GetCarDetailsDto(); 30 | 31 | IResult Add(Car car); 32 | IResult Delete(Car car); 33 | 34 | IResult Update(Car car); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /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 | using System.Threading.Tasks; 8 | 9 | namespace Core.Extensions 10 | { 11 | public static class ClaimExtensions 12 | { 13 | public static void AddEmail(this ICollection claims, string email) 14 | { 15 | claims.Add(new Claim(JwtRegisteredClaimNames.Email, email)); 16 | } 17 | 18 | public static void AddName(this ICollection claims, string name) 19 | { 20 | claims.Add(new Claim(ClaimTypes.Name, name)); 21 | } 22 | 23 | public static void AddNameIdentifier(this ICollection claims, string nameIdentifier) 24 | { 25 | claims.Add(new Claim(ClaimTypes.NameIdentifier, nameIdentifier)); 26 | } 27 | 28 | public static void AddRoles(this ICollection claims, string[] roles) 29 | { 30 | roles.ToList().ForEach(role => claims.Add(new Claim(ClaimTypes.Role, role))); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /WebAPI/Program.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Extensions.DependencyInjection; 3 | using Business.DependencyResolvers.Autofac; 4 | using Microsoft.AspNetCore.Hosting; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.Extensions.Hosting; 7 | using Microsoft.Extensions.Logging; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | using System.Threading.Tasks; 12 | 13 | namespace WebAPI 14 | { 15 | public class Program 16 | { 17 | public static void Main(string[] args) 18 | { 19 | CreateHostBuilder(args).Build().Run(); 20 | } 21 | 22 | public static IHostBuilder CreateHostBuilder(string[] args) => 23 | Host.CreateDefaultBuilder(args) 24 | .UseServiceProviderFactory(new AutofacServiceProviderFactory()) 25 | .ConfigureContainer(builder => 26 | { 27 | builder.RegisterModule(new AutofacBusinessModule()); 28 | }) 29 | .ConfigureWebHostDefaults(webBuilder => 30 | { 31 | webBuilder.UseStartup(); 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfUserDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using Core.Entities.Concrete; 3 | using DataAccess.Abstract; 4 | using Entity.Concrete; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace DataAccess.Concrete.EntityFramework 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 | } 31 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/MethodInterception.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | 4 | namespace Core.Utilities.Interceptors 5 | { 6 | public abstract class MethodInterception : MethodInterceptionBaseAttribute 7 | { 8 | protected virtual void OnBefore(IInvocation invocation) { } 9 | protected virtual void OnAfter(IInvocation invocation) { } 10 | protected virtual void OnException(IInvocation invocation, System.Exception e) { } 11 | protected virtual void OnSuccess(IInvocation invocation) { } 12 | public override void Intercept(IInvocation invocation) 13 | { 14 | var isSuccess = true; 15 | OnBefore(invocation); 16 | try 17 | { 18 | invocation.Proceed(); 19 | } 20 | catch (Exception e) 21 | { 22 | isSuccess = false; 23 | OnException(invocation, e); 24 | throw; 25 | } 26 | finally 27 | { 28 | if (isSuccess) 29 | { 30 | OnSuccess(invocation); 31 | } 32 | } 33 | OnAfter(invocation); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/RentACarContext.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Entity.Concrete; 3 | using Microsoft.EntityFrameworkCore; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace DataAccess.Concrete.EntityFramework 11 | { 12 | public class RentACarContext : DbContext 13 | { 14 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 15 | { 16 | optionsBuilder.UseSqlServer(@"Server=(localdb)\MSSQLLocalDb;Database=RentACar;Trusted_Connection=true"); 17 | } 18 | public DbSet Cars { get; set; } 19 | public DbSet Colors { get; set; } 20 | public DbSet Brands { get; set; } 21 | public DbSet Customers { get; set; } 22 | public DbSet Rentals { get; set; } 23 | public DbSet CarImages { get; set; } 24 | public DbSet OperationClaims { get; set; } 25 | public DbSet Users { get; set; } 26 | public DbSet UserOperationClaims { get; set; } 27 | public DbSet Payments { get; set; } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Performance/PerformanceAspect.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Interceptors; 2 | using Core.Utilities.IoC; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Diagnostics; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using Microsoft.Extensions.DependencyInjection; 10 | using Castle.DynamicProxy; 11 | 12 | namespace Core.Aspects.Autofac.Performance 13 | { 14 | public class PerformanceAspect : MethodInterception 15 | { 16 | private int _interval; 17 | private Stopwatch _stopwatch; 18 | 19 | public PerformanceAspect(int interval) 20 | { 21 | _interval = interval; 22 | _stopwatch = ServiceTool.ServiceProvider.GetService(); 23 | } 24 | 25 | 26 | protected override void OnBefore(IInvocation invocation) 27 | { 28 | _stopwatch.Start(); 29 | } 30 | 31 | protected override void OnAfter(IInvocation invocation) 32 | { 33 | if (_stopwatch.Elapsed.TotalSeconds > _interval) 34 | { 35 | Debug.WriteLine($"Performance : {invocation.Method.DeclaringType.FullName}.{invocation.Method.Name}-->{_stopwatch.Elapsed.TotalSeconds}"); 36 | } 37 | _stopwatch.Reset(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /WebAPI/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace WebAPI.Controllers 9 | { 10 | [ApiController] 11 | [Route("[controller]")] 12 | public class WeatherForecastController : ControllerBase 13 | { 14 | private static readonly string[] Summaries = new[] 15 | { 16 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 17 | }; 18 | 19 | private readonly ILogger _logger; 20 | 21 | public WeatherForecastController(ILogger logger) 22 | { 23 | _logger = logger; 24 | } 25 | 26 | [HttpGet] 27 | public IEnumerable Get() 28 | { 29 | var rng = new Random(); 30 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 31 | { 32 | Date = DateTime.Now.AddDays(index), 33 | TemperatureC = rng.Next(-20, 55), 34 | Summary = Summaries[rng.Next(Summaries.Length)] 35 | }) 36 | .ToArray(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /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 | using System.Threading.Tasks; 10 | 11 | namespace Core.Aspects.Autofac.Validation 12 | { 13 | public class ValidationAspect : MethodInterception 14 | { 15 | private Type _validatorType; 16 | public ValidationAspect(Type validatorType) 17 | { 18 | if (!typeof(IValidator).IsAssignableFrom(validatorType)) 19 | { 20 | throw new System.Exception("Bu Bir Doğrulama Sınıfı Değil"); 21 | } 22 | 23 | _validatorType = validatorType; 24 | } 25 | protected override void OnBefore(IInvocation invocation) 26 | { 27 | var validator = (IValidator)Activator.CreateInstance(_validatorType); 28 | var entityType = _validatorType.BaseType.GetGenericArguments()[0]; 29 | var entities = invocation.Arguments.Where(t => t.GetType() == entityType); 30 | foreach (var entity in entities) 31 | { 32 | ValidationTool.Validate(validator, entity); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Business/BusinessAspects/Autofac/SecuredOperation.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Interceptors; 2 | using Core.Utilities.IoC; 3 | using Microsoft.AspNetCore.Http; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using Castle.DynamicProxy; 10 | using Microsoft.Extensions.DependencyInjection; 11 | using Core.Extensions; 12 | using Business.Constraints; 13 | 14 | namespace Business.BusinessAspects.Autofac 15 | { 16 | //for jwt 17 | public class SecuredOperation : MethodInterception 18 | { 19 | private string[] _roles; 20 | private IHttpContextAccessor _httpContextAccessor; 21 | 22 | public SecuredOperation(string roles) 23 | { 24 | _roles = roles.Split(','); 25 | _httpContextAccessor = ServiceTool.ServiceProvider.GetService(); 26 | 27 | } 28 | 29 | protected override void OnBefore(IInvocation invocation) 30 | { 31 | var roleClaims = _httpContextAccessor.HttpContext.User.ClaimRoles(); 32 | foreach (var role in _roles) 33 | { 34 | if (roleClaims.Contains(role)) 35 | { 36 | return; 37 | } 38 | } 39 | throw new Exception(Messages.AuthorizationDenied); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Hashing/HashingHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Core.Utilities.Security.Hashing 8 | { 9 | public class HashingHelper 10 | { 11 | public static void CreatePasswordHash 12 | (string password, out byte[] passwordHash, out byte[] passwordSalt) 13 | { 14 | using (var hmac = new System.Security.Cryptography.HMACSHA512()) 15 | { 16 | passwordSalt = hmac.Key; 17 | passwordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(password)); 18 | } 19 | } 20 | public static bool VerifyPasswordHash 21 | (string password, byte[] passwordHash, byte[] passwordSalt) 22 | { 23 | using (var hmac = new System.Security.Cryptography.HMACSHA512(passwordSalt)) 24 | { 25 | var computedHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(password)); 26 | 27 | for (int i = 0; i < computedHash.Length; i++) 28 | { 29 | if (computedHash[i] != passwordHash[i]) 30 | { 31 | return false; 32 | } 33 | } 34 | return true; 35 | } 36 | 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Caching/CacheAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.CrossCuttingConcerns.Caching; 3 | using Core.Utilities.Interceptors; 4 | using Core.Utilities.IoC; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using Microsoft.Extensions.DependencyInjection; 11 | 12 | namespace Core.Aspects.Autofac.Caching 13 | { 14 | public class CacheAspect : MethodInterception 15 | { 16 | private int _duration; 17 | private ICacheManager _cacheManager; 18 | 19 | public CacheAspect(int duration = 60) 20 | { 21 | _duration = duration; 22 | _cacheManager = ServiceTool.ServiceProvider.GetService(); 23 | } 24 | 25 | public override void Intercept(IInvocation invocation) 26 | { 27 | var methodName = string.Format($"{invocation.Method.ReflectedType.FullName}.{invocation.Method.Name}"); 28 | var arguments = invocation.Arguments.ToList(); 29 | var key = $"{methodName}({string.Join(",", arguments.Select(x => x?.ToString() ?? ""))})"; 30 | if (_cacheManager.IsAdd(key)) 31 | { 32 | invocation.ReturnValue = _cacheManager.Get(key); 33 | return; 34 | } 35 | invocation.Proceed(); 36 | _cacheManager.Add(key, invocation.ReturnValue, _duration); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Business/Concrete/PaymentManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constraints; 3 | using Core.Utilities.Results; 4 | using DataAccess.Abstract; 5 | using Entity.Concrete; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | 12 | namespace Business.Concrete 13 | { 14 | public class PaymentManager : IPaymentService 15 | { 16 | IPaymentDal _paymentDal; 17 | 18 | public PaymentManager(IPaymentDal paymentDal) 19 | { 20 | _paymentDal = paymentDal; 21 | } 22 | 23 | public IResult Add(Payment payment) 24 | { 25 | _paymentDal.Add(payment); 26 | return new SuccessResult(Messages.paymentAdded); 27 | } 28 | 29 | 30 | public IResult Delete(Payment payment) 31 | { 32 | _paymentDal.Delete(payment); 33 | return new SuccessResult(Messages.paymentDeleted); 34 | } 35 | 36 | public IDataResult> GetAll() 37 | { 38 | return new SuccessDataResult>(_paymentDal.GetAll()); 39 | } 40 | 41 | public IDataResult> GetAllByUserId(int userId) 42 | { 43 | return new SuccessDataResult>(_paymentDal.GetAll(c => c.UserId == userId)); 44 | } 45 | 46 | 47 | public IDataResult GetById(int id) 48 | { 49 | return new SuccessDataResult(_paymentDal.Get(c => c.Id == id)); 50 | } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfRentalDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entity.Concrete; 4 | using Entity.DTOs; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace DataAccess.Concrete.EntityFramework 12 | { 13 | public class EfRentalDal : EfEntityRepositoryBase, IRentalDal 14 | { 15 | public List GetRentalDetails() 16 | { 17 | using (RentACarContext context = new RentACarContext()) 18 | { 19 | var result = from r in context.Rentals 20 | join c in context.Cars on r.CarId equals c.Id 21 | //join cs in context.Customers on r.CustomerId equals cs.Id 22 | join u in context.Users on r.UserId equals u.Id 23 | join b in context.Brands on c.BrandId equals b.Id 24 | 25 | 26 | select new RentalDetailDto 27 | { 28 | BrandName = b.Name, 29 | Id = r.Id, 30 | FirstName = u.FirstName, 31 | LastName = u.LastName, 32 | RentDate = r.RentDate, 33 | ReturnDate = r.ReturnDate, 34 | DailyPrice = c.DailyPrice, 35 | ModelYear = c.ModelYear 36 | 37 | 38 | }; 39 | return result.ToList(); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /WebAPI/Controllers/AuthController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entity.DTOs; 3 | using Microsoft.AspNetCore.Mvc; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | 9 | namespace WebAPI.Controllers 10 | { 11 | [Route("api/[controller]")] 12 | [ApiController] 13 | public class AuthController : Controller 14 | { 15 | private IAuthService _authService; 16 | 17 | public AuthController(IAuthService authService) 18 | { 19 | _authService = authService; 20 | } 21 | 22 | [HttpPost("login")] 23 | public ActionResult Login(UserForLoginDto userForLoginDto) 24 | { 25 | var userToLogin = _authService.Login(userForLoginDto); 26 | if (!userToLogin.Success) 27 | { 28 | return BadRequest(userToLogin.Message); 29 | } 30 | 31 | var result = _authService.CreateAccessToken(userToLogin.Data); 32 | if (result.Success) 33 | { 34 | return Ok(result); 35 | } 36 | 37 | return BadRequest(result.Message); 38 | } 39 | 40 | [HttpPost("register")] 41 | public ActionResult Register(UserForRegisterDto userForRegisterDto) 42 | { 43 | var userExists = _authService.UserExists(userForRegisterDto.Email); 44 | if (!userExists.Success) 45 | { 46 | return BadRequest(userExists.Message); 47 | } 48 | 49 | var registerResult = _authService.Register(userForRegisterDto, userForRegisterDto.Password); 50 | var result = _authService.CreateAccessToken(registerResult.Data); 51 | if (result.Success) 52 | { 53 | return Ok(result.Data); 54 | } 55 | 56 | return BadRequest(result.Message); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Core/Extensions/ExceptionMiddleware.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Microsoft.AspNetCore.Http; 8 | using System.Net; 9 | using FluentValidation.Results; 10 | 11 | namespace Core.Extensions 12 | { 13 | public class ExceptionMiddleware 14 | { 15 | private RequestDelegate _next; 16 | 17 | public ExceptionMiddleware(RequestDelegate next) 18 | { 19 | _next = next; 20 | } 21 | 22 | public async Task InvokeAsync(HttpContext httpContext) 23 | { 24 | try 25 | { 26 | await _next(httpContext); 27 | } 28 | catch (Exception e) 29 | { 30 | await HandleExceptionAsync(httpContext, e); 31 | } 32 | } 33 | 34 | private Task HandleExceptionAsync(HttpContext httpContext, Exception e) 35 | { 36 | httpContext.Response.ContentType = "application/json"; 37 | httpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; 38 | 39 | string message = "Internal Server Error"; 40 | IEnumerable errors; 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, Errors = errors 50 | }.ToString()); 51 | } 52 | 53 | return httpContext.Response.WriteAsync(new ErrorDetails 54 | { 55 | StatusCode = httpContext.Response.StatusCode, 56 | Message = message 57 | }.ToString()); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Business/Concrete/CustomerManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constraints; 3 | using Business.ValidationsRules.FluentValidation; 4 | using Core.Aspects.Autofac.Validation; 5 | using Core.Utilities.Results; 6 | using DataAccess.Abstract; 7 | using Entity.Concrete; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | 14 | namespace Business.Concrete 15 | { 16 | public class CustomerManager : ICustomerService 17 | { 18 | ICustomerDal _customerDal; 19 | 20 | public CustomerManager(ICustomerDal customerDal) 21 | { 22 | _customerDal = customerDal; 23 | } 24 | 25 | [ValidationAspect(typeof(CustomerValidator))] 26 | public IResult Add(Customer customer) 27 | { 28 | _customerDal.Add(customer); 29 | return new SuccessResult(Messages.CustomerAdded); 30 | } 31 | 32 | public IResult Delete(Customer customer) 33 | { 34 | try 35 | { 36 | _customerDal.Delete(customer); 37 | return new SuccessResult(Messages.CustomerDeleted); 38 | } 39 | catch (Exception) 40 | { 41 | return new ErrorResult(Messages.CustomerCantDeledet); 42 | } 43 | } 44 | 45 | public IDataResult> GetAll() 46 | { 47 | return new SuccessDataResult>(_customerDal.GetAll(), Messages.CustomersListed); 48 | 49 | } 50 | 51 | public IDataResult GetByUserId(int id) 52 | { 53 | return new SuccessDataResult(_customerDal.Get(c => c.UserId == id), Messages.CustomerListed); 54 | } 55 | 56 | public IResult Update(Customer customer) 57 | { 58 | try 59 | { 60 | _customerDal.Update(customer); 61 | return new SuccessResult(Messages.CustomerUpdated); 62 | } 63 | catch (Exception) 64 | { 65 | return new ErrorResult(Messages.CustomerCantUpdated); 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /WebAPI/Controllers/ColorsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entity.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class ColorsController : ControllerBase 15 | { 16 | IColorService _colorService; 17 | 18 | public ColorsController(IColorService colorService) 19 | { 20 | _colorService = colorService; 21 | } 22 | 23 | [HttpGet("getall")] 24 | public IActionResult GetAll() 25 | { 26 | var result = _colorService.GetAll(); 27 | 28 | if (result.Success) 29 | { 30 | return Ok(result); 31 | } 32 | return BadRequest(result); 33 | } 34 | [HttpGet("getbyid")] 35 | public IActionResult GetById(int id) 36 | { 37 | var result = _colorService.GetById(id); 38 | 39 | if (result.Success) 40 | { 41 | return Ok(result); 42 | } 43 | return BadRequest(result); 44 | } 45 | [HttpPost("add")] 46 | public IActionResult Add(Color color) 47 | { 48 | var result = _colorService.Add(color); 49 | if (result.Success) 50 | { 51 | return Ok(result); 52 | } 53 | return BadRequest(result); 54 | } 55 | [HttpPost("update")] 56 | public IActionResult Update(Color color) 57 | { 58 | var result = _colorService.Update(color); 59 | if (result.Success) 60 | { 61 | return Ok(result); 62 | } 63 | return BadRequest(result); 64 | } 65 | [HttpPost("delete")] 66 | public IActionResult Delete(Color color) 67 | { 68 | var result = _colorService.Delete(color); 69 | if (result.Success) 70 | { 71 | return Ok(result); 72 | } 73 | return BadRequest(result); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /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 | using System.Threading.Tasks; 9 | 10 | namespace Core.DataAccess.EntityFramework 11 | { 12 | public class EfEntityRepositoryBase : IEntityRepository 13 | where TEntity : class, IEntity, new() where TContext : DbContext, new() 14 | { 15 | public void Add(TEntity entity) 16 | { 17 | //IDisposable pattern implementation of c# 18 | using (TContext context = new TContext()) 19 | { 20 | var addedEntity = context.Entry(entity); 21 | addedEntity.State = EntityState.Added; 22 | context.SaveChanges(); 23 | 24 | 25 | } 26 | } 27 | 28 | public void Delete(TEntity entity) 29 | { 30 | using (TContext context = new TContext()) 31 | { 32 | var deletedEntity = context.Entry(entity); 33 | deletedEntity.State = EntityState.Deleted; 34 | context.SaveChanges(); 35 | } 36 | } 37 | 38 | public TEntity Get(Expression> filter) 39 | { 40 | using (TContext context = new TContext()) 41 | { 42 | return context.Set().SingleOrDefault(filter); 43 | } 44 | } 45 | 46 | public List GetAll(Expression> filter = null) 47 | { 48 | using (TContext context = new TContext()) 49 | { 50 | return filter == null ? context.Set().ToList() 51 | : context.Set().Where(filter).ToList(); 52 | 53 | } 54 | } 55 | 56 | public void Update(TEntity entity) 57 | { 58 | using (TContext context = new TContext()) 59 | { 60 | var updatedEntity = context.Entry(entity); 61 | updatedEntity.State = EntityState.Modified; 62 | context.SaveChanges(); 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /WebAPI/Controllers/PaymentsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entity.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 PaymentsController : ControllerBase 15 | { 16 | IPaymentService _paymentService; 17 | 18 | public PaymentsController(IPaymentService paymentService) 19 | { 20 | _paymentService = paymentService; 21 | } 22 | 23 | [HttpGet("getallbyuserid")] 24 | public IActionResult GetAllByUserId(int userId) 25 | { 26 | var result = _paymentService.GetAllByUserId(userId); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | 32 | return BadRequest(result); 33 | } 34 | 35 | [HttpGet("getall")] 36 | public IActionResult GetAll() 37 | { 38 | var result = _paymentService.GetAll(); 39 | if (result.Success) 40 | { 41 | return Ok(result); 42 | } 43 | return BadRequest(result); 44 | } 45 | 46 | [HttpGet("getbyid")] 47 | public IActionResult GetById(int id) 48 | { 49 | var result = _paymentService.GetById(id); 50 | if (result.Success) return Ok(result); 51 | 52 | return BadRequest(result); 53 | } 54 | 55 | 56 | [HttpPost("add")] 57 | public IActionResult Add(Payment payment) 58 | { 59 | var result = _paymentService.Add(payment); 60 | if (result.Success) 61 | { 62 | return Ok(result); 63 | } 64 | 65 | return BadRequest(result); 66 | } 67 | 68 | [HttpPost("delete")] 69 | public IActionResult Delete(Payment payment) 70 | { 71 | var result = _paymentService.Delete(payment); 72 | if (result.Success) 73 | { 74 | return Ok(result); 75 | } 76 | 77 | return BadRequest(result); 78 | } 79 | 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CustomersController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entity.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 | [HttpGet("getall")] 23 | public IActionResult GetAll() 24 | { 25 | var result = _customerService.GetAll(); 26 | if (result.Success) 27 | { 28 | return Ok(result); 29 | } 30 | return BadRequest(result); 31 | } 32 | [HttpGet("getbyid")] 33 | public IActionResult Get(int id) 34 | { 35 | var result = _customerService.GetByUserId(id); 36 | if (result.Success) 37 | { 38 | return Ok(result); 39 | } 40 | return BadRequest(result); 41 | } 42 | 43 | 44 | [HttpPost("add")] 45 | public IActionResult Add(Customer customer) 46 | { 47 | var result = _customerService.Add(customer); 48 | if (result.Success) 49 | { 50 | return Ok(result); 51 | } 52 | return BadRequest(result); 53 | } 54 | [HttpPut("update")] 55 | public IActionResult Update(Customer customer) 56 | { 57 | var result = _customerService.Update(customer); 58 | if (result.Success) 59 | { 60 | return Ok(result); 61 | } 62 | return BadRequest(result); 63 | } 64 | [HttpDelete("delete")] 65 | public IActionResult Delete(Customer customer) 66 | { 67 | var result = _customerService.Delete(customer); 68 | if (result.Success) 69 | { 70 | return Ok(result); 71 | } 72 | return BadRequest(result); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /WebAPI/Controllers/UsersController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Core.Entities.Concrete; 3 | using Entity.Concrete; 4 | using Entity.DTOs; 5 | using Microsoft.AspNetCore.Http; 6 | using Microsoft.AspNetCore.Mvc; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using System.Threading.Tasks; 11 | 12 | namespace WebAPI.Controllers 13 | { 14 | [Route("api/[controller]")] 15 | [ApiController] 16 | public class UsersController : ControllerBase 17 | { 18 | IUserService _userService; 19 | 20 | public UsersController(IUserService userService) 21 | { 22 | _userService = userService; 23 | } 24 | 25 | [HttpGet("getbyid")] 26 | public IActionResult GetById(int id) 27 | { 28 | var result = _userService.GetById(id); 29 | if (result.Success) 30 | { 31 | return Ok(result); 32 | } 33 | return BadRequest(result); 34 | } 35 | 36 | [HttpGet("getall")] 37 | public IActionResult GetAll() 38 | { 39 | var result = _userService.GetAll(); 40 | if (result.Success) 41 | { 42 | return Ok(result); 43 | } 44 | return BadRequest(result); 45 | } 46 | 47 | [HttpGet("getbyuserid")] 48 | public IActionResult GetByUserId(int userId) 49 | { 50 | var result = _userService.GetByUserId(userId); 51 | if (result.Success) 52 | { 53 | return Ok(result); 54 | } 55 | 56 | return BadRequest(result); 57 | } 58 | 59 | [HttpPost("updateprofile")] 60 | public IActionResult ProfileUpdate(UserForUpdateDto userForUpdateDto) 61 | { 62 | var result = _userService.Update(userForUpdateDto.User, userForUpdateDto.Password); 63 | if (result.Success) 64 | { 65 | return Ok(result); 66 | } 67 | return BadRequest(result); 68 | } 69 | [HttpGet("getbyemail")] 70 | public IActionResult GetByEmail(string email) 71 | { 72 | var result = _userService.GetByEmail(email); 73 | if (result.Success) 74 | { 75 | return Ok(result); 76 | } 77 | 78 | return BadRequest(result); 79 | } 80 | 81 | 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /WebAPI/Controllers/BrandsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entity.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 | 17 | //Loosely Coupled 18 | //Naming Convertion 19 | //IoC Container -- Inversion of Control 20 | IBrandService _brandService; 21 | public BrandsController(IBrandService brandService) 22 | { 23 | _brandService = brandService; 24 | } 25 | [HttpGet("getall")] 26 | public IActionResult Get() 27 | { 28 | var result = _brandService.GetAll(); 29 | if (result.Success) 30 | { 31 | return Ok(result); 32 | } 33 | 34 | 35 | //return NotFound(result); 36 | return BadRequest(result); 37 | //return Unauthorized(result); 38 | } 39 | [HttpPost("add")] 40 | public IActionResult Add(Brand brand) 41 | { 42 | var result = _brandService.Add(brand); 43 | 44 | if (result.Success) 45 | { 46 | return Ok(result); 47 | } 48 | return BadRequest(result); 49 | } 50 | [HttpGet("getbyid")] 51 | public IActionResult GetById(int id) 52 | { 53 | var result = _brandService.GetById(id); 54 | if (result.Success) 55 | { 56 | return Ok(result); 57 | } 58 | return BadRequest(result); 59 | } 60 | 61 | [HttpPost("updatebrand")] 62 | public IActionResult Update(Brand brand) 63 | { 64 | var result = _brandService.Update(brand); 65 | if (result.Success) 66 | { 67 | return Ok(result); 68 | } 69 | return BadRequest(result); 70 | } 71 | [HttpPost("deletebrand")] 72 | public IActionResult Delete(Brand brand) 73 | { 74 | var result = _brandService.Delete(brand); 75 | if (result.Success) 76 | { 77 | return Ok(result); 78 | } 79 | return BadRequest(result); 80 | } 81 | 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Business/Concrete/UserManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Business.Abstract; 4 | using Business.Constraints; 5 | using Core.Aspects.Autofac.Caching; 6 | using Core.Entities.Concrete; 7 | using Core.Utilities.Results; 8 | using Core.Utilities.Security.Hashing; 9 | using DataAccess.Abstract; 10 | 11 | namespace Business.Concrete 12 | { 13 | public class UserManager : IUserService 14 | { 15 | IUserDal _userDal; 16 | public UserManager(IUserDal userDal) 17 | { 18 | _userDal = userDal; 19 | } 20 | //[ValidationAspect(typeof(UserValidator))] 21 | public List GetClaims(User user) 22 | { 23 | return _userDal.GetClaims(user); 24 | } 25 | 26 | public void Add(User user) 27 | { 28 | _userDal.Add(user); 29 | } 30 | 31 | public User GetByMail(string email) 32 | { 33 | return _userDal.Get(u => u.Email == email); 34 | } 35 | 36 | [CacheRemoveAspect("IUserService.Get")] 37 | public IResult Update(User user, string password) 38 | { 39 | byte[] passwordHash, passwordSalt; 40 | HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt); 41 | 42 | var updatedUser = new User 43 | { 44 | Id = user.Id, 45 | Email = user.Email, 46 | FirstName = user.FirstName, 47 | LastName = user.LastName, 48 | PasswordHash = passwordHash, 49 | PasswordSalt = passwordSalt, 50 | Status = user.Status 51 | }; 52 | _userDal.Update(updatedUser); 53 | return new SuccessResult(Messages.UserUpdated); 54 | 55 | } 56 | 57 | public IDataResult GetByUserId(int userId) 58 | { 59 | return new SuccessDataResult(_userDal.Get(user => user.Id == userId)); 60 | } 61 | 62 | public IDataResult> GetAll() 63 | { 64 | return new SuccessDataResult>(_userDal.GetAll()); 65 | } 66 | 67 | public IDataResult GetById(int id) 68 | { 69 | return new SuccessDataResult(_userDal.Get(data => data.Id == id)); 70 | } 71 | 72 | public IDataResult GetByEmail(string email) 73 | { 74 | return new SuccessDataResult(_userDal.Get(data => data.Email == email)); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /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.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Text.RegularExpressions; 9 | using Microsoft.Extensions.DependencyInjection; 10 | 11 | namespace Core.CrossCuttingConcerns.Caching.Microsoft 12 | { 13 | //Adapter Pattern 14 | public class MemoryCacheManager : ICacheManager 15 | { 16 | IMemoryCache _memoryCache; 17 | 18 | public MemoryCacheManager() 19 | { 20 | _memoryCache = ServiceTool.ServiceProvider.GetService(); 21 | } 22 | 23 | public void Add(string key, object value, int duration) 24 | { 25 | _memoryCache.Set(key, value, TimeSpan.FromMinutes(duration)); 26 | } 27 | 28 | public T Get(string key) 29 | { 30 | return _memoryCache.Get(key); 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 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CarImagesController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entity.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 | [HttpGet("getall")] 23 | public IActionResult GetAll() 24 | { 25 | var result = _carImageService.GetAll(); 26 | 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result.Message); 32 | } 33 | 34 | [HttpPost("add")] 35 | public IActionResult Add(IFormFile file, [FromForm] CarImage carImages) 36 | { 37 | var result = _carImageService.Add(carImages, file); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result.Message); 43 | } 44 | 45 | [HttpDelete("delete")] 46 | public IActionResult Delete([FromForm(Name = ("id"))] int id) 47 | { 48 | var deleteCarImage = _carImageService.GetById(id).Data; 49 | var result = _carImageService.Delete(deleteCarImage); 50 | if (result.Success) 51 | { 52 | return Ok(result); 53 | } 54 | return BadRequest(result.Message); 55 | } 56 | [HttpPut("update")] 57 | public IActionResult Update([FromForm] CarImage carImages, [FromForm(Name = ("Image"))] IFormFile file) 58 | { 59 | var result = _carImageService.Update(carImages, file); 60 | if (result.Success) 61 | { 62 | return Ok(result); 63 | } 64 | return BadRequest(result.Message); 65 | } 66 | 67 | [HttpGet("getbycarid")] 68 | public IActionResult GetByCarId(int carId) 69 | { 70 | var result = _carImageService.GetByCarId(carId); 71 | if (result.Success) 72 | { 73 | return Ok(result); 74 | } 75 | return BadRequest(result.Message); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Business/Concrete/ColorManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constraints; 3 | using Business.ValidationsRules.FluentValidation; 4 | using Core.Aspects.Autofac.Caching; 5 | using Core.Aspects.Autofac.Validation; 6 | using Core.Utilities.Results; 7 | using DataAccess.Abstract; 8 | using Entity.Concrete; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | using System.Threading.Tasks; 14 | 15 | namespace Business.Concrete 16 | { 17 | public class ColorManager : IColorService 18 | { 19 | IColorDal _colorDal; 20 | 21 | public ColorManager(IColorDal colorDal) 22 | { 23 | _colorDal = colorDal; 24 | } 25 | 26 | [ValidationAspect(typeof(ColorValidator))] 27 | [CacheRemoveAspect("IColorService.Get")] 28 | public IResult Add(Color color) 29 | { 30 | _colorDal.Add(color); 31 | return new SuccessResult (Messages.ColorAdded); 32 | } 33 | 34 | [CacheRemoveAspect("IColorService.Get")] 35 | public IResult Delete(Color color) 36 | { 37 | try 38 | { 39 | _colorDal.Delete(color); 40 | return new SuccessResult(Messages.ColorDeleted); 41 | } 42 | catch (Exception) 43 | { 44 | 45 | return new ErrorResult(Messages.ColorCantDeleted); 46 | } 47 | } 48 | 49 | [CacheAspect] 50 | public IDataResult> GetAll() 51 | { 52 | var result = _colorDal.GetAll(); 53 | //return new SuccessDataResult>(_colorDal.GetAll(),Messages.ColorsListed); 54 | if (result.Count < 0) 55 | { 56 | return new ErrorDataResult>(Messages.ColorNotFound); 57 | } 58 | return new SuccessDataResult>(result, Messages.ColorListed); 59 | } 60 | 61 | [CacheAspect] 62 | public IDataResult GetById(int id) 63 | { 64 | return new SuccessDataResult(_colorDal.Get(color => color.Id == id),Messages.ColorListed); 65 | } 66 | 67 | 68 | [CacheRemoveAspect("IColorService.Get")] 69 | public IResult Update(Color color) 70 | { 71 | try 72 | { 73 | _colorDal.Update(color); 74 | return new SuccessResult(Messages.ColorUpdated); 75 | } 76 | catch (Exception) 77 | { 78 | 79 | return new ErrorResult(Messages.ColorCantUpdated); 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /Business/Concrete/AuthManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Core.Entities.Concrete; 3 | using Core.Utilities.Results; 4 | using Core.Utilities.Security.Hashing; 5 | using Core.Utilities.Security.JWT; 6 | using Entity.DTOs; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using System.Text; 11 | using System.Threading.Tasks; 12 | 13 | namespace Business.Concrete 14 | { 15 | public class AuthManager : IAuthService 16 | { 17 | private IUserService _userService; 18 | private ITokenHelper _tokenHelper; 19 | 20 | public AuthManager(IUserService userService, ITokenHelper tokenHelper) 21 | { 22 | _userService = userService; 23 | _tokenHelper = tokenHelper; 24 | } 25 | 26 | public IDataResult Register(UserForRegisterDto userForRegisterDto, string password) 27 | { 28 | byte[] passwordHash, passwordSalt; 29 | HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt); 30 | var user = new User 31 | { 32 | Email = userForRegisterDto.Email, 33 | FirstName = userForRegisterDto.FirstName, 34 | LastName = userForRegisterDto.LastName, 35 | PasswordHash = passwordHash, 36 | PasswordSalt = passwordSalt, 37 | Status = true 38 | }; 39 | _userService.Add(user); 40 | return new SuccessDataResult(user, "Kayıt oldu"); 41 | } 42 | 43 | public IDataResult Login(UserForLoginDto userForLoginDto) 44 | { 45 | var userToCheck = _userService.GetByMail(userForLoginDto.Email); 46 | if (userToCheck == null) 47 | { 48 | return new ErrorDataResult("Kullanıcı Bulunamadı"); 49 | } 50 | 51 | if (!HashingHelper.VerifyPasswordHash(userForLoginDto.Password, userToCheck.PasswordHash, userToCheck.PasswordSalt)) 52 | { 53 | return new ErrorDataResult("Parola Hatası"); 54 | } 55 | 56 | return new SuccessDataResult(userToCheck, "Başarılı Giriş"); 57 | } 58 | 59 | public IResult UserExists(string email) 60 | { 61 | if (_userService.GetByMail(email) != null) 62 | { 63 | return new ErrorResult("Kullanıcı Mevcut"); 64 | } 65 | return new SuccessResult(); 66 | } 67 | 68 | public IDataResult CreateAccessToken(User user) 69 | { 70 | var claims = _userService.GetClaims(user); 71 | var accessToken = _tokenHelper.CreateToken(user, claims); 72 | return new SuccessDataResult(accessToken, "Token Oluşturuldu"); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Business/Concrete/BrandManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.BusinessAspects.Autofac; 3 | using Business.Constraints; 4 | using Business.ValidationsRules.FluentValidation; 5 | using Core.Aspects.Autofac.Caching; 6 | using Core.Aspects.Autofac.Performance; 7 | using Core.Aspects.Autofac.Transaction; 8 | using Core.Aspects.Autofac.Validation; 9 | using Core.Utilities.Results; 10 | using DataAccess.Abstract; 11 | using Entity.Concrete; 12 | using System; 13 | using System.Collections.Generic; 14 | using System.Linq; 15 | using System.Text; 16 | using System.Threading.Tasks; 17 | 18 | namespace Business.Concrete 19 | { 20 | public class BrandManager : IBrandService 21 | { 22 | 23 | IBrandDal _brandDal; 24 | 25 | public BrandManager(IBrandDal brandDal) 26 | { 27 | _brandDal = brandDal; 28 | } 29 | 30 | //[SecuredOperation("brand.add,admin ")] 31 | [ValidationAspect(typeof(BrandValidator))] 32 | [CacheRemoveAspect("IBrandService.Get")] 33 | public IResult Add(Brand brand) 34 | { 35 | 36 | 37 | _brandDal.Add(brand); 38 | return new SuccessResult(Messages.BrandAdded); 39 | 40 | } 41 | 42 | [TransactionScopeAspect] 43 | public IResult AddTransactionalTest(Brand brand) 44 | { 45 | //ToDo -- transaction dene 46 | return null; 47 | } 48 | 49 | [CacheRemoveAspect("IBrandService.Get")] 50 | public IResult Delete(Brand brand) 51 | { 52 | try 53 | { 54 | _brandDal.Delete(brand); 55 | return new SuccessResult(Messages.BrandDeleted); 56 | } 57 | catch (Exception) 58 | { 59 | 60 | return new ErrorResult(Messages.BrandCantDeledet); 61 | } 62 | 63 | } 64 | 65 | [CacheAspect] 66 | public IDataResult> GetAll() 67 | { 68 | return new SuccessDataResult>(_brandDal.GetAll(),Messages.BrandsListed); 69 | } 70 | 71 | 72 | [CacheAspect] 73 | [PerformanceAspect(7)] // bu metotun çalışması 7 saniyeyi geçerce beni uyar 74 | public IDataResult GetById(int id) 75 | { 76 | return new SuccessDataResult(_brandDal.Get(brand => brand.Id == id),Messages.BrandsListed); 77 | } 78 | 79 | [ValidationAspect(typeof(BrandValidator))] 80 | [CacheRemoveAspect("IBrandService.Get")] 81 | public IResult Update(Brand brand) 82 | { 83 | try 84 | { 85 | _brandDal.Update(brand); 86 | return new SuccessResult(Messages.BrandUpdated); 87 | } 88 | catch (Exception) 89 | { 90 | 91 | return new ErrorResult(Messages.BrandCantUpdated); 92 | } 93 | 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /WebAPI/Controllers/RentalsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entity.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 | [HttpGet("getall")] 23 | public IActionResult GetAll() 24 | { 25 | var result = _rentalService.GetAll(); 26 | if (result.Success) 27 | { 28 | return Ok(result); 29 | } 30 | return BadRequest(result); 31 | } 32 | [HttpGet("getbyid")] 33 | public IActionResult Get(int id) 34 | { 35 | var result = _rentalService.GetByCustomerId(id); 36 | if (result.Success) 37 | { 38 | return Ok(result); 39 | } 40 | return BadRequest(result); 41 | } 42 | 43 | 44 | [HttpPost("add")] 45 | public IActionResult Add(Rental rental) 46 | { 47 | var result = _rentalService.Add(rental); 48 | if (result.Success) 49 | { 50 | return Ok(result); 51 | } 52 | return BadRequest(result); 53 | } 54 | 55 | [HttpPost("addmultiple")] 56 | public IActionResult AddMultiple(Rental[] rentals) 57 | { 58 | var result = _rentalService.AddMultiple(rentals); 59 | if (result.Success) 60 | { 61 | return Ok(result); 62 | } 63 | return BadRequest(result); 64 | } 65 | 66 | [HttpPut("update")] 67 | public IActionResult Update(Rental rental) 68 | { 69 | var result = _rentalService.Update(rental); 70 | if (result.Success) 71 | { 72 | return Ok(result); 73 | } 74 | return BadRequest(result); 75 | } 76 | [HttpDelete("delete")] 77 | public IActionResult Delete(Rental rental) 78 | { 79 | var result = _rentalService.Delete(rental); 80 | if (result.Success) 81 | { 82 | return Ok(result); 83 | } 84 | return BadRequest(result); 85 | } 86 | [HttpGet("getrentaldetails")] 87 | public IActionResult GetDetails() 88 | { 89 | var result = _rentalService.GetRentalDetails(); 90 | if (result.Success) 91 | { 92 | return Ok(result); 93 | } 94 | 95 | return BadRequest(result); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /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 | using System.Threading.Tasks; 13 | 14 | namespace Core.Utilities.Security.JWT 15 | { 16 | public class JwtHelper : ITokenHelper 17 | { 18 | public IConfiguration Configuration { get; } 19 | private TokenOptions _tokenOptions; 20 | private DateTime _accessTokenExpiration; 21 | public JwtHelper(IConfiguration configuration) 22 | { 23 | Configuration = configuration; 24 | _tokenOptions = Configuration.GetSection("TokenOptions").Get(); 25 | 26 | } 27 | public AccessToken CreateToken(User user, List operationClaims) 28 | { 29 | _accessTokenExpiration = DateTime.Now.AddMinutes(_tokenOptions.AccessTokenExpiration); 30 | var securityKey = SecurityKeyHelper.CreateSecurityKey(_tokenOptions.SecurityKey); 31 | var signingCredentials = SigningCredentialsHelper.CreateSigningCredentials(securityKey); 32 | var jwt = CreateJwtSecurityToken(_tokenOptions, user, signingCredentials, operationClaims); 33 | var jwtSecurityTokenHandler = new JwtSecurityTokenHandler(); 34 | var token = jwtSecurityTokenHandler.WriteToken(jwt); 35 | 36 | return new AccessToken 37 | { 38 | Token = token, 39 | Expiration = _accessTokenExpiration, 40 | UserId = user.Id, // ToDo 41 | FirstName = user.FirstName, // normalde bunlar burada olmamalı burası core katmanı... 42 | LastName = user.LastName // gerizekalı değiliz refactor edicez bi ara 43 | 44 | }; 45 | 46 | } 47 | 48 | public JwtSecurityToken CreateJwtSecurityToken(TokenOptions tokenOptions, User user, 49 | SigningCredentials signingCredentials, List operationClaims) 50 | { 51 | var jwt = new JwtSecurityToken( 52 | issuer: tokenOptions.Issuer, 53 | audience: tokenOptions.Audience, 54 | expires: _accessTokenExpiration, 55 | notBefore: DateTime.Now, 56 | claims: SetClaims(user, operationClaims), 57 | signingCredentials: signingCredentials 58 | ); 59 | return jwt; 60 | } 61 | 62 | private IEnumerable SetClaims(User user, List operationClaims) 63 | { 64 | var claims = new List(); 65 | claims.AddNameIdentifier(user.Id.ToString()); 66 | claims.AddEmail(user.Email); 67 | claims.AddName($"{user.FirstName} {user.LastName}"); 68 | claims.AddRoles(operationClaims.Select(c => c.Name).ToArray()); 69 | 70 | return claims; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /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.Helpers; 7 | using Core.Utilities.Interceptors; 8 | using Core.Utilities.Security.JWT; 9 | using DataAccess.Abstract; 10 | using DataAccess.Concrete.EntityFramework; 11 | using Microsoft.AspNetCore.Http; 12 | using System; 13 | using System.Collections.Generic; 14 | using System.Linq; 15 | using System.Text; 16 | using System.Threading.Tasks; 17 | 18 | namespace Business.DependencyResolvers.Autofac 19 | { 20 | public class AutofacBusinessModule : Module 21 | { 22 | protected override void Load(ContainerBuilder builder) 23 | { 24 | // IoC Yapısı Kurdum 25 | // For Brand 26 | builder.RegisterType().As().SingleInstance(); 27 | builder.RegisterType().As().SingleInstance(); 28 | // For Color 29 | builder.RegisterType().As().SingleInstance(); 30 | builder.RegisterType().As().SingleInstance(); 31 | // For Car 32 | builder.RegisterType().As().SingleInstance(); 33 | builder.RegisterType().As().SingleInstance(); 34 | // For User 35 | builder.RegisterType().As().SingleInstance(); 36 | builder.RegisterType().As().SingleInstance(); 37 | // For Customer 38 | builder.RegisterType().As().SingleInstance(); 39 | builder.RegisterType().As().SingleInstance(); 40 | // For Rental 41 | builder.RegisterType().As().SingleInstance(); 42 | builder.RegisterType().As().SingleInstance(); 43 | 44 | // For CarImage 45 | builder.RegisterType().As().SingleInstance(); 46 | builder.RegisterType().As().SingleInstance(); 47 | builder.RegisterType().As().SingleInstance(); 48 | 49 | // 50 | builder.RegisterType().As(); 51 | builder.RegisterType().As(); 52 | 53 | builder.RegisterType().As(); 54 | builder.RegisterType().As(); 55 | // 56 | builder.RegisterType().As().SingleInstance(); 57 | builder.RegisterType().As().SingleInstance(); 58 | 59 | var assembly = System.Reflection.Assembly.GetExecutingAssembly(); 60 | 61 | builder.RegisterAssemblyTypes(assembly).AsImplementedInterfaces() 62 | .EnableInterfaceInterceptors(new ProxyGenerationOptions() 63 | { 64 | Selector = new AspectInterceptorSelector() 65 | }).SingleInstance(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /DataAccess/Concrete/InMemory/InMemoryCarDal.cs: -------------------------------------------------------------------------------- 1 | using DataAccess.Abstract; 2 | using Entity.Concrete; 3 | using Entity.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Linq.Expressions; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace DataAccess.Concrete.InMemory 12 | { 13 | public class InMemoryCarDal : ICarDal 14 | { 15 | List _cars; 16 | 17 | public InMemoryCarDal() 18 | { 19 | _cars = new List { 20 | new Car() {Id=1,BrandId=1,ColorId=2,ModelYear=2014,DailyPrice=150,Description="Çicek Gibi Araba" }, 21 | new Car() {Id=2,BrandId=3,ColorId=1,ModelYear=2020,DailyPrice=300,Description="Param Olsaaaaa daaaaa ben binsemmmm" }, 22 | new Car() {Id=3,BrandId=4,ColorId=4,ModelYear=2021,DailyPrice=350,Description="Doktordan temiz" }, 23 | new Car() {Id=4,BrandId=2,ColorId=3,ModelYear=2013,DailyPrice=120,Description="Programcıdan Hafif Kırık" } 24 | }; 25 | Console.WriteLine("Sistem InMemory Alternatifine Geçti... SOLİD BEBEK GİBİ ÇALIŞIYOR YANİ HEEE"); 26 | } 27 | 28 | 29 | public void Add(Car car) 30 | { 31 | _cars.Add(car); 32 | } 33 | 34 | public void Delete(Car car) 35 | { 36 | Car carToDelete; 37 | 38 | carToDelete = _cars.SingleOrDefault(item => item.Id == car.Id); 39 | _cars.Remove(carToDelete); 40 | 41 | } 42 | 43 | public Car Get(Expression> filter) 44 | { 45 | throw new NotImplementedException(); 46 | } 47 | 48 | public List GetAll() 49 | { 50 | return _cars; 51 | } 52 | 53 | public List GetAll(Expression> filter = null) 54 | { 55 | throw new NotImplementedException(); 56 | } 57 | 58 | public List GetById(int id) 59 | { 60 | return _cars.Where(item => item.Id == id).ToList(); 61 | } 62 | 63 | public List GetCarDetailDtosWithBrandId(int id) 64 | { 65 | throw new NotImplementedException(); 66 | } 67 | 68 | public List GetCarDetailDtosWithColorId(int id) 69 | { 70 | throw new NotImplementedException(); 71 | } 72 | 73 | public List GetCarDetailDtosWithColorIdAndBrandId(int colorId, int brandId) 74 | { 75 | throw new NotImplementedException(); 76 | } 77 | 78 | public List GetCarDetails() 79 | { 80 | throw new NotImplementedException(); 81 | } 82 | 83 | public List GetCarDetailsDtoWithCarId(int carId) 84 | { 85 | throw new NotImplementedException(); 86 | } 87 | 88 | public void Update(Car car) 89 | { 90 | Car carToUpdate; 91 | 92 | carToUpdate = _cars.SingleOrDefault(item => item.Id == car.Id); 93 | 94 | carToUpdate.BrandId = car.BrandId; 95 | carToUpdate.ColorId = car.ColorId; 96 | carToUpdate.DailyPrice = car.DailyPrice; 97 | carToUpdate.Description = car.Description; 98 | carToUpdate.ModelYear = car.ModelYear; 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /RentACarProject.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31313.79 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entity", "Entity\Entity.csproj", "{A92CFD69-5D3B-40BE-8982-1D2D48FF6F87}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAccess", "DataAccess\DataAccess.csproj", "{855508A6-903D-4026-9B68-C6C04EEF1F3A}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Business", "Business\Business.csproj", "{A38CA290-0566-4A3C-A320-A477ACA672B2}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleUI", "ConsoleUI\ConsoleUI.csproj", "{015B96D8-6B7A-4965-915F-584031E7874C}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{B0DF1086-0615-4A58-8659-1A59C00FBEF5}" 15 | EndProject 16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebAPI", "WebAPI\WebAPI.csproj", "{FEEA9607-4F94-4884-90E7-F847BA837272}" 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 | {A92CFD69-5D3B-40BE-8982-1D2D48FF6F87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {A92CFD69-5D3B-40BE-8982-1D2D48FF6F87}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {A92CFD69-5D3B-40BE-8982-1D2D48FF6F87}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {A92CFD69-5D3B-40BE-8982-1D2D48FF6F87}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {855508A6-903D-4026-9B68-C6C04EEF1F3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {855508A6-903D-4026-9B68-C6C04EEF1F3A}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {855508A6-903D-4026-9B68-C6C04EEF1F3A}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {855508A6-903D-4026-9B68-C6C04EEF1F3A}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {A38CA290-0566-4A3C-A320-A477ACA672B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {A38CA290-0566-4A3C-A320-A477ACA672B2}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {A38CA290-0566-4A3C-A320-A477ACA672B2}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {A38CA290-0566-4A3C-A320-A477ACA672B2}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {015B96D8-6B7A-4965-915F-584031E7874C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {015B96D8-6B7A-4965-915F-584031E7874C}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {015B96D8-6B7A-4965-915F-584031E7874C}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {015B96D8-6B7A-4965-915F-584031E7874C}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {B0DF1086-0615-4A58-8659-1A59C00FBEF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {B0DF1086-0615-4A58-8659-1A59C00FBEF5}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {B0DF1086-0615-4A58-8659-1A59C00FBEF5}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {B0DF1086-0615-4A58-8659-1A59C00FBEF5}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {FEEA9607-4F94-4884-90E7-F847BA837272}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {FEEA9607-4F94-4884-90E7-F847BA837272}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {FEEA9607-4F94-4884-90E7-F847BA837272}.Release|Any CPU.ActiveCfg = Release|Any CPU 47 | {FEEA9607-4F94-4884-90E7-F847BA837272}.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 = {723FC2B5-3130-4B74-874F-57D9B48BE280} 54 | EndGlobalSection 55 | EndGlobal 56 | -------------------------------------------------------------------------------- /ConsoleUI/Program.cs: -------------------------------------------------------------------------------- 1 | using Business.Concrete; 2 | using Core.Utilities.Helpers; 3 | using DataAccess.Concrete.EntityFramework; 4 | using DataAccess.Concrete.InMemory; 5 | using Entity.Concrete; 6 | using System; 7 | using System.Collections.Generic; 8 | 9 | namespace ConsoleUI 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | //BrandTest(); 16 | //ColorTest(); 17 | //CarTest(); 18 | //RentalManager rentalManager = new RentalManager(new EfRentalDal()); 19 | //Rental rental = new Rental(); 20 | //Rental rental2 = new Rental(); 21 | //rental.CarId = 3; 22 | //rental.CustomerId = 2; 23 | //rental.RentDate = new DateTime(2015, 12, 25); 24 | //rental.ReturnDate = new DateTime(2016, 12, 25); 25 | //rental2.CarId = 1002; 26 | //rental2.CustomerId = 4; 27 | //rental2.RentDate = new DateTime(2015, 12, 25); 28 | 29 | 30 | 31 | //rentalManager.Add(rental2); 32 | 33 | 34 | 35 | 36 | //CarImageManager carImageManager = new CarImageManager(new EfCarImageDal(), new FileHelper()); 37 | 38 | //var sayi = carImageManager.IsOverflowCarImageCount(3); 39 | 40 | //Console.WriteLine(sayi.Message); 41 | 42 | } 43 | 44 | private static void CarTest() 45 | { 46 | //CarManager carManager = new CarManager(new EfCarDal()); 47 | //carManager.Add(new Car() { BrandId = 1, ColorId = 2, ModelYear = 2019, DailyPrice = 180.00m, Description = "Programcıdan Hafif Kırık" }); 48 | //carManager.Update(new Car() { Id = 1 ,BrandId = 1, ColorId = 2, ModelYear = 2019, DailyPrice = 180.00m, Description = "Bebek Gibi Araba" }); 49 | //carManager.Delete(new Car() { Id = 2}); 50 | //foreach (var car in carManager.GetAll()) 51 | //{ 52 | // Console.WriteLine(car.Description); 53 | //} 54 | //Console.WriteLine(carManager.GetById(3).DailyPrice); 55 | //var result = carManager.GetCarDetailsDto(); 56 | //foreach (var c in result.Data) 57 | //{ 58 | // Console.WriteLine(c.Id+" "+c.BrandName+" "+c.ColorName+" "+c.DailyPrice+" "); 59 | //} 60 | //Console.WriteLine(result.Message); 61 | } 62 | 63 | private static void ColorTest() 64 | { 65 | //ColorManager colorManager = new ColorManager(new EfColorDal()); 66 | 67 | //foreach (var color in colorManager.GetAll()) 68 | //{ 69 | // Console.WriteLine(color.Name); 70 | //} 71 | 72 | //Console.WriteLine(colorManager.GetById(1).Name); 73 | 74 | //colorManager.Add(new Color() { Name = "Mor" }); 75 | //colorManager.Update(new Color() { Id=3, Name = "UpdatedMor" }); 76 | //colorManager.Delete(new Color() { Id = 4}); 77 | } 78 | 79 | private static void BrandTest() 80 | { 81 | //BrandManager brandManager = new BrandManager(new EfBrandDal()); 82 | 83 | //foreach (var brand in brandManager.GetAll()) 84 | //{ 85 | // Console.WriteLine(brand.Name); 86 | //} 87 | 88 | //Console.WriteLine(brandManager.GetById(1).Name); 89 | 90 | //brandManager.Add(new Brand() { Name = "Audi" }); 91 | //brandManager.Update(new Brand() { Id=9 ,Name = "Lamborgini2" }); 92 | //brandManager.Delete(new Brand() { Id = 9, Name = "Lamborgini" }); 93 | 94 | 95 | 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Core/Utilities/Helpers/FileHelper.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Microsoft.AspNetCore.Http; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Core.Utilities.Helpers 11 | { 12 | public class FileHelper : IFileHelper 13 | { 14 | private static string _currentDirectory = Environment.CurrentDirectory + "\\wwwroot"; 15 | private static string _folderName = "\\images\\"; 16 | public void CheckDirectoryExist(string directory) 17 | { 18 | if (!Directory.Exists(directory)) 19 | { 20 | Directory.CreateDirectory(directory); 21 | } 22 | } 23 | 24 | public IResult CheckFileExist(IFormFile file) 25 | { 26 | if (file != null && file.Length > 0) 27 | { 28 | return new SuccessResult(); 29 | } 30 | return new ErrorResult(); 31 | } 32 | 33 | public IResult CheckFileTypeValid(string type) 34 | { 35 | if (type != ".jpeg" && type != ".png" && type != ".jpg") 36 | { 37 | return new ErrorResult("Bu tipte bir dosya yüklenemez."); 38 | } 39 | return new SuccessResult(); 40 | } 41 | 42 | public void CreateFile(string directory, IFormFile file) 43 | { 44 | using (FileStream fs = File.Create(directory)) 45 | { 46 | file.CopyTo(fs); 47 | fs.Flush(); 48 | } 49 | } 50 | 51 | public IResult Delete(string path) 52 | { 53 | DeleteOldFile((_currentDirectory + path).Replace("/", "\\")); 54 | return new SuccessResult(); 55 | } 56 | 57 | public void DeleteOldFile(string directory) 58 | { 59 | if (File.Exists(directory.Replace("/", "\\"))) 60 | { 61 | File.Delete(directory.Replace("/", "\\")); 62 | } 63 | } 64 | 65 | public IResult Update(IFormFile file, string imagePath) 66 | { 67 | var fileExists = CheckFileExist(file); 68 | if (fileExists.Message != null) 69 | { 70 | return new ErrorResult(fileExists.Message); 71 | } 72 | var type = Path.GetExtension(file.FileName); 73 | var typeValid = CheckFileTypeValid(type); 74 | var randomName = Guid.NewGuid().ToString(); 75 | 76 | if (typeValid == null) 77 | { 78 | return new ErrorResult(typeValid.Message); 79 | } 80 | CheckDirectoryExist(_currentDirectory + _folderName); 81 | CreateFile(_currentDirectory + _folderName + randomName + type, file); 82 | return new SuccessResult((_folderName + randomName + type).Replace("\\", "/")); 83 | } 84 | 85 | public IResult Upload(IFormFile file) 86 | { 87 | var fileExists = CheckFileExist(file); 88 | if (fileExists.Message != null) 89 | { 90 | return new ErrorResult(fileExists.Message); 91 | } 92 | var type = Path.GetExtension(file.FileName); 93 | var typeValid = CheckFileTypeValid(type); 94 | var randomName = Guid.NewGuid().ToString(); 95 | 96 | if (typeValid == null) 97 | { 98 | return new ErrorResult(typeValid.Message); 99 | } 100 | CheckDirectoryExist(_currentDirectory + _folderName); 101 | CreateFile(_currentDirectory + _folderName + randomName + type, file); 102 | return new SuccessResult((_folderName + randomName + type).Replace("\\", "/")); 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CarsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entity.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 CarsController : ControllerBase 15 | { 16 | ICarService _carService; 17 | 18 | public CarsController(ICarService carService) 19 | { 20 | _carService = carService; 21 | } 22 | 23 | [HttpGet("getall")] 24 | public IActionResult GetAll() 25 | { 26 | var result = _carService.GetAll(); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result); 32 | } 33 | [HttpGet("getbyid")] 34 | public IActionResult Get(int id) 35 | { 36 | var result = _carService.GetById(id); 37 | if (result.Success) 38 | { 39 | return Ok(result); 40 | } 41 | return BadRequest(result); 42 | } 43 | [HttpGet("getbybrandid")] 44 | public IActionResult GetByBrandId(int id) 45 | { 46 | var result = _carService.GetCarsByBrandId(id); 47 | if (result.Success) 48 | { 49 | return Ok(result); 50 | } 51 | return BadRequest(result); 52 | } 53 | [HttpGet("getbycolorid")] 54 | public IActionResult GetByColorId(int id) 55 | { 56 | var result = _carService.GetCarsByColorId(id); 57 | if (result.Success) 58 | { 59 | return Ok(result); 60 | } 61 | return BadRequest(result); 62 | } 63 | 64 | [HttpGet("getbycoloridandbrandid")] 65 | public IActionResult GetCarBrandIdAndColorId(int colorId,int brandId) 66 | { 67 | var result = _carService.GetCarsDetailDtoByBrandAndColorId(brandId, colorId); 68 | if (result.Success) 69 | { 70 | return Ok(result); 71 | } 72 | return BadRequest(result); 73 | } 74 | 75 | [HttpGet("getcardetailsbydto")] 76 | public IActionResult GetDetailsByDto() 77 | { 78 | var result = _carService.GetCarDetailsDto(); 79 | if (result.Success) 80 | { 81 | return Ok(result); 82 | } 83 | return BadRequest(result); 84 | } 85 | 86 | [HttpGet("getcardetailsdtobycarid")] 87 | public IActionResult GetCarDetailsDtoByCarId(int id) 88 | { 89 | var result = _carService.GetCarsDetailDtoByCarId(id); 90 | if (result.Success) 91 | { 92 | return Ok(result); 93 | } 94 | return BadRequest(result); 95 | } 96 | 97 | [HttpPost("add")] 98 | public IActionResult Add(Car car) 99 | { 100 | var result = _carService.Add(car); 101 | if (result.Success) 102 | { 103 | return Ok(result); 104 | } 105 | return BadRequest(result); 106 | } 107 | 108 | [HttpPost("update")] 109 | public IActionResult Update(Car car) 110 | { 111 | var result = _carService.Update(car); 112 | if (result.Success) 113 | { 114 | return Ok(result); 115 | } 116 | return BadRequest(result); 117 | } 118 | 119 | [HttpPost("delete")] 120 | public IActionResult Delete(Car car) 121 | { 122 | var result = _carService.Delete(car); 123 | if (result.Success) 124 | { 125 | return Ok(result); 126 | } 127 | return BadRequest(result); 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /Business/Concrete/CarManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.BusinessAspects.Autofac; 3 | using Business.Constraints; 4 | using Business.ValidationsRules.FluentValidation; 5 | using Core.Aspects.Autofac.Caching; 6 | using Core.Aspects.Autofac.Validation; 7 | using Core.Utilities.Results; 8 | using DataAccess.Abstract; 9 | using Entity.Concrete; 10 | using Entity.DTOs; 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Linq; 14 | using System.Text; 15 | using System.Threading; 16 | using System.Threading.Tasks; 17 | 18 | namespace Business.Concrete 19 | { 20 | public class CarManager : ICarService 21 | { 22 | ICarDal _carDal; 23 | 24 | public CarManager(ICarDal carDal) 25 | { 26 | _carDal = carDal; 27 | } 28 | 29 | [SecuredOperation("car.add,admin")] 30 | [ValidationAspect(typeof(CarValidator))] 31 | [CacheRemoveAspect("ICarService.Get")] 32 | public IResult Add(Car car) 33 | { 34 | 35 | _carDal.Add(car); 36 | return new SuccessResult(Messages.CarAdded); 37 | } 38 | 39 | [CacheRemoveAspect("ICarService.Get")] 40 | public IResult Delete(Car car) 41 | { 42 | try 43 | { 44 | _carDal.Delete(car); 45 | return new SuccessResult(Messages.CarDeleted); 46 | } 47 | catch (Exception) 48 | { 49 | 50 | return new ErrorResult(Messages.CarCantDeleted); 51 | } 52 | } 53 | 54 | [CacheAspect] 55 | public IDataResult> GetAll() 56 | { 57 | return new SuccessDataResult>(_carDal.GetAll(), Messages.CarsListed); 58 | } 59 | 60 | //public IDataResult> GetCarsByBrandId(int id) 61 | //{ 62 | // return new SuccessDataResult>(_carDal.GetAll(car => car.BrandId == id), Messages.CarListedByBrand); 63 | //} 64 | 65 | [CacheAspect] 66 | public IDataResult> GetCarsByBrandId(int id) 67 | { 68 | return new SuccessDataResult>(_carDal.GetCarDetailDtosWithBrandId(id), Messages.CarListedByBrand); 69 | } 70 | 71 | //[CacheAspect] 72 | public IDataResult> GetCarDetailsDto() 73 | { 74 | 75 | return new SuccessDataResult>(_carDal.GetCarDetails(), Messages.CarsListedDetailDto); 76 | } 77 | //public IDataResult> GetCarsByColorId(int id) 78 | //{ 79 | // return new SuccessDataResult>(_carDal.GetAll(car => car.ColorId == id), Messages.CarListedByColor); 80 | //} 81 | 82 | [CacheAspect] 83 | public IDataResult> GetCarsByColorId(int id) 84 | { 85 | return new SuccessDataResult>(_carDal.GetCarDetailDtosWithColorId(id), Messages.CarListedByColor); 86 | } 87 | 88 | [CacheRemoveAspect("ICarService.Get")] 89 | public IResult Update(Car car) 90 | { 91 | try 92 | { 93 | _carDal.Update(car); 94 | return new SuccessResult(Messages.CarUpdated); 95 | } 96 | catch (Exception) 97 | { 98 | 99 | return new ErrorResult(Messages.CarCantUpdated); 100 | } 101 | } 102 | 103 | [CacheAspect] 104 | public IDataResult GetById(int id) 105 | { 106 | return new SuccessDataResult(_carDal.Get(car => car.Id == id), Messages.CarListed); 107 | 108 | } 109 | 110 | [CacheAspect] 111 | public IDataResult> GetCarsDetailDtoByCarId(int id) 112 | { 113 | return new SuccessDataResult>(_carDal.GetCarDetailsDtoWithCarId(id), Messages.CarListed); 114 | } 115 | 116 | 117 | [CacheAspect] 118 | public IDataResult> GetCarsDetailDtoByBrandAndColorId(int brandId, int colorId) 119 | { 120 | return new SuccessDataResult>(_carDal.GetCarDetailDtosWithColorIdAndBrandId(colorId,brandId), Messages.CarListed); 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /Business/Concrete/RentalManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constraints; 3 | using Business.ValidationsRules.FluentValidation; 4 | using Core.Aspects.Autofac.Caching; 5 | using Core.Aspects.Autofac.Validation; 6 | using Core.Utilities.Business; 7 | using Core.Utilities.Results; 8 | using DataAccess.Abstract; 9 | using Entity.Concrete; 10 | using Entity.DTOs; 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Linq; 14 | using System.Text; 15 | using System.Threading.Tasks; 16 | 17 | namespace Business.Concrete 18 | { 19 | public class RentalManager : IRentalService 20 | { 21 | IRentalDal _rentalDal; 22 | 23 | 24 | public RentalManager(IRentalDal rentalDal) 25 | { 26 | _rentalDal = rentalDal; 27 | } 28 | 29 | [ValidationAspect(typeof(RentalValidator))] 30 | public IResult Add(Rental rental) 31 | { 32 | IResult result2 = BusinessRules.Run(controlDelivered(rental)); 33 | 34 | if (result2 != null) 35 | { 36 | return result2; 37 | } 38 | _rentalDal.Add(rental); 39 | return new SuccessResult(Messages.RentalAdded); 40 | 41 | 42 | } 43 | 44 | [CacheRemoveAspect("ICarService.Get")] 45 | public IResult Delete(Rental rental) 46 | { 47 | try 48 | { 49 | _rentalDal.Delete(rental); 50 | return new SuccessResult(Messages.RentalDeleted); 51 | } 52 | catch (Exception) 53 | { 54 | 55 | return new ErrorResult(Messages.RentalCantDeledet); 56 | } 57 | } 58 | public IDataResult> GetRentalDetails() 59 | { 60 | return new SuccessDataResult>(_rentalDal.GetRentalDetails(), Messages.RentalListed); 61 | } 62 | 63 | public IDataResult> GetAll() 64 | { 65 | return new SuccessDataResult>(_rentalDal.GetAll(), Messages.RentalsListed); 66 | } 67 | 68 | public IDataResult GetByCustomerId(int id) 69 | { 70 | return new SuccessDataResult(_rentalDal.Get(rental => rental.UserId == id), Messages.RentalListed); 71 | } 72 | 73 | public IResult Update(Rental rental) 74 | { 75 | try 76 | { 77 | _rentalDal.Update(rental); 78 | return new SuccessResult(Messages.RentalUpdated); 79 | } 80 | catch (Exception) 81 | { 82 | 83 | return new ErrorResult(Messages.RentalCantUpdated); 84 | } 85 | } 86 | 87 | [CacheRemoveAspect("ICarService.Get")] 88 | public IResult AddMultiple(Rental[] rentals) 89 | { 90 | //bool hataliMi = false; 91 | 92 | List successRentals = new List(); 93 | 94 | foreach (var rental in rentals) 95 | { 96 | var results = _rentalDal.GetAll(re => re.CarId == rental.CarId); 97 | 98 | foreach (var result in results) 99 | { 100 | if ((rental.RentDate >= result.RentDate && rental.RentDate <= result.ReturnDate) || (rental.ReturnDate >= result.RentDate && rental.RentDate <= result.ReturnDate)) 101 | { 102 | return new ErrorResult("Kiralamaz aga"); 103 | } 104 | 105 | } 106 | if (rental.ReturnDate <= rental.RentDate) 107 | { 108 | return new ErrorResult("Aga sen Nolan mısın arabayı bugün alıp, dün teslim ediyorsun ?"); 109 | } 110 | 111 | successRentals.Add(rental); 112 | 113 | } 114 | foreach (var successRental in successRentals) 115 | { 116 | _rentalDal.Add(successRental); 117 | } 118 | return new SuccessResult(Messages.RentalAdded); 119 | 120 | } 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | public IResult controlDelivered(Rental rental) 131 | { 132 | var results = _rentalDal.GetAll(re => re.CarId == rental.CarId); 133 | 134 | foreach (var result in results) 135 | { 136 | if ((rental.RentDate >= result.RentDate && rental.RentDate <= result.ReturnDate) || (rental.ReturnDate >= result.RentDate && rental.RentDate <= result.ReturnDate)) 137 | { 138 | return new ErrorResult("Kiralamaz aga"); 139 | } 140 | 141 | } 142 | if (rental.ReturnDate <= rental.RentDate) 143 | { 144 | return new ErrorResult("Aga sen Nolan mısın arabayı bugün alıp, dün teslim ediyorsun ?"); 145 | } 146 | return new SuccessResult(); 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /Business/Concrete/CarImageManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constraints; 3 | using Core.Utilities.Business; 4 | using Core.Utilities.Helpers; 5 | using Core.Utilities.Results; 6 | using DataAccess.Abstract; 7 | using Entity.Concrete; 8 | using Entity.DTOs; 9 | using Microsoft.AspNetCore.Http; 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Linq; 13 | using System.Text; 14 | using System.Threading.Tasks; 15 | 16 | namespace Business.Concrete 17 | { 18 | 19 | public class CarImageManager : ICarImageService 20 | { 21 | ICarImageDal _carImageDal; 22 | IFileHelper _fileHelper; 23 | 24 | public CarImageManager(ICarImageDal carImageDal, IFileHelper fileHelper) 25 | { 26 | _carImageDal = carImageDal; 27 | _fileHelper = fileHelper; 28 | } 29 | 30 | public IResult Add(CarImage carImage, IFormFile file) 31 | { 32 | IResult result = BusinessRules.Run( 33 | IsOverflowCarImageCount(carImage.CarId)); 34 | 35 | if (result != null) 36 | { 37 | return new ErrorResult(result.Message); 38 | } 39 | 40 | var imageResult = _fileHelper.Upload(file); 41 | if (!imageResult.Success) 42 | { 43 | return new ErrorResult(imageResult.Message); 44 | } 45 | carImage.ImagePath = imageResult.Message; 46 | carImage.Date = DateTime.Now; 47 | _carImageDal.Add(carImage); 48 | return new SuccessResult(Messages.CarImageAdded); 49 | } 50 | 51 | 52 | 53 | public IResult Delete(CarImage carImage) 54 | { 55 | try 56 | { 57 | var imageDelete = _carImageDal.Get(c => c.Id == carImage.Id); 58 | if (imageDelete == null) 59 | { 60 | return new ErrorResult(Messages.CarImageNotFound); 61 | } 62 | _carImageDal.Delete(carImage); 63 | 64 | return new SuccessResult(Messages.CarImageDeleted); 65 | } 66 | catch (Exception) 67 | { 68 | 69 | return new ErrorResult("Resim Silinemedi"); 70 | } 71 | 72 | } 73 | 74 | public IDataResult> GetAll() 75 | { 76 | return new SuccessDataResult>(_carImageDal.GetAll(), Messages.CarImagesListed); 77 | } 78 | 79 | public IDataResult> GetByCarId(int carId) 80 | { 81 | var result = BusinessRules.Run(ShowDefaultImage(carId)); 82 | if (result == null) 83 | { 84 | return new SuccessDataResult>(_carImageDal.GetAll(c => c.CarId == carId)); 85 | 86 | } 87 | return new ErrorDataResult>("Hata"); 88 | 89 | 90 | 91 | } 92 | 93 | public IDataResult GetById(int id) 94 | { 95 | return new SuccessDataResult(_carImageDal.Get(c => c.Id == id), Messages.CarImageListed); 96 | } 97 | 98 | public IResult Update(CarImage carImage, IFormFile file) 99 | { 100 | var imageDelete = _carImageDal.Get(c => c.Id == carImage.Id); 101 | if (imageDelete == null) 102 | { 103 | return new ErrorResult("Bulunamadı"); 104 | } 105 | var updatedFile = _fileHelper.Update(file, imageDelete.ImagePath); 106 | if (!updatedFile.Success) 107 | { 108 | return new ErrorResult(updatedFile.Message); 109 | } 110 | carImage.ImagePath = updatedFile.Message; 111 | _carImageDal.Update(carImage); 112 | 113 | return new SuccessResult(Messages.CarImageUpdated); 114 | } 115 | 116 | public IResult IsOverflowCarImageCount(int carId) 117 | { 118 | var result = _carImageDal.GetAll(im => im.CarId == carId); 119 | 120 | if (result.Count >= 5) 121 | { 122 | return new ErrorResult(Messages.OverflowCarImageMessage); 123 | } 124 | 125 | return new SuccessResult(); 126 | 127 | } 128 | private IResult ShowDefaultImage(int carId) 129 | { 130 | 131 | 132 | try 133 | { 134 | string path = @"\images\default.png"; 135 | var result = _carImageDal.GetAll(c => c.CarId == carId).Any(); 136 | if (result) 137 | { 138 | List carImages = new List(); 139 | carImages.Add(new CarImage { CarId = carId, Date = DateTime.Now, ImagePath = path }); 140 | return new SuccessDataResult>(carImages); 141 | } 142 | } 143 | catch (Exception) 144 | { 145 | 146 | return new ErrorDataResult>("Hata"); 147 | } 148 | return new SuccessDataResult>(_carImageDal.GetAll(c => c.CarId == carId).ToList()); 149 | 150 | 151 | 152 | 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /Business/Constraints/Messages.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.Serialization; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Business.Constraints 9 | { 10 | public static class Messages 11 | { 12 | 13 | // Brand Manager Messages 14 | public static string BrandAdded = "Marka Başarı ile Eklendi"; 15 | public static string BrandDeleted = "Marka Başarı ile Silindi"; 16 | public static string BrandCantDeledet = "Marka Silinemedi... Böyle Birşey Artık Olmayabilir."; 17 | public static string BrandsListed = "Markalar Başarı ile Listelendi"; 18 | public static string BrandListed = "Marka Başarı ile Getirildi"; 19 | public static string BrandUpdated ="Marka Başarı ile Güncellendi"; 20 | public static string BrandCantUpdated = "Marka Güncellenemedi... Böyle Birşey Artık Olmayabilir"; 21 | // End of Brand Manager Messages 22 | // Color Manager Messages 23 | public static string ColorAdded = "Renk Başarı ile Eklendi"; 24 | public static string ColorDeleted = "Renk Başarı ile Silindi"; 25 | public static string ColorCantDeleted = "Renk Silinemedi... Böyle Birşey Artık Olmayabilir."; 26 | public static string ColorsListed = "Renkler Başarı ile Listelendi"; 27 | public static string ColorNotFound = "Renk Bulunamadı"; 28 | public static string ColorListed = "Renk Başarı ile Getirildi"; 29 | public static string ColorUpdated = "Renk Başarı ile Güncellendi"; 30 | public static string ColorCantUpdated = "Renk Güncellenemedi... Böyle Birşey Artık Olmayabilir."; 31 | // End of Color Manager Messages 32 | // Car Manager Messages 33 | public static string CarAdded = "Araba Başarı ile Eklendi"; 34 | public static string CarDescInvalidLetterLenght = "Araç Açıklaması 2 Karakterden Büyük Olmalıdır.\n "; 35 | public static string CarPriceInvalidCost = "Araç Günlük Fiyatı 0 liradan den Fazla Olmalıdır."; 36 | public static string CarDeleted = "Araba Başarı ile Silindi"; 37 | public static string CarCantDeleted = "Araba Silinemedi... Böyle Birşey Artık Olmayabilir."; 38 | public static string CarListed = "Araba Başarı ile Getirildi"; 39 | public static string CarsListed = "Araba Başarı ile Listelendi"; 40 | public static string CarListedByBrand = "Araba Başarı ile Listelendi"; 41 | public static string CarListedByColor = "Araba Başarı ile Listelendi"; 42 | public static string CarUpdated = "Araba Başarı ile Güncellendi"; 43 | public static string CarCantUpdated = "Araba Güncellenemedi... Böyle Birşey Artık Olmayabilir."; 44 | public static string CarsListedDetailDto = "Arabalar Başarı ile Listelendi"; 45 | // End of Car Manager Messages 46 | // User Manager Messages 47 | public static string UserAdded = "Kullanıcı Başarı ile Eklendi"; 48 | public static string UserDeleted = "Kullanıcı Başarı ile Silindi"; 49 | public static string UserCantDeledet = "Kullanıcı Silinemedi... Böyle Birşey Artık Olmayabilir."; 50 | public static string UserUpdated = "Kullanıcı Başarı ile Güncellendi"; 51 | public static string UserCantUpdated = "Kullanıcı Güncellenemedi... Böyle Birşey Artık Olmayabilir."; 52 | public static string UsersListed = "Kullanıcılar Başarı ile Listelendi"; 53 | public static string UserListed = "Kullanıcı Başarı ile Getirildi"; 54 | // End of User Manager Messages 55 | // Customer Manager Messages 56 | public static string CustomerAdded = "Müşteri Başarı ile Eklendi"; 57 | public static string CustomerDeleted = "Müşteri Başarı ile Silindi"; 58 | public static string CustomerCantDeledet = "Müşteri Silinemedi... Böyle Birşey Artık Olmayabilir."; 59 | public static string CustomerUpdated = "Müşteri Başarı ile Güncellendi"; 60 | public static string CustomerCantUpdated = "Müşteri Güncellenemedi... Böyle Birşey Artık Olmayabilir."; 61 | public static string CustomersListed = "Müşteriler Başarı ile Listelendi"; 62 | public static string CustomerListed = "Müşteri Başarı ile Getirildi"; 63 | // End of Customer Manager Messages 64 | // Rental Manager Messages 65 | public static string RentalAdded = "Kiralama Başarı ile Eklendi"; 66 | public static string RentalDeleted = "Kiralama Başarı ile Silindi"; 67 | public static string RentalCantDeledet = "Kiralama Silinemedi... Böyle Birşey Artık Olmayabilir."; 68 | public static string RentalsListed = "Kiralamalar Başarı ile Listelendi"; 69 | public static string RentalListed = "Kiralama Başarı ile Getirildi"; 70 | public static string RentalUpdated = "Kiralama Başarı ile Güncellendi"; 71 | public static string RentalCantUpdated = "Kiralama Güncellenemedi... Böyle Birşey Artık Olmayabilir."; 72 | public static string RentalProblem = "Araç Kiralanamadı... Araç yok"; 73 | // End of Rental Manager Messages 74 | // Car Image Manager Messages 75 | public static string OverflowCarImageMessage = "Aracın 5 ten fazla Resmi olamaz"; 76 | public static string CarImageAdded = "Araç Resmi Başarı İle Eklendi"; 77 | public static string CarImageNotFound = "Resim Bulunamadı"; 78 | public static string CarImageDeleted = "Araç Resmi Silindi"; 79 | public static string CarImagesListed = "Araç Resimleri Listeleni"; 80 | public static string CarImageListed = "Araç Resimi Getirildi"; 81 | public static string CarImageUpdated = "Araç Resmi Güncellendi"; 82 | public static string AuthorizationDenied = "Yetkiniz Yok"; 83 | public static string paymentAdded = "Ödeme Eklendi"; 84 | public static string paymentDeleted = "Ödeme Silindi"; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCarDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entity.Concrete; 4 | using Entity.DTOs; 5 | using Microsoft.EntityFrameworkCore; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Linq.Expressions; 10 | using System.Text; 11 | using System.Threading.Tasks; 12 | 13 | namespace DataAccess.Concrete.EntityFramework 14 | { 15 | public class EfCarDal : EfEntityRepositoryBase, ICarDal 16 | { 17 | public List GetCarDetails() 18 | { 19 | using (RentACarContext context = new RentACarContext()) 20 | { 21 | var result = from ca in context.Cars 22 | join co in context.Colors 23 | on ca.ColorId equals co.Id 24 | join br in context.Brands 25 | on ca.BrandId equals br.Id 26 | //join ci in context.CarImages 27 | //on ca.Id equals ci.CarId 28 | //join re in context.Rentals 29 | //on ca.Id equals re.CarId 30 | select new CarDetailDto 31 | { 32 | Id = ca.Id, 33 | BrandName = br.Name, 34 | ColorName = co.Name, 35 | DailyPrice = ca.DailyPrice, 36 | Description = ca.Description, 37 | Model = ca.Model, 38 | ModelYear = ca.ModelYear, 39 | ImagePath = (from x in context.CarImages where x.CarId == ca.Id select x.ImagePath).FirstOrDefault(), 40 | //ReturnDate = re.ReturnDate 41 | ReturnDate = (from y in context.Rentals orderby y.ReturnDate descending where y.CarId == ca.Id select y.ReturnDate.ToString("MM/dd/yyyy")).FirstOrDefault() 42 | }; 43 | return result.ToList(); 44 | } 45 | } 46 | public List GetCarDetailDtosWithColorIdAndBrandId(int colorId, int brandId) 47 | { 48 | using (RentACarContext context = new RentACarContext()) 49 | { 50 | var result = from ca in context.Cars 51 | join co in context.Colors 52 | on ca.ColorId equals co.Id 53 | where co.Id == colorId 54 | join br in context.Brands 55 | on ca.BrandId equals br.Id 56 | where br.Id == brandId 57 | //join ci in context.CarImages 58 | //on ca.Id equals ci.CarId 59 | //join re in context.Rentals 60 | //on ca.Id equals re.CarId 61 | select new CarDetailDto 62 | { 63 | Id = ca.Id, 64 | BrandName = br.Name, 65 | ColorName = co.Name, 66 | DailyPrice = ca.DailyPrice, 67 | Description = ca.Description, 68 | ModelYear = ca.ModelYear, 69 | Model = ca.Model, 70 | ImagePath = (from x in context.CarImages where x.CarId == ca.Id select x.ImagePath).FirstOrDefault(), 71 | //ReturnDate = re.ReturnDate 72 | ReturnDate = (from y in context.Rentals orderby y.ReturnDate descending where y.CarId == ca.Id select y.ReturnDate.ToString("MM/dd/yyyy")).FirstOrDefault() 73 | }; 74 | return result.ToList(); 75 | } 76 | } 77 | 78 | public List GetCarDetailDtosWithBrandId(int id) 79 | { 80 | 81 | using (RentACarContext context = new RentACarContext()) 82 | { 83 | var result = from ca in context.Cars 84 | join co in context.Colors 85 | on ca.ColorId equals co.Id 86 | join br in context.Brands 87 | on ca.BrandId equals br.Id where br.Id == id 88 | select new CarDetailDto 89 | { 90 | Id = ca.Id, 91 | BrandName = br.Name, 92 | ColorName = co.Name, 93 | DailyPrice = ca.DailyPrice, 94 | Description = ca.Description, 95 | ModelYear = ca.ModelYear, 96 | Model = ca.Model, 97 | ImagePath = (from x in context.CarImages where x.CarId == ca.Id select x.ImagePath).FirstOrDefault(), 98 | ReturnDate = (from y in context.Rentals orderby y.ReturnDate descending where y.CarId == ca.Id select y.ReturnDate.ToString("MM/dd/yyyy")).FirstOrDefault() 99 | 100 | }; 101 | 102 | return result.ToList(); 103 | } 104 | 105 | 106 | 107 | 108 | } 109 | 110 | public List GetCarDetailDtosWithColorId(int id) 111 | { 112 | using (RentACarContext context = new RentACarContext()) 113 | { 114 | var result = from ca in context.Cars 115 | join co in context.Colors 116 | on ca.ColorId equals co.Id where co.Id == id 117 | join br in context.Brands 118 | on ca.BrandId equals br.Id 119 | select new CarDetailDto 120 | { 121 | Id = ca.Id, 122 | BrandName = br.Name, 123 | ColorName = co.Name, 124 | DailyPrice = ca.DailyPrice, 125 | Description = ca.Description, 126 | ModelYear = ca.ModelYear, 127 | Model = ca.Model, 128 | ImagePath = (from x in context.CarImages where x.CarId == ca.Id select x.ImagePath).FirstOrDefault(), 129 | ReturnDate = (from y in context.Rentals orderby y.ReturnDate descending where y.CarId == ca.Id select y.ReturnDate.ToString("MM/dd/yyyy")).FirstOrDefault() 130 | 131 | }; 132 | 133 | return result.ToList(); 134 | } 135 | } 136 | 137 | public List GetCarDetailsDtoWithCarId(int carId) 138 | { 139 | using (RentACarContext context = new RentACarContext()) 140 | { 141 | var result = from ca in context.Cars where ca.Id == carId 142 | join co in context.Colors 143 | on ca.ColorId equals co.Id 144 | join br in context.Brands 145 | on ca.BrandId equals br.Id 146 | select new CarDetailDto 147 | { 148 | Id = ca.Id, 149 | BrandName = br.Name, 150 | ColorName = co.Name, 151 | DailyPrice = ca.DailyPrice, 152 | Description = ca.Description, 153 | ModelYear = ca.ModelYear, 154 | Model = ca.Model, 155 | ReturnDate = (from y in context.Rentals orderby y.ReturnDate descending where y.CarId == ca.Id select y.ReturnDate.ToString("MM/dd/yyyy")).FirstOrDefault() 156 | 157 | 158 | }; 159 | 160 | return result.ToList(); 161 | } 162 | } 163 | 164 | 165 | 166 | } 167 | } 168 | --------------------------------------------------------------------------------