├── WebAPI ├── Program.cs ├── Startup.cs ├── wwwroot │ └── Images │ │ ├── 23abfd2e-85c6-4695-bc2a-96fa847f53ad.jpg │ │ ├── 307d26a1-6bc9-4eab-b449-2c5bff6a9840.jpg │ │ ├── a21b838c-e8a1-4772-9ff1-3570cb560b51.jpg │ │ ├── adcc6cbd-1122-479e-827c-e79da723bf6b.jpg │ │ ├── be4ab371-47d7-4306-b7e9-1dd3a50c09bd.jpg │ │ ├── d9656b9b-cc7f-44d7-b75f-56acef6f66bb.jpg │ │ ├── e9732c85-cac7-497a-91d0-cef11a65febd.jpg │ │ └── f87805c8-b8c0-4b02-8577-e923761b4c0e.jpg ├── appsettings.Development.json ├── Models │ └── CarImageModel.cs ├── WeatherForecast.cs ├── appsettings.json ├── WebAPI.csproj ├── Properties │ └── launchSettings.json └── Controllers │ ├── WeatherForecastController.cs │ ├── AuthController.cs │ ├── UsersController.cs │ ├── BrandsController.cs │ ├── ColorsController.cs │ ├── RentalsController.cs │ ├── CustomersController.cs │ ├── CarImagesController.cs │ └── CarsController.cs ├── Core ├── Entities │ ├── IDto.cs │ ├── IEntity.cs │ └── Concrete │ │ ├── OperationClaim.cs │ │ ├── UserOperationClaim.cs │ │ └── User.cs ├── Utilities │ ├── IoC │ │ ├── ICoreModule.cs │ │ └── ServiceTool.cs │ ├── Security │ │ ├── JWT │ │ │ ├── AccessToken.cs │ │ │ ├── ITokenHelper.cs │ │ │ ├── TokenOptions.cs │ │ │ └── JwtHelper.cs │ │ ├── Encryption │ │ │ ├── SecurityKeyHelper.cs │ │ │ └── SigningCredentialsHelper.cs │ │ └── Hashing │ │ │ └── HashingHelper.cs │ ├── Results │ │ ├── Abstract │ │ │ ├── IDataResult.cs │ │ │ └── IResult.cs │ │ └── Concrete │ │ │ ├── ErrorResult.cs │ │ │ ├── SuccessResult.cs │ │ │ ├── DataResult.cs │ │ │ ├── Result.cs │ │ │ ├── SuccessDataResult.cs │ │ │ └── ErrorDataResult.cs │ ├── MethodInterceptionBaseAttribute.cs │ ├── Business │ │ └── BusinessRules.cs │ ├── AspectInterceptorSelector.cs │ ├── MethodInterception.cs │ └── Helpers │ │ └── FileHelper.cs ├── CrossCuttingConcerns │ ├── Caching │ │ ├── ICacheManager.cs │ │ └── Microsoft │ │ │ └── MemoryCacheManager.cs │ └── Validation │ │ └── ValidationTool.cs ├── Extensions │ ├── ServiceCollectionExtensions.cs │ ├── ClaimsPrincipalExtensions.cs │ └── ClaimExtensions.cs ├── DependencyResolvers │ └── CoreModule.cs ├── DataAccess │ ├── IEntityRepository.cs │ └── EntityFramework │ │ └── EfEntityRepositoryBase.cs ├── Aspects │ └── Autofac │ │ ├── Caching │ │ ├── CacheRemoveAspect.cs │ │ └── CacheAspect.cs │ │ ├── Transaction │ │ └── TransactionScopeAspect.cs │ │ ├── Performance │ │ └── PerformanceAspect.cs │ │ └── Validation │ │ └── ValidationAspect.cs └── Core.csproj ├── Entities ├── DTOs │ ├── IFilterDto.cs │ ├── UserForLoginDto.cs │ ├── UserForRegisterDto.cs │ ├── CustomerDetailDto.cs │ ├── CarDetailFilterDto.cs │ └── CarDetailDto.cs ├── Concrete │ ├── Brand.cs │ ├── Color.cs │ ├── Customer.cs │ ├── Rental.cs │ ├── CarImage.cs │ └── Car.cs └── Entities.csproj ├── SQLQuery4.sql ├── DataAccess ├── Abstract │ ├── IBrandDal.cs │ ├── IColorDal.cs │ ├── IRentalDal.cs │ ├── ICustomerDal.cs │ ├── ICarImageDal.cs │ ├── IUserDal.cs │ └── ICarDal.cs ├── Concrete │ ├── EntityFrameWork │ │ ├── EfCarImageDal.cs │ │ ├── EfCustomerDal.cs │ │ ├── EfBrandDal.cs │ │ ├── EfColorDal.cs │ │ ├── EfRentalDal.cs │ │ ├── EfUserDal.cs │ │ ├── ReCapDatabaseCotext.cs │ │ └── EfCarDal.cs │ └── InMemoryCarDal.cs └── DataAccess.csproj ├── SQLQuery1.sql ├── Business ├── ValidationRules │ └── FluentValidation │ │ ├── BrandValidator.cs │ │ ├── ColorValidator.cs │ │ ├── RentalValidator.cs │ │ └── CarValidator.cs ├── Abstract │ ├── IBrandService.cs │ ├── IColorService.cs │ ├── IRentalService.cs │ ├── ICustomerService.cs │ ├── IAuthService.cs │ ├── IUserService.cs │ ├── ICarImageService.cs │ └── ICarService.cs ├── Business.csproj ├── BusinessAspect │ └── SecuredOperation.cs ├── Constants │ └── Messages.cs ├── Concrete │ ├── BrandManager.cs │ ├── ColorManager.cs │ ├── CustomerManager.cs │ ├── RentalManager.cs │ ├── UserManager.cs │ ├── AuthManager.cs │ ├── CarManager.cs │ └── CarImageManager.cs └── DependencyResolvers │ └── Autofac │ └── AutofacBusinessModule.cs ├── ConsoleUI ├── ConsoleUI.csproj └── Program.cs ├── SQLQuery3.sql ├── SQLQuerysecurity.sql ├── SQLQuery2Recap.sql ├── SQLQuery2.sql ├── .gitattributes ├── ReCapProject.sln ├── .editorconfig ├── .gitignore └── README.md /WebAPI/Program.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kadernur/ReCapProject/HEAD/WebAPI/Program.cs -------------------------------------------------------------------------------- /WebAPI/Startup.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kadernur/ReCapProject/HEAD/WebAPI/Startup.cs -------------------------------------------------------------------------------- /Core/Entities/IDto.cs: -------------------------------------------------------------------------------- 1 | namespace Core 2 | { 3 | public interface IDto 4 | { 5 | 6 | } 7 | } -------------------------------------------------------------------------------- /Entities/DTOs/IFilterDto.cs: -------------------------------------------------------------------------------- 1 | namespace Entities.DTOs 2 | { 3 | public interface IFilterDto 4 | { 5 | 6 | } 7 | } -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/23abfd2e-85c6-4695-bc2a-96fa847f53ad.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kadernur/ReCapProject/HEAD/WebAPI/wwwroot/Images/23abfd2e-85c6-4695-bc2a-96fa847f53ad.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/307d26a1-6bc9-4eab-b449-2c5bff6a9840.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kadernur/ReCapProject/HEAD/WebAPI/wwwroot/Images/307d26a1-6bc9-4eab-b449-2c5bff6a9840.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/a21b838c-e8a1-4772-9ff1-3570cb560b51.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kadernur/ReCapProject/HEAD/WebAPI/wwwroot/Images/a21b838c-e8a1-4772-9ff1-3570cb560b51.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/adcc6cbd-1122-479e-827c-e79da723bf6b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kadernur/ReCapProject/HEAD/WebAPI/wwwroot/Images/adcc6cbd-1122-479e-827c-e79da723bf6b.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/be4ab371-47d7-4306-b7e9-1dd3a50c09bd.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kadernur/ReCapProject/HEAD/WebAPI/wwwroot/Images/be4ab371-47d7-4306-b7e9-1dd3a50c09bd.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/d9656b9b-cc7f-44d7-b75f-56acef6f66bb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kadernur/ReCapProject/HEAD/WebAPI/wwwroot/Images/d9656b9b-cc7f-44d7-b75f-56acef6f66bb.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/e9732c85-cac7-497a-91d0-cef11a65febd.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kadernur/ReCapProject/HEAD/WebAPI/wwwroot/Images/e9732c85-cac7-497a-91d0-cef11a65febd.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/f87805c8-b8c0-4b02-8577-e923761b4c0e.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kadernur/ReCapProject/HEAD/WebAPI/wwwroot/Images/f87805c8-b8c0-4b02-8577-e923761b4c0e.jpg -------------------------------------------------------------------------------- /SQLQuery4.sql: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Delete 5 | From Colors 6 | Where ColorId Not In 7 | ( 8 | Select MAX(ColorId) 9 | From Colors 10 | Group By ColorName, ColorName 11 | ) 12 | 13 | 14 | -------------------------------------------------------------------------------- /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/IEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities 6 | { 7 | public interface IEntity 8 | { 9 | // Veri Tabanı tablosudur 10 | //IEntity implement eden bir classtır. 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IBrandDal.cs: -------------------------------------------------------------------------------- 1 | using Core.Abstract; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface IBrandDal:IEntityRepository 10 | { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IColorDal.cs: -------------------------------------------------------------------------------- 1 | using Core.Abstract; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface IColorDal:IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IRentalDal.cs: -------------------------------------------------------------------------------- 1 | using Core.Abstract; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface IRentalDal:IEntityRepository 10 | { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICustomerDal.cs: -------------------------------------------------------------------------------- 1 | using Core.Abstract; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface ICustomerDal:IEntityRepository 10 | { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICarImageDal.cs: -------------------------------------------------------------------------------- 1 | using Core.Abstract; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface ICarImageDal:IEntityRepository 10 | { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/OperationClaim.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities.Concrete 6 | { 7 | public class OperationClaim : IEntity 8 | { 9 | public int Id { get; set; } 10 | public string Name { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Entities/DTOs/UserForLoginDto.cs: -------------------------------------------------------------------------------- 1 | using Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class UserForLoginDto : IDto 9 | { 10 | public string Email { get; set; } 11 | public string Password { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/Utilities/IoC/ICoreModule.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.IoC 7 | { 8 | public interface ICoreModule 9 | { 10 | void Load(IServiceCollection serviceCollection); 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Entities/Concrete/Brand.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Brand:IEntity 9 | { 10 | public int BrandId { get; set; } 11 | public string BrandName { get; set; } 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Entities/Concrete/Color.cs: -------------------------------------------------------------------------------- 1 | 2 | using Core.Entities; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Entities.Concrete 8 | { 9 | public class Color:IEntity 10 | { 11 | public int ColorId { get; set; } 12 | public string ColorName { get; set; } 13 | 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SQLQuery1.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [dbo].[CarImages] ( 2 | [Id] INT IDENTITY (1, 1) NOT NULL, 3 | [CarId] INT NULL, 4 | [ImagePath] NVARCHAR (MAX) NULL, 5 | [CarImageDate] DATETIME NULL, 6 | PRIMARY KEY CLUSTERED ([Id] ASC), 7 | FOREIGN KEY ([CarId]) REFERENCES [dbo].[Cars] ([CarId]) 8 | ); 9 | -------------------------------------------------------------------------------- /WebAPI/Models/CarImageModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace WebAPI.Models 8 | { 9 | public class CarImageModel 10 | { 11 | public IFormFile files { get; set; } 12 | 13 | 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/AccessToken.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Security.JWT 6 | { 7 | //Erişim anahtarı 8 | public class AccessToken 9 | { 10 | public string Token { get; set; } 11 | public DateTime Expiration { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/ITokenHelper.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Security.JWT 7 | { 8 | public interface ITokenHelper 9 | { 10 | AccessToken CreateToken(User user, List operationClaim); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Entities/Entities.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 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 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/UserOperationClaim.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities.Concrete 6 | { 7 | public class UserOperationClaim : IEntity 8 | { 9 | public int Id { get; set; } 10 | public int UserId { get; set; } 11 | public int OperationClaimId { get; set; } 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IUserDal.cs: -------------------------------------------------------------------------------- 1 | using Core.Abstract; 2 | using Core.Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq.Expressions; 6 | using System.Text; 7 | 8 | namespace DataAccess.Abstract 9 | { 10 | public interface IUserDal : IEntityRepository 11 | { 12 | List GetClaims(User user); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Core/Utilities/Results/Abstract/IDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results.Abstract 6 | { 7 | //bu interface: mesaj, işlem sonucunun yanında 8 | //data da içermesini istenen işlemlerde kullanılır 9 | public interface IDataResult:IResult 10 | { 11 | T Data { get; } 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/BrandValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class BrandValidator : AbstractValidator 10 | { 11 | public BrandValidator() 12 | { 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/ColorValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class ColorValidator : AbstractValidator 10 | { 11 | public ColorValidator() 12 | { 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFrameWork/EfCarImageDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFrameWork 9 | { 10 | public class EfCarImageDal:EfEntityRepositoryBase,ICarImageDal 11 | { 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFrameWork/EfCustomerDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFrameWork 9 | { 10 | public class EfCustomerDal:EfEntityRepositoryBase,ICustomerDal 11 | { 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Entities/DTOs/UserForRegisterDto.cs: -------------------------------------------------------------------------------- 1 | using Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class UserForRegisterDto : IDto 9 | { 10 | public string Email { get; set; } 11 | public string Password { get; set; } 12 | public string FirstName { get; set; } 13 | public string LastName { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Core/Utilities/Results/Abstract/IResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results.Abstract 6 | { 7 | public interface IResult 8 | { 9 | //Yaptığım işlev başarılı mı değilmi onu test ediyorum. 10 | bool Success { get; } 11 | 12 | // ekranda mesaj göstermek istiyorsam. 13 | 14 | string Message { get; } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Core/Utilities/Results/Concrete/ErrorResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results.Concrete 6 | { 7 | public class ErrorResult:Result 8 | { 9 | public ErrorResult(string message):base(false,message) 10 | { 11 | 12 | } 13 | 14 | public ErrorResult():base(false) 15 | { 16 | 17 | } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/TokenOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Security.JWT 6 | { 7 | public class TokenOptions 8 | { 9 | public string Audience { get; set; } 10 | public string Issuer { get; set; } 11 | public int AccessTokenExpiration { get; set; } 12 | public string SecurityKey { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Entities/Concrete/Customer.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Customer:IEntity 9 | { 10 | public int CustomerId { get; set; } 11 | public int UserId { get; set; } 12 | public string CustomerName { get; set; } 13 | public string CampanyName { get; set; } 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFrameWork/EfBrandDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq.Expressions; 7 | using System.Text; 8 | 9 | namespace DataAccess.Concrete.EntityFrameWork 10 | { 11 | public class EfBrandDal : EfEntityRepositoryBase,IBrandDal 12 | { 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFrameWork/EfColorDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq.Expressions; 7 | using System.Text; 8 | 9 | namespace DataAccess.Concrete.EntityFrameWork 10 | { 11 | public class EfColorDal : EfEntityRepositoryBase,IColorDal 12 | { 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFrameWork/EfRentalDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq.Expressions; 7 | using System.Text; 8 | 9 | namespace DataAccess.Concrete.EntityFrameWork 10 | { 11 | public class EfRentalDal : EfEntityRepositoryBase, IRentalDal 12 | { 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Entities/DTOs/CustomerDetailDto.cs: -------------------------------------------------------------------------------- 1 | using Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class CustomerDetailDto : IDto 9 | { 10 | public int Id { get; set; } 11 | public string FirstName { get; set; } 12 | public string LastName { get; set; } 13 | public string Email { get; set; } 14 | public string Password { get; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /WebAPI/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "TokenOptions": { 3 | "Audience": "kader@kader.com", //kitle 4 | "Issuer": "kader@kader.com", 5 | "AccessTokenExpiration": 10, 6 | "SecurityKey": "mysupersecretkeymysupersecretkey" 7 | }, 8 | 9 | 10 | "Logging": { 11 | "LogLevel": { 12 | "Default": "Information", 13 | "Microsoft": "Warning", 14 | "Microsoft.Hosting.Lifetime": "Information" 15 | } 16 | }, 17 | "AllowedHosts": "*" 18 | } 19 | -------------------------------------------------------------------------------- /ConsoleUI/ConsoleUI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Entities/DTOs/CarDetailFilterDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Core.Entities; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class CarDetailFilterDto:IFilterDto 9 | { 10 | public int? BrandId { get; set; } 11 | public int? ColorId { get; set; } 12 | public int? ModelYear { get; set; } 13 | public int? Id { get; set; } 14 | public string CarName { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SQLQuery3.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO Cars(BrandId,ColorId,ModelYear,DailyPrice,Descriptions) 2 | VALUES 3 | ('1','Manuel1','2','2012','100','Manuel Benzin'), 4 | ('1','Otomotik1','3','2015','150','Otomatik Dizel'), 5 | ('2','Otomotik2','1','2017','200','Otomatik Hybrid'), 6 | ('3','Manuel2','3','2014','125','Manuel Dizel'); 7 | 8 | Delete (CarName) 9 | ALTER TABLE Cars 10 | DROP COLUMN CarName; 11 | 12 | INSERT INTO Brands(BrandName) 13 | VALUES 14 | ('Tesla'), 15 | ('BMW'), 16 | ('Renault'); -------------------------------------------------------------------------------- /Core/Utilities/Security/Encryption/SecurityKeyHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IdentityModel.Tokens; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Security.Encryption 7 | { 8 | public class SecurityKeyHelper 9 | { 10 | public static SecurityKey CreateSecurityKey(string securityKey) 11 | { 12 | return new SymmetricSecurityKey(Encoding.UTF8.GetBytes(securityKey)); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Entities/Concrete/Rental.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Rental:IEntity 9 | { 10 | public int RentalId { get; set; } 11 | public int CarId { get; set; } 12 | public int CustomerId { get; set; } 13 | public DateTime RentDate { get; set; } 14 | public DateTime ReturnDate { get; set; } 15 | 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DataAccess/DataAccess.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Caching/ICacheManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Caching 6 | { 7 | public interface ICacheManager 8 | { 9 | T Get(string key); 10 | object Get(string key); 11 | void Add(string key, object value, int duration); 12 | bool IsAdd(string key); 13 | void Remove(string key); 14 | void RemoveByPattern(string pattern); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Business/Abstract/IBrandService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results.Abstract; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface IBrandService 10 | { 11 | IDataResult> GetAll(); 12 | IDataResult GetById(int id); 13 | IResult Add(Brand brand); 14 | IResult Update(Brand brand); 15 | IResult Delete(Brand brand); 16 | 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Core/Utilities/MethodInterceptionBaseAttribute.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | 4 | namespace Core.Utilities 5 | { 6 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] 7 | public abstract class MethodInterceptionBaseAttribute : Attribute, IInterceptor 8 | { 9 | public int Priority { get; set; } 10 | 11 | public virtual void Intercept(IInvocation invocation) 12 | { 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Business/Abstract/IColorService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results.Abstract; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface IColorService 10 | { 11 | IDataResult> GetAll(); 12 | IDataResult GetById(int id); 13 | 14 | 15 | IResult Add(Color color); 16 | IResult Update(Color color); 17 | IResult Delete(Color color); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Business/Abstract/IRentalService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results.Abstract; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface IRentalService 10 | { 11 | IDataResult> GetAll(); 12 | 13 | IDataResult GetById(int id); 14 | IResult Add(Rental rental); 15 | IResult Delete(Rental rental); 16 | IResult Update(Rental rental); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/RentalValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class RentalValidator : AbstractValidator 10 | { 11 | public RentalValidator() 12 | { 13 | RuleFor(r => r.RentDate).NotEmpty(); 14 | RuleFor(r => r.ReturnDate).NotEmpty(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Business/Abstract/ICustomerService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results.Abstract; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface ICustomerService 10 | { 11 | IDataResult> GetAll(); 12 | 13 | IDataResult GetById(int id); 14 | IResult Add(Customer customer); 15 | IResult Delete(Customer customer); 16 | IResult Update(Customer customer); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /SQLQuerysecurity.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [dbo].[OperationClaims] ( 2 | [Id] INT IDENTITY (1, 1) NOT NULL, 3 | [Name] NVARCHAR (250) NOT NULL, 4 | PRIMARY KEY CLUSTERED ([Id] ASC) 5 | ); 6 | 7 | 8 | CREATE TABLE [dbo].[UserOperationClaims] ( 9 | [Id] INT IDENTITY (1, 1) NOT NULL, 10 | [UserId] INT NOT NULL, 11 | [OperationClaimId] INT NOT NULL, 12 | PRIMARY KEY CLUSTERED ([Id] ASC) 13 | ); 14 | 15 | 16 | 17 | ALTER TABLE Users ADD alan_adi verituru, alan_adi verituru, alan_adi verituru; -------------------------------------------------------------------------------- /Entities/Concrete/CarImage.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class CarImage:IEntity 9 | { 10 | 11 | public int Id { get; set; } 12 | public int CarId { get; set; } 13 | public string ImagePath { get; set; } 14 | public DateTime CarImageDate { get; set; } 15 | 16 | public CarImage() 17 | { 18 | CarImageDate = DateTime.Now; 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Utilities/IoC/ServiceTool.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.IoC 7 | { 8 | public static class ServiceTool 9 | { 10 | public static IServiceProvider ServiceProvider { get; private set; } 11 | 12 | public static IServiceCollection Create(IServiceCollection services) 13 | { 14 | ServiceProvider = services.BuildServiceProvider(); 15 | return services; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Entities/Concrete/Car.cs: -------------------------------------------------------------------------------- 1 | 2 | using Core.Entities; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Entities.Concrete 8 | { 9 | public class Car:IEntity 10 | { 11 | public int CarId { get; set; } 12 | public string CarName { get; set; } 13 | public int BrandId { get; set; } 14 | public int ColorId { get; set; } 15 | public string ModelYear { get; set; } 16 | public decimal DailyPrice { get; set; } 17 | public string Descriptions { get; set; } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/User.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Entities.Concrete 7 | { 8 | public class User:IEntity 9 | { 10 | public int UserId { get; set; } 11 | public string FirstName { get; set; } 12 | public string LastName { get; set; } 13 | public string Email { get; set; } 14 | public byte[] PasswordSalt { get; set; } 15 | public byte[] PasswordHash { get; set; } 16 | public bool Status { get; set; } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Encryption/SigningCredentialsHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IdentityModel.Tokens; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Security.Encryption 7 | { 8 | public class SigningCredentialsHelper 9 | { 10 | //credential = mesela siteye girerken kullanılan bilgiler şifre mail vs vs 11 | public static SigningCredentials CreateSigningCredentials(SecurityKey securityKey) 12 | { 13 | return new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha512Signature); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Core/Utilities/Results/Concrete/SuccessResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results.Concrete 6 | { 7 | public class SuccessResult:Result 8 | { 9 | //default olarak true verip mesaj yazcam 10 | //sadece mesaj vercem 11 | //base:Result sınıfını temsil eder. 12 | public SuccessResult(string message) : base(true, message) 13 | { 14 | 15 | } 16 | 17 | //mesaj vermek istemiyorsam 18 | public SuccessResult():base(true) 19 | { 20 | 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Business/Abstract/IAuthService.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Core.Utilities.Results.Abstract; 3 | using Core.Utilities.Security.JWT; 4 | using Entities.DTOs; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace Business.Abstract 10 | { 11 | public interface IAuthService 12 | { 13 | IDataResult Register(UserForRegisterDto userForRegisterDto, string password); 14 | IDataResult Login(UserForLoginDto userForLoginDto); 15 | IResult UserExists(string email); 16 | IDataResult CreateAccessToken(User user); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Business/Abstract/IUserService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results.Abstract; 2 | using Core.Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface IUserService 10 | { 11 | IDataResult> GetAll(); 12 | 13 | IDataResult GetById(int id); 14 | 15 | IResult Add(User user); 16 | IResult Delete(User user); 17 | IResult Update(User user); 18 | 19 | List GetClaims(User user); 20 | 21 | User GetByMail(string email); 22 | 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/CarValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class CarValidator : AbstractValidator 10 | { 11 | public CarValidator() 12 | { 13 | RuleFor(c => c.CarName).NotEmpty(); 14 | RuleFor(c => c.CarName).MinimumLength(2); 15 | RuleFor(c => c.DailyPrice).NotEmpty(); 16 | RuleFor(c => c.DailyPrice).GreaterThan(0); 17 | 18 | 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Validation/ValidationTool.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.CrossCuttingConcerns.Validation 7 | { 8 | public static class ValidationTool 9 | { 10 | public static void Validate(IValidator validator,object entity) 11 | { 12 | var context = new ValidationContext(entity); 13 | 14 | var result = validator.Validate(context); 15 | if(!result.IsValid) 16 | { 17 | throw new ValidationException(result.Errors); 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Business/Abstract/ICarImageService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace Business.Abstract 9 | { 10 | public interface ICarImageService 11 | { 12 | IResult Add(IFormFile formFile, CarImage carImage); 13 | IResult Update(IFormFile formFile, CarImage carImage); 14 | IResult Delete( CarImage carImage); 15 | 16 | IDataResult> GetAll(); 17 | IDataResult> GetImagesByCarId(int id); 18 | IDataResult GetImageById(int id); 19 | 20 | 21 | 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Core/Extensions/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.IoC; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Core.Extensions 8 | { 9 | public static class ServiceCollectionExtensions 10 | { 11 | public static IServiceCollection AddDependencyResolvers( 12 | this IServiceCollection serviceCollection, 13 | ICoreModule[] modules) 14 | 15 | { 16 | foreach (var module in modules) 17 | { 18 | module.Load(serviceCollection); 19 | } 20 | 21 | return ServiceTool.Create(serviceCollection); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Core/Extensions/ClaimsPrincipalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Claims; 5 | using System.Text; 6 | 7 | namespace Core.Extensions 8 | { 9 | public static class ClaimsPrincipalExtensions 10 | { 11 | public static List Claims(this ClaimsPrincipal claimsPrincipal, string claimType) 12 | { 13 | var result = claimsPrincipal?.FindAll(claimType)?.Select(x => x.Value).ToList(); 14 | return result; 15 | } 16 | 17 | public static List ClaimRoles(this ClaimsPrincipal claimsPrincipal) 18 | { 19 | return claimsPrincipal?.Claims(ClaimTypes.Role); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Entities/DTOs/CarDetailDto.cs: -------------------------------------------------------------------------------- 1 | using Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class CarDetailDto:IDto 9 | //join işlemleri 10 | { 11 | public int CarId { get; set; } 12 | public int BrandId { get; set; } 13 | public string BrandName { get; set; } 14 | public int ColorId { get; set; } 15 | public string ColorName { get; set; } 16 | public decimal DailyPrice { get; set; } 17 | public int ModelYear { get; set; } 18 | public string Description { get; set; } 19 | public int MinFindeksScore { get; set; } 20 | public List Images { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Utilities/Results/Concrete/DataResult.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results.Abstract; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Results.Concrete 7 | { 8 | public class DataResult : Result, IDataResult 9 | { 10 | //base:Result sınıfını temsil etmektedir. 11 | public DataResult(T data, bool success, string message) 12 | :base(success,message) 13 | { 14 | Data = data; 15 | } 16 | //mesaj göndermek istemiyorum:) 17 | public DataResult(T data,bool success) 18 | :base(success) 19 | { 20 | Data = data; 21 | } 22 | 23 | 24 | public T Data { get; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Core/Utilities/Results/Concrete/Result.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results.Abstract; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Results.Concrete 7 | { 8 | public class Result : IResult 9 | { 10 | //base constructor yapısını kullandım. 11 | //mesaj ve başarılı olup olmadığını döndürmek istiyorum. 12 | 13 | public Result(bool success,string message):this(success) 14 | { 15 | Message = message; 16 | } 17 | //mesaj döndürmek istemiyorum. 18 | public Result(bool success) 19 | { 20 | Success = success; 21 | } 22 | public bool Success { get; } 23 | public string Message { get; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Business/Business.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /WebAPI/WebAPI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Core/Utilities/Results/Concrete/SuccessDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results.Concrete 6 | { 7 | public class SuccessDataResult:DataResult 8 | { 9 | //sistem versiyonları: 10 | 11 | public SuccessDataResult(T data,string message) 12 | :base(data,true,message) 13 | { 14 | 15 | } 16 | 17 | public SuccessDataResult(T data) 18 | :base(data,true) 19 | { 20 | 21 | } 22 | 23 | public SuccessDataResult(string message) 24 | :base(default,true,message) 25 | { 26 | 27 | } 28 | 29 | public SuccessDataResult() 30 | :base(default,true) 31 | { 32 | 33 | } 34 | 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Core/Utilities/Results/Concrete/ErrorDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results.Concrete 6 | { 7 | public class ErrorDataResult:DataResult 8 | 9 | { 10 | //sistem versiyonları: 11 | 12 | public ErrorDataResult(T data ,string message) 13 | :base(data,false,message) 14 | { 15 | 16 | } 17 | 18 | public ErrorDataResult(T data) 19 | :base(data,false) 20 | { 21 | 22 | } 23 | 24 | public ErrorDataResult(string message) 25 | :base(default,false,message) 26 | { 27 | 28 | } 29 | 30 | public ErrorDataResult() 31 | :base(default,false) 32 | { 33 | 34 | } 35 | 36 | 37 | 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Core/Utilities/Business/BusinessRules.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results.Abstract; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Business 7 | { 8 | public class BusinessRules 9 | { 10 | public static IResult Run(params IResult[] logics) 11 | { 12 | try 13 | { 14 | foreach (var logic in logics) 15 | { 16 | if(!logic.Success) 17 | { 18 | return logic; 19 | } 20 | 21 | } 22 | return null; 23 | } 24 | catch (Exception exception ) 25 | { 26 | 27 | throw new Exception(exception.Message); 28 | } 29 | } 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICarDal.cs: -------------------------------------------------------------------------------- 1 | using Core.Abstract; 2 | using Core.DataAccess; 3 | using Entities.Concrete; 4 | using Entities.DTOs; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq.Expressions; 8 | using System.Text; 9 | 10 | namespace DataAccess.Abstract 11 | { 12 | public interface ICarDal:IEntityRepository 13 | { 14 | 15 | List GetCarDetails(Expression> filter = null); 16 | List GetAllCarDetailsByFilter(CarDetailFilterDto filter); 17 | 18 | List GetCarDetailsById(int carId); 19 | List GetCarDetailsByColorId(int colorId); 20 | List GetCarDetailsByBrandId(int brandId); 21 | List GetCarDetailsByBrandAndColor(int brandId, int colorId); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Core/DependencyResolvers/CoreModule.cs: -------------------------------------------------------------------------------- 1 | using Core.CrossCuttingConcerns.Caching; 2 | using Core.CrossCuttingConcerns.Caching.Microsoft; 3 | using Core.Utilities.IoC; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Diagnostics; 9 | using System.Text; 10 | 11 | namespace Core.DependencyResolvers 12 | { 13 | public class CoreModule : ICoreModule 14 | { 15 | public void Load(IServiceCollection serviceCollection) 16 | { 17 | serviceCollection.AddMemoryCache(); 18 | serviceCollection.AddSingleton(); 19 | serviceCollection.AddSingleton(); 20 | serviceCollection.AddSingleton(); 21 | 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Core/DataAccess/IEntityRepository.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq.Expressions; 6 | using System.Text; 7 | 8 | namespace Core.Abstract 9 | { 10 | //Burda generic class yapısını kullandım. ve bu classın IEntity'i implemente eden bir class ve newlenemez olması şartını yazdım. 11 | 12 | public interface IEntityRepository where T:class,IEntity,new() 13 | { 14 | //Expression yapısıyla birlikte filtreleme yapılacak linq yapısına ortam hazırladım diyebiliriz. 15 | List GetAll(Expression> filter=null); 16 | 17 | //tek bir data getirmemi sağlayan method. 18 | T Get(Expression> filter); 19 | 20 | void Add(T entity); 21 | 22 | void Update(T entity); 23 | void Delete(T entity); 24 | 25 | 26 | 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Caching/CacheRemoveAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.CrossCuttingConcerns.Caching; 3 | using Core.Utilities; 4 | using Core.Utilities.IoC; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | using Microsoft.Extensions.DependencyInjection; 9 | 10 | namespace Core.Aspects.Autofac.Caching 11 | { 12 | public class CacheRemoveAspect : MethodInterception 13 | { 14 | private string _pattern; 15 | private ICacheManager _cacheManager; 16 | 17 | public CacheRemoveAspect(string pattern) 18 | { 19 | _pattern = pattern; 20 | _cacheManager = ServiceTool.ServiceProvider.GetService(); 21 | } 22 | 23 | protected override void OnSuccess(IInvocation invocation) 24 | { 25 | _cacheManager.RemoveByPattern(_pattern); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Transaction/TransactionScopeAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.Utilities; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using System.Transactions; 7 | 8 | namespace Core.Aspects.Autofac.Transaction 9 | { 10 | public class TransactionScopeAspect : MethodInterception 11 | { 12 | public override void Intercept(IInvocation invocation) 13 | { 14 | using (TransactionScope transactionScope = new TransactionScope()) 15 | { 16 | try 17 | { 18 | invocation.Proceed(); 19 | transactionScope.Complete(); 20 | } 21 | catch (System.Exception e) 22 | { 23 | transactionScope.Dispose(); 24 | throw; 25 | } 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /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:59622", 8 | "sslPort": 44345 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "weatherforecast", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "WebAPI": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "weatherforecast", 24 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Core/Utilities/AspectInterceptorSelector.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | 8 | namespace Core.Utilities 9 | { 10 | 11 | public class AspectInterceptorSelector : IInterceptorSelector 12 | { 13 | public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) 14 | { 15 | var classAttributes = type.GetCustomAttributes 16 | (true).ToList(); 17 | var methodAttributes = type.GetMethod(method.Name) 18 | .GetCustomAttributes(true); 19 | classAttributes.AddRange(methodAttributes); 20 | // classAttributes.Add(new ExceptionLogAspect(typeof(FileLogger))); 21 | 22 | return classAttributes.OrderBy(x => x.Priority).ToArray(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Core/Extensions/ClaimExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IdentityModel.Tokens.Jwt; 4 | using System.Linq; 5 | using System.Security.Claims; 6 | using System.Text; 7 | 8 | namespace Core.Extensions 9 | { 10 | public static class ClaimExtensions 11 | { 12 | public static void AddEmail(this ICollection claims, string email) 13 | { 14 | claims.Add(new Claim(JwtRegisteredClaimNames.Email, email)); 15 | } 16 | 17 | public static void AddName(this ICollection claims, string name) 18 | { 19 | claims.Add(new Claim(ClaimTypes.Name, name)); 20 | } 21 | 22 | public static void AddNameIdentifier(this ICollection claims, string nameIdentifier) 23 | { 24 | claims.Add(new Claim(ClaimTypes.NameIdentifier, nameIdentifier)); 25 | } 26 | 27 | public static void AddRoles(this ICollection claims, string[] roles) 28 | { 29 | roles.ToList().ForEach(role => claims.Add(new Claim(ClaimTypes.Role, role))); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFrameWork/EfUserDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Core.Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | using System.Linq; 8 | 9 | namespace DataAccess.Concrete.EntityFrameWork 10 | { 11 | public class EfUserDal:EfEntityRepositoryBase,IUserDal 12 | { 13 | public List GetClaims(User user) 14 | { 15 | using (var context = new ReCapDatabaseContext()) 16 | { 17 | var result = from operationClaim in context.OperationClaims 18 | join userOperationClaim in context.UserOperationClaims 19 | on operationClaim.Id equals userOperationClaim.OperationClaimId 20 | where userOperationClaim.UserId == user.UserId 21 | select new OperationClaim { Id = operationClaim.Id, Name = operationClaim.Name }; 22 | return result.ToList(); 23 | 24 | } 25 | 26 | 27 | 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Business/Abstract/ICarService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results.Abstract; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace Business.Abstract 9 | { 10 | public interface ICarService 11 | { 12 | IDataResult> GetAll(); 13 | IResult Add(Car car); 14 | IResult Delete(Car car); 15 | IResult Update(Car car); 16 | IResult AddTransactionalTest(Car car); 17 | IDataResult GetCarById(int id); 18 | IDataResult> GetCarsFiltreDetails(CarDetailFilterDto filterDto); 19 | IDataResult> GetByDailyPrice(decimal min, decimal max); 20 | IDataResult> GetCarsByBrandId(int brandId); 21 | IDataResult> GetCarDetails(); 22 | IDataResult> GetCarDetail(int carId); 23 | IDataResult> GetCarsDetailByBrandId(int brandId); 24 | IDataResult> GetByCategoryId(int categoryId); 25 | IDataResult> GetCarsDetailByColorId(int colorId); 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Core/Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Core/Utilities/MethodInterception.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | 4 | namespace Core.Utilities 5 | { 6 | public abstract class MethodInterception : MethodInterceptionBaseAttribute 7 | { 8 | protected virtual void OnBefore(IInvocation invocation) { } 9 | protected virtual void OnAfter(IInvocation invocation) { } 10 | protected virtual void OnException(IInvocation invocation, System.Exception e) { } 11 | protected virtual void OnSuccess(IInvocation invocation) { } 12 | public override void Intercept(IInvocation invocation) 13 | { 14 | var isSuccess = true; 15 | OnBefore(invocation); 16 | try 17 | { 18 | invocation.Proceed(); 19 | } 20 | catch (Exception e) 21 | { 22 | isSuccess = false; 23 | OnException(invocation, e); 24 | throw; 25 | } 26 | finally 27 | { 28 | if (isSuccess) 29 | { 30 | OnSuccess(invocation); 31 | } 32 | } 33 | OnAfter(invocation); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Performance/PerformanceAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.Utilities; 3 | using Core.Utilities.IoC; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Diagnostics; 7 | using System.Text; 8 | using Microsoft.Extensions.DependencyInjection; 9 | namespace Core.Aspects.Autofac.Performance 10 | { 11 | public class PerformanceAspect : MethodInterception 12 | { 13 | private int _interval; 14 | private Stopwatch _stopwatch; 15 | 16 | public PerformanceAspect(int interval) 17 | { 18 | _interval = interval; 19 | _stopwatch = ServiceTool.ServiceProvider.GetService(); 20 | } 21 | 22 | 23 | protected override void OnBefore(IInvocation invocation) 24 | { 25 | _stopwatch.Start(); 26 | } 27 | 28 | protected override void OnAfter(IInvocation invocation) 29 | { 30 | if (_stopwatch.Elapsed.TotalSeconds > _interval) 31 | { 32 | Debug.WriteLine($"Performance : {invocation.Method.DeclaringType.FullName}.{invocation.Method.Name}-->{_stopwatch.Elapsed.TotalSeconds}"); 33 | } 34 | _stopwatch.Reset(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Business/BusinessAspect/SecuredOperation.cs: -------------------------------------------------------------------------------- 1 | using Business.Constants; 2 | using Castle.DynamicProxy; 3 | using Core.Extensions; 4 | using Core.Utilities; 5 | using Core.Utilities.IoC; 6 | using Microsoft.AspNetCore.Http; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | using Microsoft.Extensions.DependencyInjection; 11 | 12 | namespace Business.BusinessAspect 13 | { 14 | public class SecuredOperation : MethodInterception 15 | { 16 | private string[] _roles; 17 | private IHttpContextAccessor _httpContextAccessor; 18 | 19 | public SecuredOperation(string roles) 20 | { 21 | _roles = roles.Split(','); 22 | _httpContextAccessor = ServiceTool.ServiceProvider.GetService(); 23 | 24 | } 25 | 26 | protected override void OnBefore(IInvocation invocation) 27 | { 28 | var roleClaims = _httpContextAccessor.HttpContext.User.ClaimRoles(); 29 | foreach (var role in _roles) 30 | { 31 | if (roleClaims.Contains(role)) 32 | { 33 | return; 34 | } 35 | } 36 | throw new Exception(Messages.AuthorizationDenied); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Business/Constants/Messages.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Runtime.Serialization; 5 | using System.Text; 6 | 7 | namespace Business.Constants 8 | { 9 | public static class Messages 10 | { 11 | public static string Added = " Eklendi"; 12 | 13 | public static string NameInvalid = "Geçersiz isim"; 14 | 15 | public static string Maintenancetime = "Sistem bakımda"; 16 | 17 | public static string Listed = " Listelendi"; 18 | 19 | public static string Deleted = "Silindi"; 20 | public static string Updated = "Güncellendi"; 21 | public static string RentInvalıd = "Araba zaten kiralandı"; 22 | public static string CarOfImageLimitExceeded="Resim Limiti aşıldı."; 23 | public static string AuthorizationDenied="Yetkiniz yok"; 24 | public static string UserRegistered="Kayıt olundu."; 25 | public static string UserNotFound="Kullanıcı bulunamadı."; 26 | public static string PasswordError="Parola hatalı."; 27 | public static string SuccessfulLogin="Giriş başarılı."; 28 | public static string UserAlreadyExists="Kullanıcı mevcut"; 29 | public static string AccessTokenCreated="Token oluşturuldu."; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Validation/ValidationAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.CrossCuttingConcerns.Validation; 3 | using Core.Utilities; 4 | using FluentValidation; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | namespace Core.Aspects.Autofac.Validation 11 | { 12 | public class ValidationAspect : MethodInterception 13 | { 14 | private Type _validatorType; 15 | public ValidationAspect(Type validatorType) 16 | { 17 | if (!typeof(IValidator).IsAssignableFrom(validatorType)) 18 | { 19 | throw new System.Exception("Bu bir doğrulama sınıfı değil"); 20 | } 21 | 22 | _validatorType = validatorType; 23 | } 24 | protected override void OnBefore(IInvocation invocation) 25 | { 26 | var validator = (IValidator)Activator.CreateInstance(_validatorType); 27 | var entityType = _validatorType.BaseType.GetGenericArguments()[0]; 28 | var entities = invocation.Arguments.Where(t => t.GetType() == entityType); 29 | foreach (var entity in entities) 30 | { 31 | ValidationTool.Validate(validator, entity); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFrameWork/ReCapDatabaseCotext.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Entities.Concrete; 3 | using Microsoft.EntityFrameworkCore; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFrameWork 9 | { 10 | public class ReCapDatabaseContext:DbContext 11 | { 12 | //veri tabanına bağlantımı sağladığım bölüm. 13 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 14 | { 15 | optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=ReCapDatabasee;Trusted_connection=true"); 16 | } 17 | 18 | //veri tabanı verileri ile kendi tablolarımdaki verileri eşleştirdim. 19 | public DbSet Cars { get; set; } 20 | public DbSet Colors { get; set; } 21 | public DbSet Brands { get; set; } 22 | 23 | public DbSet Users { get; set; } 24 | public DbSet Customers { get; set; } 25 | public DbSet Rentals { get; set; } 26 | 27 | public DbSet CarImages { get; set; } 28 | 29 | public DbSet OperationClaims { get; set; } 30 | public DbSet UserOperationClaims { get; set; } 31 | 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /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/Utilities/Security/Hashing/HashingHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Security.Hashing 6 | { 7 | public class HashingHelper 8 | { 9 | public static void CreatePasswordHash(string password, out byte[] passwordHash, out byte[] passwordSalt) 10 | { 11 | using (var hmac = new System.Security.Cryptography.HMACSHA512()) 12 | { 13 | passwordSalt = hmac.Key; // yukarıdan gelen kullanıcı için oluşturulan key , her kullanıcı için farkllı bir key oluşturur 14 | passwordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(password)); 15 | } 16 | } 17 | public static bool VerifyPasswordHash(string password, byte[] passwordHash, byte[] passwordSalt) 18 | { 19 | using (var hmac = new System.Security.Cryptography.HMACSHA512(passwordSalt)) 20 | { 21 | var computedHash = passwordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(password)); 22 | for (int i = 0; i < computedHash.Length; i++) 23 | { 24 | if (computedHash[i] != passwordHash[i]) 25 | { 26 | return false; 27 | } 28 | 29 | } 30 | return true; 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Caching/CacheAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.CrossCuttingConcerns.Caching; 3 | using Core.Utilities; 4 | using Core.Utilities.IoC; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using System.Linq; 10 | 11 | namespace Core.Aspects.Autofac.Caching 12 | { 13 | public class CacheAspect : MethodInterception 14 | { 15 | private int _duration; 16 | private ICacheManager _cacheManager; 17 | 18 | public CacheAspect(int duration = 60) 19 | { 20 | _duration = duration; 21 | _cacheManager = ServiceTool.ServiceProvider.GetService(); 22 | } 23 | 24 | public override void Intercept(IInvocation invocation) 25 | { 26 | var methodName = string.Format($"{invocation.Method.ReflectedType.FullName}.{invocation.Method.Name}"); 27 | var arguments = invocation.Arguments.ToList(); 28 | var key = $"{methodName}({string.Join(",", arguments.Select(x => x?.ToString() ?? ""))})"; 29 | if (_cacheManager.IsAdd(key)) 30 | { 31 | invocation.ReturnValue = _cacheManager.Get(key); 32 | return; 33 | } 34 | invocation.Proceed(); 35 | _cacheManager.Add(key, invocation.ReturnValue, _duration); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Business/Concrete/BrandManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Core.Utilities.Results.Abstract; 4 | using Core.Utilities.Results.Concrete; 5 | using DataAccess.Abstract; 6 | using Entities.Concrete; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | 11 | namespace Business.Concrete 12 | { 13 | public class BrandManager : IBrandService 14 | { 15 | IBrandDal _brandDal; 16 | 17 | public BrandManager(IBrandDal brandDal) 18 | { 19 | _brandDal = brandDal; 20 | } 21 | 22 | public IResult Add(Brand brand) 23 | { 24 | _brandDal.Add(brand); 25 | return new SuccessResult(Messages.Added); 26 | } 27 | 28 | public IResult Delete(Brand brand) 29 | { 30 | _brandDal.Delete(brand); 31 | return new SuccessResult(Messages.Deleted); 32 | } 33 | 34 | public IDataResult> GetAll() 35 | { 36 | return new SuccessDataResult>( _brandDal.GetAll(),Messages.Listed); 37 | } 38 | 39 | public IDataResult GetById(int id) 40 | { 41 | return new SuccessDataResult(_brandDal.Get(p => p.BrandId == id),Messages.Listed); 42 | 43 | } 44 | 45 | public IResult Update(Brand brand) 46 | { 47 | _brandDal.Update(brand); 48 | return new SuccessResult(Messages.Updated); 49 | } 50 | 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Business/Concrete/ColorManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Core.Utilities.Results.Abstract; 4 | using Core.Utilities.Results.Concrete; 5 | using DataAccess.Abstract; 6 | using Entities.Concrete; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | 11 | namespace Business.Concrete 12 | { 13 | public class ColorManager : IColorService 14 | { 15 | //iş kodlarımı yazarım. 16 | IColorDal _colorDal; 17 | 18 | public ColorManager(IColorDal colorDal) 19 | { 20 | _colorDal = colorDal; 21 | } 22 | 23 | public IResult Add(Color color) 24 | { 25 | 26 | _colorDal.Add(color); 27 | return new SuccessResult(Messages.Added); 28 | } 29 | 30 | public IResult Delete(Color color) 31 | { 32 | _colorDal.Delete(color); 33 | return new SuccessResult(Messages.Deleted); 34 | 35 | } 36 | 37 | public IDataResult> GetAll() 38 | { 39 | return new SuccessDataResult>( _colorDal.GetAll(),Messages.Listed); 40 | } 41 | 42 | public IDataResult GetById(int id) 43 | { 44 | return new SuccessDataResult( _colorDal.Get(c => c.ColorId == id),Messages.Listed); 45 | 46 | } 47 | 48 | public IResult Update(Color color) 49 | { 50 | _colorDal.Update(color); 51 | return new SuccessResult(Messages.Updated); 52 | } 53 | 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Business/Concrete/CustomerManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Core.Utilities.Results.Abstract; 4 | using Core.Utilities.Results.Concrete; 5 | using DataAccess.Abstract; 6 | using Entities.Concrete; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | 11 | namespace Business.Concrete 12 | { 13 | public class CustomerManager : ICustomerService 14 | { 15 | ICustomerDal _customerDal; 16 | 17 | public CustomerManager(ICustomerDal customerDal) 18 | { 19 | _customerDal = customerDal; 20 | } 21 | 22 | public IResult Add(Customer customer) 23 | { 24 | 25 | _customerDal.Add(customer); 26 | return new SuccessResult(Messages.Added); 27 | } 28 | 29 | public IResult Delete(Customer customer) 30 | { 31 | _customerDal.Delete(customer); 32 | return new SuccessResult(Messages.Deleted); 33 | } 34 | 35 | public IDataResult> GetAll() 36 | { 37 | return new SuccessDataResult>(_customerDal.GetAll(), Messages.Listed); 38 | } 39 | 40 | public IDataResult GetById(int id) 41 | { 42 | return new SuccessDataResult(_customerDal.Get(c => c.CustomerId == id), Messages.Listed); 43 | 44 | } 45 | 46 | public IResult Update(Customer customer) 47 | { 48 | _customerDal.Update(customer); 49 | return new SuccessResult(Messages.Updated); 50 | 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Business/Concrete/RentalManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Core.Utilities.Results.Abstract; 4 | using Core.Utilities.Results.Concrete; 5 | using DataAccess.Abstract; 6 | using Entities.Concrete; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | 11 | namespace Business.Concrete 12 | { 13 | public class RentalManager : IRentalService 14 | { 15 | IRentalDal _rentalDal; 16 | 17 | public RentalManager(IRentalDal rentalDal) 18 | { 19 | _rentalDal = rentalDal; 20 | } 21 | 22 | public IResult Add(Rental rental) 23 | { 24 | if(rental.ReturnDate> GetAll() 39 | { 40 | return new SuccessDataResult>(_rentalDal.GetAll(), Messages.Listed); 41 | 42 | } 43 | 44 | public IDataResult GetById(int id) 45 | { 46 | return new SuccessDataResult(_rentalDal.Get(p => p.RentalId == id), Messages.Listed); 47 | } 48 | 49 | public IResult Update(Rental rental) 50 | { 51 | _rentalDal.Update(rental); 52 | return new SuccessResult(Messages.Updated); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Business/Concrete/UserManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Core.Utilities.Results.Abstract; 4 | using Core.Utilities.Results.Concrete; 5 | using DataAccess.Abstract; 6 | using Core.Entities.Concrete; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | 11 | namespace Business.Concrete 12 | { 13 | public class UserManager : IUserService 14 | { 15 | IUserDal _userDal; 16 | 17 | public UserManager(IUserDal userDal) 18 | { 19 | _userDal = userDal; 20 | } 21 | 22 | public IResult Add(User user) 23 | { 24 | _userDal.Add(user); 25 | return new SuccessResult(Messages.Added); 26 | } 27 | 28 | public IResult Delete(User user) 29 | { 30 | _userDal.Delete(user); 31 | return new SuccessResult(Messages.Deleted); 32 | 33 | } 34 | 35 | public IDataResult> GetAll() 36 | { 37 | return new SuccessDataResult>(_userDal.GetAll(), Messages.Listed); 38 | } 39 | 40 | public IDataResult GetById(int id) 41 | { 42 | return new SuccessDataResult(_userDal.Get(u => u.UserId == id), Messages.Listed); 43 | } 44 | 45 | public User GetByMail(string email) 46 | { 47 | return _userDal.Get(u => u.Email == email); 48 | } 49 | 50 | public List GetClaims(User user) 51 | { 52 | return _userDal.GetClaims(user); 53 | } 54 | 55 | public IResult Update(User user) 56 | { 57 | _userDal.Update(user); 58 | return new SuccessResult(Messages.Updated); 59 | 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /SQLQuery2Recap.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE Cars( 2 | CarId int PRIMARY KEY IDENTITY(1,1), 3 | BrandId int, 4 | ColorId int, 5 | ModelYear nvarchar(25), 6 | DailyPrice decimal, 7 | Descriptions nvarchar(25), 8 | FOREIGN KEY (ColorId) REFERENCES Colors(ColorId), 9 | FOREIGN KEY (BrandId) REFERENCES Brands(BrandId) 10 | ) 11 | 12 | CREATE TABLE Colors( 13 | ColorId int PRIMARY KEY IDENTITY(1,1), 14 | ColorName nvarchar(25), 15 | ) 16 | 17 | CREATE TABLE Brands( 18 | BrandId int PRIMARY KEY IDENTITY(1,1), 19 | BrandName nvarchar(25), 20 | ) 21 | 22 | CREATE TABLE Users( 23 | UserId int PRIMARY KEY IDENTITY(1,1), 24 | FirstName nvarchar(25), 25 | LastName nvarchar(25), 26 | Email nvarchar(55), 27 | Password nvarchar(35), 28 | ) 29 | 30 | 31 | CREATE TABLE Customers( 32 | CustomerId int PRIMARY KEY IDENTITY(1,1), 33 | UserId int, 34 | CustomerName nvarchar(25), 35 | FOREIGN KEY (UserId) REFERENCES Users(UserId), 36 | ) 37 | 38 | CREATE TABLE Rentals( 39 | RentalId int PRIMARY KEY IDENTITY(1,1), 40 | CarId int, 41 | CustomerID int, 42 | RentDate datetime, 43 | ReturnDate datetime, 44 | FOREIGN KEY (CarId) REFERENCES Cars(CarId), 45 | FOREIGN KEY (CustomerId) REFERENCES Customers(CustomerId), 46 | 47 | ) 48 | 49 | 50 | 51 | 52 | INSERT INTO Cars(BrandId,ColorId,ModelYear,DailyPrice,Descriptions) 53 | VALUES 54 | ('1','2','2012','100','Manuel Benzin'), 55 | ('1','3','2015','150','Otomatik Dizel'), 56 | ('2','1','2017','200','Otomatik Hybrid'), 57 | ('3','3','2014','125','Manuel Dizel'); 58 | 59 | INSERT INTO Colors(ColorName) 60 | VALUES 61 | ('Beyaz'), 62 | ('Siyah'), 63 | ('Mavi'), 64 | ('Gri'); 65 | 66 | 67 | 68 | INSERT INTO Brands(BrandName) 69 | VALUES 70 | ('Tesla'), 71 | ('BMW'), 72 | ('Renault'), 73 | ('Mercedes'); 74 | 75 | SELECT *FROM Cars 76 | SELECT * FROM Brands 77 | select* from Colors 78 | 79 | 80 | -------------------------------------------------------------------------------- /WebAPI/Controllers/AuthController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.DTOs; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class AuthController : Controller 15 | { 16 | private IAuthService _authService; 17 | 18 | public AuthController(IAuthService authService) 19 | { 20 | _authService = authService; 21 | } 22 | 23 | [HttpPost("login")] 24 | public ActionResult Login(UserForLoginDto userForLoginDto) 25 | { 26 | var userToLogin = _authService.Login(userForLoginDto); 27 | if (!userToLogin.Success) 28 | { 29 | return BadRequest(userToLogin.Message); 30 | } 31 | 32 | var result = _authService.CreateAccessToken(userToLogin.Data); 33 | if (result.Success) 34 | { 35 | return Ok(result.Data); 36 | } 37 | 38 | return BadRequest(result.Message); 39 | } 40 | 41 | [HttpPost("register")] 42 | public ActionResult Register(UserForRegisterDto userForRegisterDto) 43 | { 44 | var userExists = _authService.UserExists(userForRegisterDto.Email); 45 | if (!userExists.Success) 46 | { 47 | return BadRequest(userExists.Message); 48 | } 49 | 50 | var registerResult = _authService.Register(userForRegisterDto, userForRegisterDto.Password); 51 | var result = _authService.CreateAccessToken(registerResult.Data); 52 | if (result.Success) 53 | { 54 | return Ok(result.Data); 55 | } 56 | 57 | return BadRequest(result.Message); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /SQLQuery2.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE Cars( 2 | CarId int PRIMARY KEY IDENTITY(1,1), 3 | CarName nvarchar(25), 4 | BrandId int, 5 | ColorId int, 6 | ModelYear nvarchar(25), 7 | DailyPrice decimal, 8 | Descriptions nvarchar(25), 9 | FOREIGN KEY (ColorId) REFERENCES Colors(ColorId), 10 | FOREIGN KEY (BrandId) REFERENCES Brands(BrandId) 11 | ) 12 | 13 | CREATE TABLE Colors( 14 | ColorId int PRIMARY KEY IDENTITY(1,1), 15 | ColorName nvarchar(25), 16 | ) 17 | 18 | CREATE TABLE Brands( 19 | BrandId int PRIMARY KEY IDENTITY(1,1), 20 | BrandName nvarchar(25), 21 | ) 22 | 23 | CREATE TABLE Users( 24 | UserId int PRIMARY KEY IDENTITY(1,1), 25 | FirstName nvarchar(25), 26 | LastName nvarchar(25), 27 | Email nvarchar(55), 28 | Password nvarchar(35), 29 | ) 30 | 31 | 32 | CREATE TABLE Customers( 33 | CustomerId int PRIMARY KEY IDENTITY(1,1), 34 | UserId int, 35 | CustomerName nvarchar(25), 36 | FOREIGN KEY (UserId) REFERENCES Users(UserId), 37 | ) 38 | 39 | CREATE TABLE Rentals( 40 | RentalId int PRIMARY KEY IDENTITY(1,1), 41 | CarId int, 42 | CustomerID int, 43 | RentDate datetime, 44 | ReturnDate datetime, 45 | FOREIGN KEY (CarId) REFERENCES Cars(CarId), 46 | FOREIGN KEY (CustomerId) REFERENCES Customers(CustomerId), 47 | 48 | ) 49 | INSERT INTO Cars(BrandId,ColorId,ModelYear,DailyPrice,Descriptions) 50 | VALUES 51 | ('1','2','2012','100','Manuel Benzin'), 52 | ('1','3','2015','150','Otomatik Dizel'), 53 | ('2','1','2017','200','Otomatik Hybrid'), 54 | ('3','3','2014','125','Manuel Dizel'); 55 | 56 | 57 | 58 | INSERT INTO Colors(ColorName) 59 | VALUES 60 | ('Beyaz'), 61 | ('Siyah'), 62 | ('Mavi'), 63 | ('Gri'); 64 | 65 | 66 | INSERT INTO Brands(BrandName) 67 | VALUES 68 | ('Tesla'), 69 | ('BMW'), 70 | ('Renault'), 71 | ('Hundai'); 72 | 73 | 74 | ALTER DATABASE ReCapDatabase 75 | SET SINGLE_USER WITH ROLLBACK IMMEDIATE 76 | 77 | ALTER DATABASE ReCapDatabase MODIFY NAME = ReCapDatabasee 78 | 79 | ALTER DATABASE ReCapDatabasee 80 | SET MULTI_USER WITH ROLLBACK IMMEDIATE -------------------------------------------------------------------------------- /WebAPI/Controllers/UsersController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Core.Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class UsersController : ControllerBase 15 | { 16 | IUserService _userService; 17 | 18 | public UsersController(IUserService userService) 19 | { 20 | _userService = userService; 21 | } 22 | 23 | [HttpGet("getall")] 24 | public IActionResult GetAll() 25 | { 26 | var result = _userService.GetAll(); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result); 32 | } 33 | 34 | [HttpGet("getbyid")] 35 | public IActionResult GetById(int id) 36 | { 37 | var result = _userService.GetById(id); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | 43 | return BadRequest(result); 44 | } 45 | 46 | 47 | [HttpPost("add")] 48 | public IActionResult Add(User user) 49 | { 50 | var result = _userService.Add(user); 51 | if (result.Success) 52 | { 53 | return Ok(result); 54 | } 55 | 56 | return BadRequest(result); 57 | } 58 | [HttpPost("delete")] 59 | public IActionResult Delete(User user) 60 | { 61 | var result = _userService.Delete(user); 62 | if (result.Success) 63 | { 64 | return Ok(result); 65 | } 66 | 67 | return BadRequest(result); 68 | } 69 | 70 | [HttpPost("update")] 71 | public IActionResult Update(User user) 72 | { 73 | var result = _userService.Update(user); 74 | if (result.Success) 75 | { 76 | return Ok(result); 77 | } 78 | 79 | return BadRequest(result); 80 | } 81 | 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /WebAPI/Controllers/BrandsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class BrandsController : ControllerBase 15 | { 16 | IBrandService _brandService; 17 | 18 | public BrandsController(IBrandService brandService) 19 | { 20 | _brandService = brandService; 21 | } 22 | [HttpGet("getall")] 23 | public IActionResult GetAll() 24 | { 25 | var result = _brandService.GetAll(); 26 | if (result.Success) 27 | { 28 | return Ok(result); 29 | } 30 | 31 | return BadRequest(result); 32 | } 33 | 34 | [HttpGet("getbyid")] 35 | public IActionResult GetById(int id) 36 | { 37 | var result = _brandService.GetById(id); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | 43 | return BadRequest(result); 44 | } 45 | 46 | [HttpPost("add")] 47 | public IActionResult Add(Brand brand) 48 | { 49 | var result = _brandService.Add(brand); 50 | if (result.Success) 51 | { 52 | return Ok(result); 53 | } 54 | 55 | return BadRequest(result); 56 | } 57 | 58 | [HttpPost("update")] 59 | public IActionResult Update(Brand brand) 60 | { 61 | var result = _brandService.Update(brand); 62 | if (result.Success) 63 | { 64 | return Ok(result); 65 | } 66 | 67 | return BadRequest(result); 68 | } 69 | 70 | [HttpPost("delete")] 71 | public IActionResult Delete(Brand brand) 72 | { 73 | var result = _brandService.Delete(brand); 74 | if (result.Success) 75 | { 76 | return Ok(result); 77 | } 78 | 79 | return BadRequest(result); 80 | 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /WebAPI/Controllers/ColorsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class ColorsController : ControllerBase 15 | { 16 | IColorService _colorService; 17 | 18 | public ColorsController(IColorService colorService) 19 | { 20 | _colorService = colorService; 21 | } 22 | [HttpGet("getall")] 23 | public IActionResult GetAll() 24 | { 25 | var result = _colorService.GetAll(); 26 | if (result.Success) 27 | { 28 | return Ok(result); 29 | } 30 | 31 | return BadRequest(result); 32 | } 33 | 34 | [HttpGet("getbyid")] 35 | public IActionResult GetById(int id) 36 | { 37 | var result = _colorService.GetById(id); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | 43 | return BadRequest(result); 44 | } 45 | 46 | [HttpPost("add")] 47 | public IActionResult Add(Color color) 48 | { 49 | var result = _colorService.Add(color); 50 | if (result.Success) 51 | { 52 | return Ok(result); 53 | } 54 | 55 | return BadRequest(result); 56 | } 57 | 58 | [HttpPost("update")] 59 | public IActionResult Update(Color color) 60 | { 61 | var result = _colorService.Update(color); 62 | if (result.Success) 63 | { 64 | return Ok(result); 65 | } 66 | 67 | return BadRequest(result); 68 | } 69 | 70 | [HttpPost("delete")] 71 | public IActionResult Delete(Color color) 72 | { 73 | var result = _colorService.Delete(color); 74 | if (result.Success) 75 | { 76 | return Ok(result); 77 | } 78 | 79 | return BadRequest(result); 80 | 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /WebAPI/Controllers/RentalsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class RentalsController : ControllerBase 15 | { 16 | IRentalService _rentalService; 17 | 18 | public RentalsController(IRentalService rentalService) 19 | { 20 | _rentalService = rentalService; 21 | } 22 | 23 | [HttpGet("getall")] 24 | public IActionResult GetAll() 25 | { 26 | var result = _rentalService.GetAll(); 27 | if (result.Success) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result); 32 | } 33 | 34 | [HttpGet("getbyid")] 35 | public IActionResult GetById(int id) 36 | { 37 | var result = _rentalService.GetById(id); 38 | if (result.Success) 39 | { 40 | return Ok(result); 41 | } 42 | 43 | return BadRequest(result); 44 | } 45 | 46 | 47 | [HttpPost("add")] 48 | public IActionResult Add(Rental rental) 49 | { 50 | var result = _rentalService.Add(rental); 51 | if (result.Success) 52 | { 53 | return Ok(result); 54 | } 55 | 56 | return BadRequest(result); 57 | } 58 | [HttpPost("delete")] 59 | public IActionResult Delete(Rental rental) 60 | { 61 | var result = _rentalService.Delete(rental); 62 | if (result.Success) 63 | { 64 | return Ok(result); 65 | } 66 | 67 | return BadRequest(result); 68 | } 69 | 70 | [HttpPost("update")] 71 | public IActionResult Update(Rental rental) 72 | { 73 | var result = _rentalService.Update(rental); 74 | if (result.Success) 75 | { 76 | return Ok(result); 77 | } 78 | 79 | return BadRequest(result); 80 | } 81 | 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CustomersController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.AspNetCore.Mvc; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Threading.Tasks; 10 | 11 | namespace WebAPI.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | [ApiController] 15 | public class CustomersController : ControllerBase 16 | { 17 | ICustomerService _customerService; 18 | 19 | public CustomersController(ICustomerService customerService) 20 | { 21 | _customerService = customerService; 22 | } 23 | 24 | [HttpGet("getall")] 25 | public IActionResult GetAll() 26 | { 27 | var result = _customerService.GetAll(); 28 | if (result.Success) 29 | { 30 | return Ok(result); 31 | } 32 | return BadRequest(result); 33 | } 34 | 35 | [HttpGet("getbyid")] 36 | public IActionResult GetById(int id) 37 | { 38 | var result = _customerService.GetById(id); 39 | if (result.Success) 40 | { 41 | return Ok(result); 42 | } 43 | 44 | return BadRequest(result); 45 | } 46 | 47 | 48 | [HttpPost("add")] 49 | public IActionResult Add(Customer customer) 50 | { 51 | var result = _customerService.Add(customer); 52 | if (result.Success) 53 | { 54 | return Ok(result); 55 | } 56 | 57 | return BadRequest(result); 58 | } 59 | [HttpPost("delete")] 60 | public IActionResult Delete(Customer customer) 61 | { 62 | var result = _customerService.Delete(customer); 63 | if (result.Success) 64 | { 65 | return Ok(result); 66 | } 67 | 68 | return BadRequest(result); 69 | } 70 | 71 | [HttpPost("update")] 72 | public IActionResult Update(Customer customer) 73 | { 74 | var result = _customerService.Update(customer); 75 | if (result.Success) 76 | { 77 | return Ok(result); 78 | } 79 | 80 | return BadRequest(result); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /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; 7 | using Core.Utilities.Security.JWT; 8 | using DataAccess.Abstract; 9 | using DataAccess.Concrete.EntityFrameWork; 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Text; 13 | 14 | namespace Business.DependencyResolvers.Autofac 15 | { 16 | public class AutofacBusinessModule:Module 17 | { 18 | protected override void Load(ContainerBuilder builder) 19 | { 20 | builder.RegisterType().As().SingleInstance(); 21 | builder.RegisterType().As().SingleInstance(); 22 | builder.RegisterType().As().SingleInstance(); 23 | builder.RegisterType().As().SingleInstance(); 24 | builder.RegisterType().As().SingleInstance(); 25 | builder.RegisterType().As().SingleInstance(); 26 | builder.RegisterType().As().SingleInstance(); 27 | builder.RegisterType().As().SingleInstance(); 28 | 29 | builder.RegisterType().As().SingleInstance(); 30 | builder.RegisterType().As().SingleInstance(); 31 | 32 | builder.RegisterType().As().SingleInstance(); 33 | builder.RegisterType().As().SingleInstance(); 34 | 35 | builder.RegisterType().As().SingleInstance(); 36 | builder.RegisterType().As().SingleInstance(); 37 | 38 | builder.RegisterType().As(); 39 | builder.RegisterType().As(); 40 | 41 | 42 | 43 | 44 | var assembly = System.Reflection.Assembly.GetExecutingAssembly(); 45 | 46 | builder.RegisterAssemblyTypes(assembly).AsImplementedInterfaces() 47 | .EnableInterfaceInterceptors(new ProxyGenerationOptions() { 48 | Selector = new AspectInterceptorSelector() 49 | }).SingleInstance(); 50 | 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Caching/Microsoft/MemoryCacheManager.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.IoC; 2 | using Microsoft.Extensions.Caching.Memory; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using Microsoft.Extensions.DependencyInjection; 7 | using System.Text.RegularExpressions; 8 | using System.Linq; 9 | 10 | namespace Core.CrossCuttingConcerns.Caching.Microsoft 11 | { 12 | public class MemoryCacheManager : ICacheManager 13 | { 14 | //Adapter pattern:sen benim sistemime göre çalışcaksın 15 | IMemoryCache _memoryCache; 16 | public MemoryCacheManager() 17 | { 18 | _memoryCache = ServiceTool.ServiceProvider.GetService(); 19 | 20 | } 21 | 22 | 23 | public void Add(string key, object value, int duration) 24 | { 25 | _memoryCache.Set(key, value, TimeSpan.FromMinutes(duration)); 26 | 27 | } 28 | 29 | public T Get(string key) 30 | { 31 | return _memoryCache.Get(key); 32 | } 33 | 34 | public object Get(string key) 35 | { 36 | return _memoryCache.Get(key); 37 | } 38 | 39 | public bool IsAdd(string key) 40 | { 41 | return _memoryCache.TryGetValue(key, out _); 42 | } 43 | 44 | public void Remove(string key) 45 | { 46 | _memoryCache.Remove(key); 47 | } 48 | //Bellekten silme 49 | public void RemoveByPattern(string pattern) 50 | { 51 | var cacheEntriesCollectionDefinition = typeof(MemoryCache).GetProperty("EntriesCollection", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); 52 | var cacheEntriesCollection = cacheEntriesCollectionDefinition.GetValue(_memoryCache) as dynamic; 53 | List cacheCollectionValues = new List(); 54 | 55 | foreach (var cacheItem in cacheEntriesCollection) 56 | { 57 | ICacheEntry cacheItemValue = cacheItem.GetType().GetProperty("Value").GetValue(cacheItem, null); 58 | cacheCollectionValues.Add(cacheItemValue); 59 | } 60 | 61 | var regex = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase); 62 | var keysToRemove = cacheCollectionValues.Where(d => regex.IsMatch(d.Key.ToString())).Select(d => d.Key).ToList(); 63 | 64 | foreach (var key in keysToRemove) 65 | { 66 | _memoryCache.Remove(key); 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Core/DataAccess/EntityFramework/EfEntityRepositoryBase.cs: -------------------------------------------------------------------------------- 1 | using Core.Abstract; 2 | using Core.Entities; 3 | using Microsoft.EntityFrameworkCore; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Linq.Expressions; 8 | using System.Text; 9 | 10 | namespace Core.DataAccess.EntityFramework 11 | { 12 | public class EfEntityRepositoryBase :IEntityRepository 13 | where TEntity:class,IEntity,new() 14 | where TContext: DbContext,new() 15 | { 16 | public void Add(TEntity entity) 17 | { 18 | //hem işimiz bittikten sonra gereksiz bellek harcamamak ve 19 | //performans artışını sağlamak için using bloğunu kullandım. 20 | 21 | using (TContext reCapDatabaseContext = new TContext()) 22 | { 23 | var addedEntity = reCapDatabaseContext.Entry(entity); 24 | addedEntity.State = EntityState.Added; 25 | reCapDatabaseContext.SaveChanges(); 26 | 27 | } 28 | } 29 | 30 | public void Delete(TEntity entity) 31 | { 32 | using (TContext reCapDatabaseContext = new TContext()) 33 | { 34 | var deletedEntity = reCapDatabaseContext.Entry(entity); 35 | deletedEntity.State = EntityState.Deleted; 36 | reCapDatabaseContext.SaveChanges(); 37 | } 38 | } 39 | 40 | public TEntity Get(Expression> filter) 41 | { 42 | using (TContext reCapDatabaseContext = new TContext()) 43 | { 44 | //tek bir data getiren methodumuz. 45 | return reCapDatabaseContext.Set().SingleOrDefault(filter); 46 | } 47 | } 48 | 49 | public List GetAll(Expression> filter = null) 50 | { 51 | //filtre zorunluluğu yok, Filtre kullanmazsam bütün dataları liste halinde döndürür. 52 | 53 | using (TContext reCapDatabaseContext = new TContext()) 54 | { 55 | return filter == null 56 | ? reCapDatabaseContext.Set().ToList() 57 | : reCapDatabaseContext.Set().Where(filter).ToList(); 58 | } 59 | } 60 | 61 | public void Update(TEntity entity) 62 | { 63 | using (TContext reCapDatabaseContext = new TContext()) 64 | { 65 | var updatedEntity = reCapDatabaseContext.Entry(entity); 66 | updatedEntity.State = EntityState.Modified; 67 | reCapDatabaseContext.SaveChanges(); 68 | 69 | } 70 | } 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /.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 Business.Constants; 3 | using Core.Entities.Concrete; 4 | using Core.Utilities.Results.Abstract; 5 | using Core.Utilities.Results.Concrete; 6 | using Core.Utilities.Security.Hashing; 7 | using Core.Utilities.Security.JWT; 8 | using Entities.DTOs; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Text; 12 | 13 | namespace Business.Concrete 14 | { 15 | public class 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 | Email = userForRegisterDto.Email, 32 | FirstName = userForRegisterDto.FirstName, 33 | LastName = userForRegisterDto.LastName, 34 | PasswordHash = passwordHash, 35 | PasswordSalt = passwordSalt, 36 | Status = true 37 | }; 38 | _userService.Add(user); 39 | return new SuccessDataResult(user, Messages.UserRegistered); 40 | } 41 | 42 | public IDataResult Login(UserForLoginDto userForLoginDto) 43 | { 44 | var userToCheck = _userService.GetByMail(userForLoginDto.Email); 45 | if (userToCheck == null) 46 | { 47 | return new ErrorDataResult(Messages.UserNotFound); 48 | } 49 | 50 | if (!HashingHelper.VerifyPasswordHash(userForLoginDto.Password, userToCheck.PasswordHash, userToCheck.PasswordSalt)) 51 | { 52 | return new ErrorDataResult(Messages.PasswordError); 53 | } 54 | 55 | return new SuccessDataResult(userToCheck, Messages.SuccessfulLogin); 56 | } 57 | 58 | public IResult UserExists(string email) 59 | { 60 | if (_userService.GetByMail(email) != null) 61 | { 62 | return new ErrorResult(Messages.UserAlreadyExists); 63 | } 64 | return new SuccessResult(); 65 | } 66 | 67 | public IDataResult CreateAccessToken(User user) 68 | { 69 | var claims = _userService.GetClaims(user); 70 | var accessToken = _tokenHelper.CreateToken(user, claims); 71 | return new SuccessDataResult(accessToken, Messages.AccessTokenCreated); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/JwtHelper.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Core.Extensions; 3 | using Core.Utilities.Security.Encryption; 4 | using Microsoft.Extensions.Configuration; 5 | using Microsoft.IdentityModel.Tokens; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.IdentityModel.Tokens.Jwt; 9 | using System.Linq; 10 | using System.Security.Claims; 11 | using System.Text; 12 | 13 | namespace Core.Utilities.Security.JWT 14 | { 15 | public class JwtHelper : ITokenHelper 16 | { 17 | public IConfiguration Configuration { get; } 18 | private TokenOptions _tokenOptions; 19 | private DateTime _accessTokenExpiration; 20 | public JwtHelper(IConfiguration configuration) 21 | { 22 | Configuration = configuration; 23 | _tokenOptions = Configuration.GetSection("TokenOptions").Get(); 24 | 25 | } 26 | public AccessToken CreateToken(User user, List operationClaims) 27 | { 28 | _accessTokenExpiration = DateTime.Now.AddMinutes(_tokenOptions.AccessTokenExpiration); 29 | var securityKey = SecurityKeyHelper.CreateSecurityKey(_tokenOptions.SecurityKey); 30 | var signingCredentials = SigningCredentialsHelper.CreateSigningCredentials(securityKey); 31 | var jwt = CreateJwtSecurityToken(_tokenOptions, user, signingCredentials, operationClaims); 32 | var jwtSecurityTokenHandler = new JwtSecurityTokenHandler(); 33 | var token = jwtSecurityTokenHandler.WriteToken(jwt); 34 | 35 | return new AccessToken { 36 | Token = token, 37 | Expiration = _accessTokenExpiration 38 | }; 39 | 40 | } 41 | 42 | public JwtSecurityToken CreateJwtSecurityToken(TokenOptions tokenOptions, User user, 43 | SigningCredentials signingCredentials, List operationClaims) 44 | { 45 | var jwt = new JwtSecurityToken( 46 | issuer: tokenOptions.Issuer, 47 | audience: tokenOptions.Audience, 48 | expires: _accessTokenExpiration, 49 | notBefore: DateTime.Now, 50 | claims: SetClaims(user, operationClaims), 51 | signingCredentials: signingCredentials 52 | ); 53 | return jwt; 54 | } 55 | 56 | private IEnumerable SetClaims(User user, List operationClaims) 57 | { 58 | var claims = new List(); 59 | claims.AddNameIdentifier(user.UserId.ToString()); 60 | claims.AddEmail(user.Email); 61 | claims.AddName($"{user.FirstName} {user.LastName}"); 62 | claims.AddRoles(operationClaims.Select(c => c.Name).ToArray()); 63 | 64 | return claims; 65 | } 66 | } 67 | // Extension : var olan bir dosyaya yeni metodlar eklemek (bize ait olmayan ) 68 | } 69 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CarImagesController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Hosting; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.AspNetCore.Mvc; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Threading.Tasks; 10 | using WebAPI.Models; 11 | 12 | namespace WebAPI.Controllers 13 | { 14 | [Route("api/[controller]")] 15 | [ApiController] 16 | public class CarImagesController : ControllerBase 17 | { 18 | public static ICarImageService _carImageService; 19 | 20 | public CarImagesController(ICarImageService carImageService) 21 | { 22 | _carImageService = carImageService; 23 | } 24 | 25 | [HttpGet("getall")] 26 | public IActionResult GetAll() 27 | { 28 | var result = _carImageService.GetAll(); 29 | if(result.Success) 30 | { 31 | return Ok(result); 32 | } 33 | return BadRequest(result); 34 | } 35 | 36 | [HttpGet("getbyid")] 37 | public IActionResult GetById([FromForm(Name ="Id")] int id) 38 | { 39 | var result = _carImageService.GetImageById(id); 40 | if(result.Success) 41 | { 42 | return Ok(result); 43 | 44 | } 45 | return BadRequest(result); 46 | 47 | } 48 | 49 | [HttpGet("getimagesbycarid")] 50 | public IActionResult GetImagesByCarId(int carId) 51 | { 52 | var result = _carImageService.GetImagesByCarId(carId); 53 | 54 | if (result.Success) 55 | { 56 | return Ok(result); 57 | 58 | } 59 | return BadRequest(result); 60 | } 61 | 62 | 63 | 64 | [HttpPost("add")] 65 | public IActionResult Add([FromForm(Name="Image")] 66 | 67 | IFormFile file, [FromForm] CarImage carImage) 68 | { 69 | 70 | var result = _carImageService.Add(file, carImage); 71 | if (result.Success) 72 | { 73 | return Ok(result); 74 | 75 | } 76 | return BadRequest(result); 77 | 78 | 79 | } 80 | 81 | [HttpPost("update")] 82 | public IActionResult Update([FromForm(Name = "Image")] IFormFile file, [FromForm] CarImage carImage) 83 | { 84 | var result = _carImageService.Update(file, carImage); 85 | if (result.Success) 86 | { 87 | return Ok(result); 88 | } 89 | 90 | return BadRequest(result); 91 | } 92 | 93 | [HttpGet("delete")] 94 | public IActionResult Delete([FromForm(Name = "Id")] int id) 95 | { 96 | var carImage = _carImageService.GetImageById(id).Data; 97 | var result = _carImageService.Delete(carImage); 98 | if (result.Success) 99 | { 100 | return Ok(result); 101 | } 102 | 103 | return BadRequest(result); 104 | } 105 | 106 | 107 | 108 | 109 | 110 | } 111 | } -------------------------------------------------------------------------------- /DataAccess/Concrete/InMemoryCarDal.cs: -------------------------------------------------------------------------------- 1 | using DataAccess.Abstract; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Linq.Expressions; 8 | using System.Text; 9 | 10 | namespace DataAccess.Concrete 11 | { 12 | public class InMemoryCarDal : ICarDal 13 | { 14 | //oracle,Sql Server gibi veri tabanlarını simüle ediyor. 15 | List _cars; 16 | 17 | public InMemoryCarDal() 18 | { 19 | _cars = new List 20 | { 21 | new Car{CarId=1,BrandId=1,ColorId=1, 22 | ModelYear="2011",DailyPrice=250, 23 | Descriptions="Opel Corsa Dizel Otomatik"}, 24 | 25 | new Car{CarId=2,BrandId=2,ColorId=2, 26 | ModelYear="2009",DailyPrice=520, 27 | Descriptions="Wolksvagen Passat Dizel Otomatik"}, 28 | 29 | new Car {CarId=3,BrandId=3,ColorId=3, 30 | ModelYear="2015",DailyPrice=450, 31 | Descriptions="Audi A3 Dizel Otomatik"}, 32 | 33 | new Car{CarId=4,BrandId=4,ColorId=4, 34 | ModelYear="2013",DailyPrice=85, 35 | Descriptions="Fiat Doblo"}, 36 | 37 | 38 | }; 39 | 40 | } 41 | 42 | public void Add(Car car) 43 | { 44 | _cars.Add(car); 45 | } 46 | 47 | public void Delete(Car car) 48 | { 49 | //LINQ ile 50 | 51 | Car carToDelete; 52 | carToDelete = _cars.SingleOrDefault(c =>c.CarId==car.CarId); 53 | _cars.Remove(carToDelete); 54 | 55 | } 56 | 57 | public Car Get(Expression> filter) 58 | { 59 | throw new NotImplementedException(); 60 | } 61 | 62 | public List GetAll() 63 | { 64 | return _cars; 65 | } 66 | 67 | public List GetAll(Expression> filter = null) 68 | { 69 | return _cars; 70 | } 71 | 72 | public List GetAllCarDetailsByFilter(CarDetailFilterDto filter) 73 | { 74 | throw new NotImplementedException(); 75 | } 76 | 77 | public List GetById(int id) 78 | { 79 | return _cars.Where(c =>c.CarId==id).ToList(); 80 | } 81 | 82 | public List GetCarDetails() 83 | { 84 | throw new NotImplementedException(); 85 | } 86 | 87 | public List GetCarDetails(Expression> filter = null) 88 | { 89 | throw new NotImplementedException(); 90 | } 91 | 92 | public void Update(Car car) 93 | { 94 | Car carToUpdate = _cars.SingleOrDefault(c=> c.CarId==car.CarId); 95 | carToUpdate.BrandId = car.BrandId; 96 | carToUpdate.ColorId = car.ColorId; 97 | carToUpdate.DailyPrice = car.DailyPrice; 98 | carToUpdate.Descriptions = car.Descriptions; 99 | 100 | 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /ReCapProject.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30804.86 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "Entities\Entities.csproj", "{EC621FF0-DD76-4AD2-86EA-9B465B9404E6}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAccess", "DataAccess\DataAccess.csproj", "{F2E551D9-79E0-45B1-8FA5-BAF1A7C4F6E8}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Business", "Business\Business.csproj", "{56FF520A-980A-4108-ACB5-F5002EB073AD}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleUI", "ConsoleUI\ConsoleUI.csproj", "{2776EC72-77E2-4290-8FB7-D20B16A311FC}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{4C899EDB-4079-4801-8F0F-CE1CF23F1A28}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPI", "WebAPI\WebAPI.csproj", "{24D1C3F9-766E-48A6-B77D-00230AAB3C91}" 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 | {EC621FF0-DD76-4AD2-86EA-9B465B9404E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {EC621FF0-DD76-4AD2-86EA-9B465B9404E6}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {EC621FF0-DD76-4AD2-86EA-9B465B9404E6}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {EC621FF0-DD76-4AD2-86EA-9B465B9404E6}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {F2E551D9-79E0-45B1-8FA5-BAF1A7C4F6E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {F2E551D9-79E0-45B1-8FA5-BAF1A7C4F6E8}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {F2E551D9-79E0-45B1-8FA5-BAF1A7C4F6E8}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {F2E551D9-79E0-45B1-8FA5-BAF1A7C4F6E8}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {56FF520A-980A-4108-ACB5-F5002EB073AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {56FF520A-980A-4108-ACB5-F5002EB073AD}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {56FF520A-980A-4108-ACB5-F5002EB073AD}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {56FF520A-980A-4108-ACB5-F5002EB073AD}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {2776EC72-77E2-4290-8FB7-D20B16A311FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {2776EC72-77E2-4290-8FB7-D20B16A311FC}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {2776EC72-77E2-4290-8FB7-D20B16A311FC}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {2776EC72-77E2-4290-8FB7-D20B16A311FC}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {4C899EDB-4079-4801-8F0F-CE1CF23F1A28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {4C899EDB-4079-4801-8F0F-CE1CF23F1A28}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {4C899EDB-4079-4801-8F0F-CE1CF23F1A28}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {4C899EDB-4079-4801-8F0F-CE1CF23F1A28}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {24D1C3F9-766E-48A6-B77D-00230AAB3C91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {24D1C3F9-766E-48A6-B77D-00230AAB3C91}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {24D1C3F9-766E-48A6-B77D-00230AAB3C91}.Release|Any CPU.ActiveCfg = Release|Any CPU 47 | {24D1C3F9-766E-48A6-B77D-00230AAB3C91}.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 = {318842C8-C113-4794-B025-895D58B6D6F1} 54 | EndGlobalSection 55 | EndGlobal 56 | -------------------------------------------------------------------------------- /Core/Utilities/Helpers/FileHelper.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results.Abstract; 2 | using Core.Utilities.Results.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.IO; 7 | using System.Text; 8 | 9 | namespace Core.Utilities.Helpers 10 | { 11 | public class FileHelper 12 | { 13 | 14 | 15 | private static string _currentDirectory = Environment.CurrentDirectory + "\\wwwroot"; 16 | private static string _folderName = "\\images\\"; 17 | 18 | public static IResult Upload(IFormFile file) 19 | { 20 | var fileExists = CheckFileExists(file); 21 | if (fileExists.Message != null) 22 | { 23 | return new ErrorResult(fileExists.Message); 24 | } 25 | 26 | var type = Path.GetExtension(file.FileName); 27 | var typeValid = CheckFileTypeValid(type); 28 | var randomName = Guid.NewGuid().ToString(); 29 | 30 | if (typeValid.Message != null) 31 | { 32 | return new ErrorResult(typeValid.Message); 33 | } 34 | 35 | CheckDirectoryExists(_currentDirectory + _folderName); 36 | CreateImageFile(_currentDirectory + _folderName + randomName + type, file); 37 | return new SuccessResult((_folderName + randomName + type).Replace("\\", "/")); 38 | 39 | 40 | 41 | } 42 | 43 | public static IResult Update(IFormFile file, string imagePath) 44 | { 45 | var fileExists = CheckFileExists(file); 46 | if (fileExists.Message != null) 47 | { 48 | return new ErrorResult(fileExists.Message); 49 | } 50 | 51 | var type = Path.GetExtension(file.FileName); 52 | var typeValid = CheckFileTypeValid(type); 53 | var randomName = Guid.NewGuid().ToString(); 54 | 55 | if (typeValid.Message != null) 56 | { 57 | return new ErrorResult(typeValid.Message); 58 | } 59 | 60 | DeleteOldImageFile((_currentDirectory + imagePath).Replace("/", "\\")); 61 | CheckDirectoryExists(_currentDirectory + _folderName); 62 | CreateImageFile(_currentDirectory + _folderName + randomName + type, file); 63 | return new SuccessResult((_folderName + randomName + type).Replace("\\", "/")); 64 | } 65 | 66 | public static IResult Delete(string path) 67 | { 68 | DeleteOldImageFile((_currentDirectory + path).Replace("/", "\\")); 69 | return new SuccessResult(); 70 | } 71 | 72 | 73 | 74 | 75 | private static IResult CheckFileExists(IFormFile file) 76 | { 77 | if (file != null && file.Length > 0) 78 | { 79 | return new SuccessResult(); 80 | } 81 | return new ErrorResult("File doesn't exists."); 82 | } 83 | 84 | 85 | private static IResult CheckFileTypeValid(string type) 86 | { 87 | if (type != ".jpeg" && type != ".png" && type != ".jpg") 88 | { 89 | return new ErrorResult("Wrong file type."); 90 | } 91 | return new SuccessResult(); 92 | } 93 | 94 | private static void CheckDirectoryExists(string directory) 95 | { 96 | if (!Directory.Exists(directory)) 97 | { 98 | Directory.CreateDirectory(directory); 99 | } 100 | } 101 | private static void CreateImageFile(string directory, IFormFile file) 102 | { 103 | using (FileStream fs = File.Create(directory)) 104 | { 105 | file.CopyTo(fs); 106 | fs.Flush(); 107 | } 108 | } 109 | 110 | private static void DeleteOldImageFile(string directory) 111 | { 112 | if (File.Exists(directory.Replace("/", "\\"))) 113 | { 114 | File.Delete(directory.Replace("/", "\\")); 115 | } 116 | 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Rules in this file were initially inferred by Visual Studio IntelliCode from the C:\Users\kader tekin\source\repos\kadernur\ReCapProject codebase based on best match to current usage at 19.02.2021 2 | # You can modify the rules from these initially generated values to suit your own policies 3 | # You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference 4 | [*.cs] 5 | 6 | 7 | #Core editorconfig formatting - indentation 8 | 9 | #use soft tabs (spaces) for indentation 10 | indent_style = space 11 | 12 | #Formatting - new line options 13 | 14 | #require members of object intializers to be on separate lines 15 | csharp_new_line_before_members_in_object_initializers = true 16 | #require braces to be on a new line for methods, types, and control_blocks (also known as "Allman" style) 17 | csharp_new_line_before_open_brace = methods, types, control_blocks 18 | 19 | #Formatting - organize using options 20 | 21 | #do not place System.* using directives before other using directives 22 | dotnet_sort_system_directives_first = false 23 | 24 | #Formatting - spacing options 25 | 26 | #require a space after a keyword in a control flow statement such as a for loop 27 | csharp_space_after_keywords_in_control_flow_statements = true 28 | #remove space within empty argument list parentheses 29 | csharp_space_between_method_call_empty_parameter_list_parentheses = false 30 | #remove space between method call name and opening parenthesis 31 | csharp_space_between_method_call_name_and_opening_parenthesis = false 32 | #do not place space characters after the opening parenthesis and before the closing parenthesis of a method call 33 | csharp_space_between_method_call_parameter_list_parentheses = false 34 | #remove space within empty parameter list parentheses for a method declaration 35 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false 36 | #place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list. 37 | csharp_space_between_method_declaration_parameter_list_parentheses = false 38 | 39 | #Formatting - wrapping options 40 | 41 | #leave code block on single line 42 | csharp_preserve_single_line_blocks = true 43 | 44 | #Style - Code block preferences 45 | 46 | #prefer curly braces even for one line of code 47 | csharp_prefer_braces = true:suggestion 48 | 49 | #Style - expression bodied member options 50 | 51 | #prefer block bodies for constructors 52 | csharp_style_expression_bodied_constructors = false:suggestion 53 | #prefer block bodies for methods 54 | csharp_style_expression_bodied_methods = false:suggestion 55 | 56 | #Style - Expression-level preferences 57 | 58 | #prefer objects to be initialized using object initializers when possible 59 | dotnet_style_object_initializer = true:suggestion 60 | 61 | #Style - implicit and explicit types 62 | 63 | #prefer var over explicit type in all cases, unless overridden by another code style rule 64 | csharp_style_var_elsewhere = true:suggestion 65 | #prefer explicit type over var when the type is already mentioned on the right-hand side of a declaration 66 | csharp_style_var_when_type_is_apparent = false:suggestion 67 | 68 | #Style - language keyword and framework type options 69 | 70 | #prefer the language keyword for local variables, method parameters, and class members, instead of the type name, for types that have a keyword to represent them 71 | dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion 72 | 73 | #Style - modifier options 74 | 75 | #prefer accessibility modifiers to be declared except for public interface members. This will currently not differ from always and will act as future proofing for if C# adds default interface methods. 76 | dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion 77 | 78 | #Style - Modifier preferences 79 | 80 | #when this rule is set to a list of modifiers, prefer the specified ordering. 81 | csharp_preferred_modifier_order = public,protected,static,override:suggestion 82 | 83 | #Style - qualification options 84 | 85 | #prefer fields not to be prefaced with this. or Me. in Visual Basic 86 | dotnet_style_qualification_for_field = false:suggestion 87 | -------------------------------------------------------------------------------- /Business/Concrete/CarManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.BusinessAspect; 3 | using Business.Constants; 4 | using Business.ValidationRules.FluentValidation; 5 | using Core.Aspects.Autofac.Caching; 6 | using Core.Aspects.Autofac.Performance; 7 | using Core.Aspects.Autofac.Validation; 8 | using Core.Utilities.Results.Abstract; 9 | using Core.Utilities.Results.Concrete; 10 | using DataAccess.Abstract; 11 | using Entities.Concrete; 12 | using Entities.DTOs; 13 | using System; 14 | using System.Collections.Generic; 15 | using System.Linq; 16 | using System.Text; 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 | 30 | [SecuredOperation("admin,product.add")] 31 | [ValidationAspect(typeof(CarValidator))] 32 | [CacheRemoveAspect("IProductService.Get")] 33 | public IResult Add(Car car) 34 | { 35 | _carDal.Add(car); 36 | return new SuccessResult(Messages.Added); 37 | } 38 | 39 | public IResult AddTransactionalTest(Car car) 40 | { 41 | throw new NotImplementedException(); 42 | } 43 | 44 | public IResult Delete(Car car) 45 | { 46 | _carDal.Delete(car); 47 | return new SuccessResult(Messages.Deleted); 48 | } 49 | [CacheAspect] 50 | public IDataResult> GetAll() 51 | { 52 | return new SuccessDataResult>(_carDal.GetAll()); 53 | } 54 | [CacheAspect] 55 | public IDataResult> GetByCategoryId(int categoryId) 56 | { 57 | return null; 58 | } 59 | 60 | public IDataResult> GetByDailyPrice(decimal min, decimal max) 61 | { 62 | return new SuccessDataResult>(_carDal.GetAll(c => c.DailyPrice >= min && c.DailyPrice <= max)); 63 | } 64 | 65 | public IDataResult GetCarById(int id) 66 | { 67 | return new SuccessDataResult(_carDal.Get(c => c.CarId == id)); 68 | } 69 | 70 | public IDataResult> GetCarDetail(int carId) 71 | { 72 | if (DateTime.Now.Hour == 5) 73 | { 74 | return new ErrorDataResult>(Messages.Maintenancetime); 75 | } 76 | return new SuccessDataResult>(_carDal.GetCarDetails(cardetail => cardetail.CarId == carId)); 77 | } 78 | 79 | public IDataResult> GetCarDetails() 80 | { 81 | return new SuccessDataResult>(_carDal.GetCarDetails(), ""); 82 | } 83 | 84 | public IDataResult> GetCarsByBrandId(int brandId) 85 | { 86 | throw new NotImplementedException(); 87 | } 88 | 89 | public IDataResult> GetCarsDetailByBrandId(int brandId) 90 | { 91 | List carDetails = _carDal.GetCarDetails(p => p.BrandId == brandId); 92 | if (carDetails == null) 93 | { 94 | return new ErrorDataResult>(""); 95 | } 96 | else 97 | { 98 | return new SuccessDataResult>(carDetails, ""); 99 | } 100 | } 101 | 102 | public IDataResult> GetCarsDetailByColorId(int colorId) 103 | { 104 | List carDetails = _carDal.GetCarDetails(p => p.ColorId == colorId); 105 | if (carDetails == null) 106 | { 107 | return new ErrorDataResult>(""); 108 | } 109 | else 110 | { 111 | return new SuccessDataResult>(carDetails, ""); 112 | } 113 | } 114 | 115 | public IDataResult> GetCarsFiltreDetails(CarDetailFilterDto filterDto) 116 | { 117 | return new SuccessDataResult>(_carDal.GetAllCarDetailsByFilter(filterDto)); 118 | } 119 | 120 | [ValidationAspect(typeof(CarValidator))] 121 | [CacheRemoveAspect("IProductService.Get")] 122 | public IResult Update(Car car) 123 | { 124 | _carDal.Update(car); 125 | return new SuccessResult(Messages.Updated); 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CarsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.AspNetCore.Mvc; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | 12 | namespace WebAPI.Controllers 13 | { 14 | [Route("api/[controller]")] 15 | [ApiController] 16 | public class CarsController : ControllerBase 17 | { 18 | ICarService _carService; 19 | public CarsController(ICarService carService) 20 | { 21 | _carService = carService; 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("getbycategory")] 34 | public IActionResult GetByCategoryId(int categoryId) 35 | { 36 | var result = _carService.GetByCategoryId(categoryId); 37 | if (result.Success) 38 | { 39 | return Ok(result); 40 | } 41 | return BadRequest(result); 42 | } 43 | [HttpGet("getbycolor")] 44 | public IActionResult GetCarByColor(int colorId) 45 | { 46 | var result = _carService.GetCarsDetailByColorId(colorId); 47 | if (result.Success) 48 | { 49 | return Ok(result); 50 | } 51 | return BadRequest(result); 52 | } 53 | 54 | [HttpGet("getbyid")] 55 | public IActionResult GetById(int carId) 56 | { 57 | var result = _carService.GetCarById(carId); 58 | if (result.Success) 59 | { 60 | return Ok(result); 61 | } 62 | 63 | return BadRequest(result); 64 | } 65 | 66 | [HttpGet("getcarsbybrand")] 67 | public IActionResult GetCarsByBrandId(int brandId) 68 | { 69 | var result = _carService.GetCarsByBrandId(brandId); 70 | if (result.Success) 71 | { 72 | return Ok(result); 73 | } 74 | 75 | return BadRequest(result); 76 | } 77 | 78 | [HttpGet("getcardetail")] 79 | public IActionResult GetCarDetails(int carId) 80 | { 81 | var result = _carService.GetCarDetail(carId); 82 | if (result.Success) 83 | { 84 | return Ok(result); 85 | } 86 | 87 | return BadRequest(result); 88 | } 89 | [HttpGet("getcardetails")] 90 | public IActionResult GetCarDetails() 91 | { 92 | var result = _carService.GetCarDetails(); 93 | if (result.Success) 94 | { 95 | return Ok(result); 96 | } 97 | 98 | return BadRequest(result); 99 | } 100 | [HttpGet("getbybrand")] 101 | public IActionResult GetByBrand(int brandId) 102 | { 103 | var result = _carService.GetCarsDetailByBrandId(brandId); 104 | if (result.Success) 105 | { 106 | return Ok(result); 107 | } 108 | 109 | return BadRequest(result); 110 | } 111 | [HttpPost("add")] 112 | public IActionResult Add(Car car) 113 | { 114 | var result = _carService.Add(car); 115 | if (result.Success) 116 | { 117 | return Ok(result); 118 | } 119 | 120 | return BadRequest(result); 121 | } 122 | 123 | [HttpPost("delete")] 124 | public IActionResult Delete(Car car) 125 | { 126 | var result = _carService.Delete(car); 127 | if (result.Success) 128 | { 129 | return Ok(result); 130 | } 131 | return BadRequest(result); 132 | } 133 | 134 | [HttpPost("update")] 135 | public IActionResult Update(Car car) 136 | { 137 | var result = _carService.Update(car); 138 | if (result.Success) 139 | { 140 | return Ok(result); 141 | } 142 | return BadRequest(result); 143 | 144 | } 145 | [HttpGet("getcarsfilterdetails")] 146 | public IActionResult GetCarsDetails([FromQuery] CarDetailFilterDto filterDto) 147 | { 148 | var result = _carService.GetCarsFiltreDetails(filterDto); 149 | if (result.Success) 150 | { 151 | return Ok(result); 152 | } 153 | return BadRequest(result); 154 | } 155 | 156 | } 157 | } 158 | 159 | -------------------------------------------------------------------------------- /Business/Concrete/CarImageManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Core.Utilities.Business; 4 | using Core.Utilities.Helpers; 5 | using Core.Utilities.Results.Abstract; 6 | using Core.Utilities.Results.Concrete; 7 | using DataAccess.Abstract; 8 | using Entities.Concrete; 9 | using Microsoft.AspNetCore.Http; 10 | using System; 11 | using System.Collections.Generic; 12 | using System.IO; 13 | using System.Linq; 14 | using System.Text; 15 | 16 | namespace Business.Concrete 17 | { 18 | public class CarImageManager : ICarImageService 19 | { 20 | public ICarImageDal _carImageDal; 21 | 22 | public CarImageManager(ICarImageDal carImageDal) 23 | { 24 | _carImageDal = carImageDal; 25 | } 26 | 27 | public IResult Add(IFormFile formFile, CarImage carImage) 28 | { 29 | var imageCount = _carImageDal.GetAll(c => c.CarId == carImage.CarId).Count; 30 | 31 | if (imageCount >= 5) 32 | { 33 | return new ErrorResult("One car must have 5 or less images"); 34 | } 35 | 36 | var imageResult = FileHelper.Upload(formFile); 37 | 38 | if (!imageResult.Success) 39 | { 40 | return new ErrorResult(imageResult.Message); 41 | } 42 | carImage.ImagePath = imageResult.Message; 43 | _carImageDal.Add(carImage); 44 | return new SuccessResult(Messages.Added); 45 | 46 | } 47 | 48 | 49 | 50 | public IResult Delete( CarImage carImage) 51 | { 52 | var image = _carImageDal.Get(c => c.Id == carImage.Id); 53 | if (image == null) 54 | { 55 | return new ErrorResult("Image not found"); 56 | } 57 | 58 | FileHelper.Delete(image.ImagePath); 59 | _carImageDal.Delete(carImage); 60 | return new SuccessResult(Messages.Deleted); 61 | 62 | 63 | 64 | 65 | } 66 | 67 | 68 | public IDataResult> GetAll() 69 | { 70 | 71 | return new SuccessDataResult>(_carImageDal.GetAll()); 72 | 73 | 74 | } 75 | 76 | 77 | 78 | 79 | 80 | 81 | public IDataResult GetImageById(int id) 82 | { 83 | 84 | return new SuccessDataResult(_carImageDal.Get(p => p.Id == id)); 85 | 86 | } 87 | 88 | 89 | 90 | public IDataResult> GetImagesByCarId(int id) 91 | { 92 | var result = _carImageDal.GetAll(c => c.CarId == id); 93 | if (result.Count == 0) 94 | { 95 | var defaultImage = DefaultImage(id); 96 | return new SuccessDataResult>(defaultImage.Data); 97 | } 98 | 99 | return new SuccessDataResult>(result); 100 | 101 | 102 | } 103 | 104 | private IDataResult> DefaultImage(int id) 105 | { 106 | List carImages = new List 107 | { 108 | new CarImage 109 | { 110 | CarId = id, ImagePath = ($@"{Environment.CurrentDirectory}\wwwroot\Images\default.jpg") 111 | } 112 | }; 113 | return new SuccessDataResult>(carImages); 114 | } 115 | 116 | 117 | 118 | public IResult Update(IFormFile formFile, CarImage carImage) 119 | { 120 | var isImage = _carImageDal.Get(c => c.Id == carImage.Id); 121 | if (isImage == null) 122 | { 123 | return new ErrorResult("Image not found"); 124 | } 125 | 126 | var updatedFile = FileHelper.Update(formFile , isImage.ImagePath); 127 | if (!updatedFile.Success) 128 | { 129 | return new ErrorResult(updatedFile.Message); 130 | } 131 | carImage.ImagePath = updatedFile.Message; 132 | _carImageDal.Update(carImage); 133 | return new SuccessResult(Messages.Updated); 134 | 135 | 136 | 137 | } 138 | 139 | 140 | 141 | 142 | private IResult CheckIfCarImageLimitExceeded(int carId) 143 | { 144 | var carImagecount = _carImageDal.GetAll(p => p.CarId == carId).Count; 145 | if (carImagecount >= 5) 146 | { 147 | return new ErrorResult(Messages.CarOfImageLimitExceeded); 148 | } 149 | 150 | return new SuccessResult(); 151 | } 152 | 153 | 154 | private IDataResult> CheckIfCarImageNull(int id) 155 | { 156 | try 157 | { 158 | string path = @"\images\logo.jpg"; 159 | var result = _carImageDal.GetAll(c => c.CarId == id).Any(); 160 | if (!result) 161 | { 162 | List carimage = new List(); 163 | carimage.Add(new CarImage { CarId = id, ImagePath = path, CarImageDate= DateTime.Now }); 164 | return new SuccessDataResult>(carimage); 165 | } 166 | } 167 | catch (Exception exception) 168 | { 169 | 170 | return new ErrorDataResult>(exception.Message); 171 | } 172 | 173 | return new SuccessDataResult>(_carImageDal.GetAll(p => p.CarId == id).ToList()); 174 | } 175 | private IResult CarImageDelete(CarImage carImage) 176 | { 177 | try 178 | { 179 | File.Delete(carImage.ImagePath); 180 | } 181 | catch (Exception exception) 182 | { 183 | 184 | return new ErrorResult(exception.Message); 185 | } 186 | 187 | return new SuccessResult(); 188 | } 189 | 190 | } 191 | 192 | } 193 | -------------------------------------------------------------------------------- /ConsoleUI/Program.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Concrete; 3 | using DataAccess.Concrete; 4 | using DataAccess.Concrete.EntityFrameWork; 5 | using Entities.Concrete; 6 | using System; 7 | 8 | namespace ConsoleUI 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | //CarTest(); 15 | 16 | //ColorTest(); 17 | // DtoTest(); 18 | 19 | CarCrudTest(); 20 | 21 | 22 | // ColorCrudTest(); 23 | //BrandCrudTest(); 24 | 25 | IRentalService _rentalManager = new RentalManager(new EfRentalDal()); 26 | Console.WriteLine(_rentalManager.Add(new Rental { CarId = 2, CustomerId = 1, RentDate = new DateTime(2021, 01, 01), ReturnDate = new DateTime(2021, 03, 11) }).Message); 27 | 28 | } 29 | 30 | private static void BrandCrudTest() 31 | { 32 | BrandManager _brandManager = new BrandManager(new EfBrandDal()); 33 | 34 | Console.WriteLine("Tüm markalarımız:"); 35 | foreach (var brand in _brandManager.GetAll().Data) 36 | { 37 | Console.WriteLine(brand.BrandName); 38 | } 39 | 40 | Console.WriteLine("İstediğiniz marka:"); 41 | Console.WriteLine(_brandManager.GetById(1).Data.BrandName); 42 | 43 | Console.WriteLine("Marka eklendi."); 44 | _brandManager.Add(new Brand() { BrandName = "Hyundai" }); 45 | 46 | Console.WriteLine("Marka güncellendi"); 47 | _brandManager.Update(new Brand() { BrandId = 5, BrandName = "Aston Martin" }); 48 | 49 | Console.WriteLine("Marka silindi"); 50 | _brandManager.Delete(new Brand() { BrandId = 5 }); 51 | } 52 | 53 | private static void ColorCrudTest() 54 | { 55 | ColorManager _colorManager = new ColorManager(new EfColorDal()); 56 | 57 | Console.WriteLine("Tüm renklerimiz:"); 58 | foreach (var color in _colorManager.GetAll().Data) 59 | { 60 | Console.WriteLine(color.ColorName); 61 | } 62 | 63 | Console.WriteLine("İstediğiniz renk:"); 64 | Console.WriteLine(_colorManager.GetById(1).Data.ColorName); 65 | 66 | Console.WriteLine("renk eklendi."); 67 | _colorManager.Add(new Color() { ColorName = "Turuncu" }); 68 | 69 | Console.WriteLine("renk güncellendi"); 70 | _colorManager.Update(new Color() { ColorId = 6, ColorName = "Fuşya" }); 71 | 72 | Console.WriteLine("renk silindi"); 73 | _colorManager.Delete(new Color() { ColorId = 6 }); 74 | } 75 | 76 | private static void CarCrudTest() 77 | { 78 | CarManager _carManager = new CarManager(new EfCarDal()); 79 | Console.WriteLine("Tüm Araçlarımız: "); 80 | foreach (var car in _carManager.GetAll().Data) 81 | { 82 | Console.WriteLine(car.Descriptions); 83 | } 84 | 85 | Console.WriteLine("\n \n " + "İstediğimiz araç :"); 86 | Console.WriteLine(_carManager.GetById(1012).Data.CarName); 87 | 88 | Console.WriteLine("Aracınız Eklendi: "); 89 | _carManager.Add(new Car() { 90 | BrandId = 3, 91 | ColorId = 4, 92 | DailyPrice = 2, 93 | Descriptions = "Fiat Linea", 94 | CarName="Yeni Model", 95 | ModelYear = "2012" 96 | 97 | 98 | }); 99 | Console.WriteLine("Aracınız Silindi"); 100 | _carManager.Delete(new Car() { CarId = 2012 }); 101 | } 102 | 103 | private static void DtoTest() 104 | { 105 | EfCarDal _efCarDal = new EfCarDal(); 106 | foreach (var car in _efCarDal.GetCarDetails()) 107 | { 108 | Console.WriteLine( 109 | car.CarName + "/" + 110 | car.ColorName + "/" + 111 | car.BrandName + "/" + 112 | car.DailyPrice + "TL"); 113 | 114 | } 115 | Console.Read(); 116 | } 117 | 118 | private static void ColorTest() 119 | { 120 | ColorManager colorManager = new ColorManager(new EfColorDal()); 121 | 122 | foreach (var color in colorManager.GetAll().Data) 123 | 124 | { 125 | Console.WriteLine(color.ColorName); 126 | } 127 | } 128 | 129 | private static void CarTest() 130 | { 131 | CarManager carManager = new CarManager(new InMemoryCarDal()); 132 | 133 | /* foreach (var car in carManager.GetAll()) 134 | 135 | { 136 | 137 | Console.WriteLine("Car of Description: "+car.Description); 138 | Console.WriteLine("Car of Id: "+car.Id); 139 | Console.WriteLine("Car of BrandId: "+car.BrandId); 140 | Console.WriteLine("Car of ColorId: "+car.ColorId); 141 | Console.WriteLine("************************************"); 142 | 143 | }*/ 144 | 145 | foreach (var car in carManager.GetAll().Data) 146 | { 147 | Console.WriteLine(car.CarId + " " + car.ModelYear + " " + car.DailyPrice + " " + car.Descriptions); 148 | } 149 | Console.WriteLine("****************************"); 150 | 151 | foreach (var car in carManager.GetCarsByBrandId(2).Data) 152 | { 153 | Console.WriteLine(car.Descriptions); 154 | } 155 | Console.WriteLine("****************************"); 156 | 157 | foreach (var car in carManager.GetCarsByColorId(3).Data) 158 | { 159 | Console.WriteLine(car.Descriptions); 160 | } 161 | Console.WriteLine("****************************"); 162 | 163 | carManager.Add(new Car { 164 | CarId = 7, 165 | BrandId = 4, 166 | ColorId = 1, 167 | DailyPrice = 500, 168 | Descriptions = "Tesle Model 3", 169 | ModelYear = "2015" 170 | }); 171 | 172 | foreach (var car in carManager.GetAll().Data) 173 | { 174 | Console.WriteLine(car.CarId + " " + car.ModelYear + " " + car.DailyPrice + " " + car.Descriptions); 175 | } 176 | } 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Araba kiralama sistemi. 3 | 4 | ![cAR](https://user-images.githubusercontent.com/63293055/107887599-3e4c0600-6f18-11eb-81c9-acd5b5b4bf31.jpg) 5 | 6 | @ReCapProject projem benim gelişimimle beraber gelişmekte olan güzel bir proje. :+1: 7 | Bu projede katmanlı mimari yapısını kullanmaya çalıştım ve projeyi oluştururken SOLID prensiplerine uygun kodlar yazmaya çalıştım ve çalışmaya devam edeceğim. Bu projede "CODE RAFACTORİNG (Kodları iyileştirme) " yaparak ilerleme sağlayacağım. :collision: 8 | 9 | ### :loud_sound::boom: GÜNCELLEME(20.02.2021) 10 | :purple_circle: Projeye Core katmanı eklendi. 11 | :purple_circle: DTOs klasörü eklendi. 12 | :purple_circle: Code refactoring yaparak IEntitiyRepository,IEntity classları Core katmanına yerleştirildi. 13 | :purple_circle: IEntityRepositoryBase class'ı oluşturuldu. 14 | :purple_circle: Car,Color ve Brand nesnelerinin Crud operasyonları eklendi.program.cs 'de test edildi. 15 | 16 | ### :loud_sound::boom: GÜNCELLEME(22.02.2021) 17 | :brown_circle: Projeye Result yaoıları eklendi. 18 | :brown_circle: Magic strings yapısı kullanıldı. 19 | :brown_circle: Business classında code refactoring yapıldı. Abstract ve Concrete sınıflarındaki class'lar generic yapısıyla değiştirildi. 20 | 21 | ### :loud_sound::boom: GÜNCELLEME(01.03.2021) 22 | :large_blue_circle: Projeye WebAPI katmanı eklendi.Bu katmanda Business katmanındaki tüm servislerin API karşılğı yazılıp postman test aracında test edildi. 23 | 24 | ### :loud_sound::boom: GÜNCELLEME(03.03.2021) 25 | :white_circle: Projeye Autofac desteği eklendi. 26 | :white_circle:FluentValidation desteği eklendi. 27 | :white_circle:Aop desteği eklendi(ValidationAspect). 28 | 29 | 30 | ### :loud_sound::boom: GÜNCELLEME(19.03.2021) 31 | :purple_circle: Cache, Transaction ve Performance aspectlerini eklendi 32 | :purple_circle:JWT entegrasyonu yapıldı 33 | :purple_circle:CarImages (Araba Resimleri) tablosu oluşturuldu. 34 | :purple_circle:Api üzerinden arabaya resim ekleyecek sistem yazıldı. 35 | 36 | 37 | ## İçindekiler 38 | ### BUSİNESS KATMANI 39 | 40 | Bu katmanda iş kodlarımı yazdım. 41 | + [Abstract:open_file_folder: :(İlgili soyut Sınıflarımı içerir.)](https://github.com/kadernur/ReCapProject/tree/master/Business/Abstract) 42 | + ICarService.cs 43 | + :purple_circle:IColorService.cs 44 | + :purple_circle:IBrandService.cs 45 | + [ Concrete:open_file_folder: : (Somut sınıflarımı içerir.)](https://github.com/kadernur/ReCapProject/tree/master/Business/Concrete) 46 | + CarManager.cs 47 | + :purple_circle:ColorManager.cs 48 | + :purple_circle:BrandManager.cs 49 | 50 | + [:brown_circle: Constants :open_file_folder:(sabitlerimizi içeren klasör](https://github.com/kadernur/ReCapProject/tree/master/Business/Constants) 51 | + Messages.cs :brown_circle: :point_right:magic string ifadelerimizi içeren classtır. Yani projede kullandığımız sabit mesajları içerir. 52 | 53 | + [:white_circle: DependencyResolvers:open_file_folder:](https://github.com/kadernur/ReCapProject/tree/master/Business/DependencyResolvers/Autofac) 54 | Autofac desteği sağladık.IOC yapısını burda sağlamış olduk. 55 | + [:white_circle: ValidationRules :open_file_folder:](https://github.com/kadernur/ReCapProject/tree/master/Business/ValidationRules/FluentValidation) 56 | Var olan varlığı iş kurallarına dahil etmek için yapısal olarak uygun olup olmadığını kontrol yapımız burda mevcuttur. 57 | 58 | 59 | 60 | 61 | ### :purple_circle: CORE KATMANI 62 | Evrensel kodlarımızı kullandığımız katmanımızdır. 63 | Core katmanı diğer katmanları referans almaz. 64 | + [ DataAceess :open_file_folder:](https://github.com/kadernur/ReCapProject/tree/master/Core/DataAccess) 65 | + [EntityFramework :open_file_folder:](https://github.com/kadernur/ReCapProject/tree/master/Core/DataAccess/EntityFramework) 66 | + EfEntityRepository.cs :point_right: Burda kodları evrensel hale getirip farklı sistemler'e implemente etmemi sağlar. 67 | + IEntityRepository :point_right: Data Access katmanındaki bu class'ı evrensel olabilmesi için Core katmanına taşıdım. 68 | + [Entities :open_file_folder:](https://github.com/kadernur/ReCapProject/tree/master/Core/Entities) 69 | + IDto.cs 70 | + IEntity.cs :point_right: Entites katmanından buraya taşıdım. 71 | 72 | + [:brown_circle:Utilities :open_file_folder:](https://github.com/kadernur/ReCapProject/tree/master/Core/Utilities/Results) Restful(JSON) sürecinin gereksinimlerini içerir. Yani Request(istek) ve Response(yanıt) sürecini yönetebilmek için ortam hazırlar. 73 | + :brown_circle: Results :open_file_folder: 74 | + :brown_circle:Abstract 75 | + IDataResult.cs :point_right: bu interface message ,success yanında data da içermesini istenen işlemlerde kullanılır. 76 | + IResult.cs :point_right: void tipinde olan veriler için success ve message bilgilerini içerir 77 | 78 | + :brown_circle:Concrete :poin_right:Result türleri için işlemin başarılı ve başarısız olma durumuna göre geçerli classları içeirir. 79 | + DataResult.cs 80 | + ErrorDataResult.cs 81 | + SuccessDataResult.cs 82 | + Result.cs 83 | + SuccessResult.cs 84 | + ErrorResult.cs 85 | + [:white_circle: Aspects :open_file_folder:](https://github.com/kadernur/ReCapProject/tree/master/Core/Aspects/Autofac/Validation) 86 | AOP yapısı kullanıldı. 87 | 88 | + [:white_circle: CrossCuttingConcerns :open_file_folder:](https://github.com/kadernur/ReCapProject/tree/master/Core/CrossCuttingConcerns/Validation) 89 | Validation yapısını ValidationTool altında genelleştirdim. 90 | 91 | 92 | ### DATA ACCESS KATMANI 93 | Veriye ulaşmak için yazdığım katman kısacası SQL kodlarımın mevcut olduğu katman 94 | 95 | + [Abstract:open_file_folder: :(İlgili soyut Sınıflarımı içerir.)](https://github.com/kadernur/ReCapProject/tree/master/DataAccess/Abstract) 96 | + ICarDal.cs 97 | + IBrandDal.cs 98 | + IColorDal.cs 99 | + IEntityRepository.cs :x: :point_right: Bu class'ım bu klasördeki var olan diğer class'larımın kullanacağı Generic yapısını oluşturur. 100 | 101 | 102 | + [ Concrete :open_file_folder: : (Somut sınıflarımı içerir.)](https://github.com/kadernur/ReCapProject/tree/master/DataAccess/Concrete) 103 | 104 | + EntityFrameWork:open_file_folder: :point_right: Bu klasör çalışmak istediğim veri tabanına bağlantı kurduğum ve istediğim verileri çekmemi sağlayan yapıları içeren bir klasördür. yani veri tabanı ile kendi class'larımı ilişkilendiğim classtır. 105 | + EfCarDal.cs 106 | + EfBrandDal.cs 107 | + EfColorDal.cs 108 | + ReCapDatabeseContext.cs :point_right: Bu class'ım veri tabanına bağlanmamı sağlayan kodları içerir ve bu klasördeki diğer class'larımın veri tabanına erişimin sağlar. 109 | 110 | + InMemoryDal :point_right: bu klasör veri tabanı kullanmadan bellekte olan verileri kullandığım klasördür. 111 | + InMemoryCarDal.cs 112 | 113 | ### ENTİTİES 114 | Bu katman yardımcı katmanımdır. 115 | + [Abstract :open_file_folder: :(İlgili soyut Sınıflarımı içerir.](https://github.com/kadernur/ReCapProject/tree/master/Entities/Abstract) 116 | + IEntity.cs :x: 117 | 118 | + [ Concrete:open_file_folder: : (Somut sınıflarımı içerir.)](https://github.com/kadernur/ReCapProject/tree/master/Entities/Concrete) 119 | :point_right: Bu klasör ise nesnelerimi ve nesnelere ait özelliklerimin tutulduğu klasördür. 120 | 121 | + Car.cs 122 | + Brand.cs 123 | + Color.cs 124 | 125 | + [DTOs :purple_circle::open_file_folder: (Veri tabanını ilişkisel tablolarını içerir. Join işlemleri burda yapılır.)](https://github.com/kadernur/ReCapProject/tree/master/Entities/DTOs) 126 | + :purple_circle: CarDetailDto.cs 127 | 128 | 129 | 130 | 131 | ### :large_blue_circle: WebAPI 132 | [Sadece veri transferi için kullanılır.RestFull mimarisini destekleyen katmandır. bu katmandaki Controller gelen bütün istekleri karşılar.(RESFUL: Http protokolü:Bir kaynağa ulaşmak için izlediğimiz yol diyebiliriz.)](https://github.com/kadernur/ReCapProject/tree/master/WebAPI) 133 | 134 | ### [SQL TABLO İÇERİKLERİ](https://github.com/kadernur/ReCapProject/blob/master/SQLQuery2Recap.sql) 135 | 136 | #### CAR TABLOSU 137 | 138 | |CarId | BrandId | ColorId | ModelYear | DailyPrice | Description | 139 | |------ |--------|---------|-----------|------------|------------------| 140 | |1|1|2|2012|100|ManuelBenzin| 141 | |2|1|3|2015|150|Otomotik Dizel| 142 | |3|2|1|2017|200|Otomotik Hybrid| 143 | |4|3|3|2014|125|Manuel Dizel| 144 | |NULL|NULL|NULL|NULL|NULL|NULL| 145 | 146 | 147 | #### BRAND TABLOSU 148 | |BranId|BrandName| 149 | |-------|---------| 150 | |1|Tesla| 151 | |2|BMw| 152 | |3|Renault| 153 | |NULL|NULL| 154 | 155 | 156 | #### COLOR TABLOSU 157 | 158 | |ColorId|ColorName| 159 | |-------|---------| 160 | |1|Beyaz| 161 | |2|Siyah| 162 | |3|Mavi| 163 | |4|Gri| 164 | |5||Turuncu| 165 | |NULL|NULL| 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFrameWork/EfCarDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using Entities.DTOs; 5 | using Microsoft.EntityFrameworkCore; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Linq.Expressions; 10 | using System.Text; 11 | 12 | namespace DataAccess.Concrete.EntityFrameWork 13 | { 14 | public class EfCarDal : EfEntityRepositoryBase, ICarDal 15 | { 16 | public List GetAllCarDetailsByFilter(CarDetailFilterDto filter) 17 | { 18 | throw new NotImplementedException(); 19 | } 20 | 21 | public List GetCarDetails(Expression> filter = null) 22 | { 23 | using (ReCapDatabaseContext context = new ReCapDatabaseContext()) 24 | { 25 | var result = from car in context.Cars 26 | join color in context.Colors on car.ColorId equals color.ColorId 27 | join brand in context.Brands on car.BrandId equals brand.BrandId 28 | // join carImage in context.CarImages on car.CarId equals carImage.CarId 29 | select new CarDetailDto() { 30 | CarId = car.CarId, 31 | Images = 32 | (from i in context.CarImages where i.CarId == car.CarId select i.ImagePath).ToList(), 33 | Description = car.Descriptions, 34 | BrandId = brand.BrandId, 35 | BrandName = brand.BrandName, 36 | ColorId = color.ColorId, 37 | ColorName = color.ColorName, 38 | DailyPrice = car.DailyPrice, 39 | 40 | 41 | }; 42 | return filter == null ? result.ToList() : result.Where(filter).ToList(); 43 | } 44 | } 45 | 46 | 47 | 48 | public List GetCarDetailsByColorId(int colorId) 49 | { 50 | using (RentACarContext context = new RentACarContext()) 51 | { 52 | var result = from c in context.Cars 53 | join b in context.Brands 54 | on c.BrandId equals b.BrandId 55 | join cl in context.Colors 56 | on c.ColorId equals cl.ColorId 57 | where c.ColorId == colorId 58 | select new CarDetailDto { 59 | CarId = c.CarId, 60 | BrandName = b.BrandName, 61 | ModelYear = c.ModelYear, 62 | ColorName = cl.ColorName, 63 | DailyPrice = c.DailyPrice, 64 | Descriptions = c.Descriptions, 65 | ImagePath = (from a in context.CarImages where a.CarId == c.CarId select a.ImagePath).FirstOrDefault() 66 | 67 | }; 68 | 69 | return result.ToList(); 70 | } 71 | } 72 | 73 | public List GetCarDetailsByBrandId(int brandId) 74 | { 75 | using (RentACarContext context = new RentACarContext()) 76 | { 77 | var result = from c in context.Cars 78 | join b in context.Brands 79 | on c.BrandId equals b.BrandId 80 | join cl in context.Colors 81 | on c.ColorId equals cl.ColorId 82 | where c.BrandId == brandId 83 | select new CarDetailDto { 84 | CarId = c.CarId, 85 | BrandName = b.BrandName, 86 | ModelYear = c.ModelYear, 87 | ColorName = cl.ColorName, 88 | DailyPrice = c.DailyPrice, 89 | Descriptions = c.Descriptions, 90 | ImagePath = (from a in context.CarImages where a.CarId == c.CarId select a.ImagePath).FirstOrDefault() 91 | 92 | }; 93 | 94 | return result.ToList(); 95 | } 96 | } 97 | 98 | public List GetCarDetailsByBrandAndColor(int brandId, int colorId) 99 | { 100 | using (RentACarContext context = new RentACarContext()) 101 | { 102 | var result = from c in context.Cars 103 | join b in context.Brands 104 | on c.BrandId equals b.BrandId 105 | join cl in context.Colors 106 | on c.ColorId equals cl.ColorId 107 | where c.BrandId == brandId 108 | where c.ColorId == colorId 109 | select new CarDetailDto { 110 | CarId = c.CarId, 111 | BrandName = b.BrandName, 112 | ModelYear = c.ModelYear, 113 | ColorName = cl.ColorName, 114 | DailyPrice = c.DailyPrice, 115 | Descriptions = c.Descriptions, 116 | ImagePath = (from a in context.CarImages where a.CarId == c.CarId select a.ImagePath).FirstOrDefault() 117 | 118 | }; 119 | 120 | return result.ToList(); 121 | } 122 | } 123 | 124 | public List GetCarDetailsById(int carId) 125 | { 126 | using (RentACarContext context = new RentACarContext()) 127 | { 128 | var result = from c in context.Cars 129 | join b in context.Brands 130 | on c.BrandId equals b.BrandId 131 | join cl in context.Colors 132 | on c.ColorId equals cl.ColorId 133 | where c.CarId == carId 134 | select new CarDetailDto { 135 | CarId = c.CarId, 136 | BrandName = b.BrandName, 137 | ModelYear = c.ModelYear, 138 | ColorName = cl.ColorName, 139 | DailyPrice = c.DailyPrice, 140 | Descriptions = c.Descriptions, 141 | ImagePath = (from a in context.CarImages where a.CarId == c.CarId select a.ImagePath).FirstOrDefault() 142 | }; 143 | 144 | return result.ToList(); 145 | } 146 | } 147 | //public List GetAllCarDetailsByFilter(CarDetailFilterDto filterDto) 148 | //{ 149 | // using (ReCapDatabaseContext context = new ReCapDatabaseContext()) 150 | // { 151 | // var filterExpression =GetAllCarDetailsByFilter (filterDto); 152 | // var result = from car in filterExpression == null ? context.Cars : context.Cars.Where(filterExpression) 153 | // join color in context.Colors on car.ColorId equals color.ColorId 154 | // join brand in context.Brands on car.BrandId equals brand.BrandId 155 | // join carImage in context.CarImages on car.CarId equals carImage.CarId 156 | // select new CarDetailDto { 157 | // CarId = car.CarId, 158 | // BrandId = brand.BrandId, 159 | // ColorId = color.ColorId, 160 | // Images = 161 | // (from i in context.CarImages where i.CarId == car.CarId select i.ImagePath).ToList(), 162 | // ModelYear = car.ModelYear, 163 | // BrandName = brand.BrandName, 164 | // Description = car.Description, 165 | // ColorName = color.ColorName, 166 | // DailyPrice = car.DailyPrice 167 | // }; 168 | // return result.ToList(); // tolist yapmadan query'e dönüştürüp verileri çekmez. 169 | 170 | // } 171 | //} 172 | } 173 | } 174 | 175 | //CarName, BrandName, ColorName, DailyPrice 176 | /* 177 | *select CarName, BrandName, ColorName, DailyPrice from Cars 178 | inner join Brands on Cars.BrandId = Brands.BrandId 179 | inner join Colors on cars.ColorId = Colors.ColorId 180 | * 181 | * 182 | *using (NorthwindContext context = new NorthwindContext()) 183 | { 184 | var result = from p in context.Products 185 | join c in context.Categories 186 | on p.CategoryId equals c.CategoryId 187 | select new ProductDetailDTO 188 | {ProductId = p.ProductId, ProductName = p.ProductName, CategoryName = c.CategoryName, UnitsInStock = p.UnitsInStock}; 189 | return result.ToList(); 190 | } 191 | * 192 | */ --------------------------------------------------------------------------------