├── WebAPI ├── images │ ├── default.png │ └── 13c4abe4-17d2-434b-9e63-eea42dd8ac50.jpg ├── wwwroot │ └── Images │ │ ├── default.png │ │ └── 13c4abe4-17d2-434b-9e63-eea42dd8ac50.jpg ├── appsettings.Development.json ├── appsettings.json ├── Properties │ └── launchSettings.json ├── WebAPI.csproj ├── Program.cs ├── Controllers │ ├── AuthController.cs │ ├── BrandsController.cs │ ├── ColorsController.cs │ ├── CustomersController.cs │ ├── UsersController.cs │ ├── RentalsController.cs │ ├── CarsController.cs │ └── CarImagesController.cs └── Startup.cs ├── Core ├── Entities │ ├── IDto.cs │ ├── IEntity.cs │ └── Concrete │ │ ├── OperationClaim.cs │ │ ├── UserOperationClaim.cs │ │ └── User.cs ├── Utilities │ ├── Results │ │ ├── IDataResult.cs │ │ ├── IResult.cs │ │ ├── ErrorResult.cs │ │ ├── SuccessResult.cs │ │ ├── DataResult.cs │ │ ├── Result.cs │ │ ├── ErrorDataResult.cs │ │ └── SuccessDataResult.cs │ ├── Security │ │ ├── JWT │ │ │ ├── AccessToken.cs │ │ │ ├── ITokenHelper.cs │ │ │ ├── TokenOptions.cs │ │ │ └── JwtHelper.cs │ │ ├── Encryption │ │ │ ├── SecurityKeyHelper.cs │ │ │ └── SigningCredentialsHelper.cs │ │ └── Hashing │ │ │ └── HashingHelper.cs │ ├── Business │ │ └── BusinessRules.cs │ ├── Interceptors │ │ ├── MethodInterceptionBaseAttribute.cs │ │ ├── AspectInterceptorSelector.cs │ │ └── MethodInterception.cs │ ├── Extensions │ │ ├── ClaimsPrincipalExtensions.cs │ │ └── ClaimExtensions.cs │ └── FileHelper │ │ └── FileHelper.cs ├── Extensions │ ├── ExceptionMiddlewareExtensions.cs │ ├── ErrorDetails.cs │ ├── ClaimPrincipalExtensions.cs │ ├── ClaimExtensions.cs │ └── ExceptionMiddleware.cs ├── DataAccess │ ├── IEntityRepository.cs │ └── EntityFramework │ │ └── EfEntityRepositoryBase.cs ├── IoC │ └── ServiceTool.cs ├── CrossCuttingConcerns │ └── Validation │ │ └── ValidationTool.cs ├── Core.csproj └── Aspects │ └── Autofac │ └── Validation │ └── ValidationAspect.cs ├── DataAccess ├── Abstract │ ├── IBrandDal.cs │ ├── IColorDal.cs │ ├── ICarImageDal.cs │ ├── ICustomerDal.cs │ ├── IUserDal.cs │ ├── IRentalDal.cs │ └── ICarDal.cs ├── Concrete │ └── EntityFramework │ │ ├── EfBrandDal.cs │ │ ├── EfColorDal.cs │ │ ├── EfCarImageDal.cs │ │ ├── CarContext.cs │ │ ├── EfUserDal.cs │ │ ├── EfCustomerDal.cs │ │ ├── EfRentalDal.cs │ │ └── EfCarDal.cs └── DataAccess.csproj ├── Entities ├── DTOs │ ├── UserForLoginDto.cs │ ├── CustomerDetailDto.cs │ ├── UserForRegisterDto.cs │ ├── RentalDetailsDto.cs │ └── CarDetailDto.cs ├── Concrete │ ├── Brand.cs │ ├── Color.cs │ ├── Customer.cs │ ├── CarImage.cs │ ├── Rental.cs │ └── Car.cs └── Entities.csproj ├── Business ├── ValidationRules │ └── FluentValidation │ │ ├── BrandValidator.cs │ │ ├── CustomerValidator.cs │ │ ├── ColorValidator.cs │ │ ├── UserValidator.cs │ │ ├── RentalValidator.cs │ │ └── CarValidator.cs ├── Abstract │ ├── IBrandService.cs │ ├── IColorService.cs │ ├── ICarImageService.cs │ ├── IUserService.cs │ ├── ICustomerService.cs │ ├── IAuthService.cs │ ├── IRentalService.cs │ └── ICarService.cs ├── Business.csproj ├── Constants │ └── Messages.cs ├── BusinessAspects │ └── Autofac │ │ └── SecuredOperation.cs ├── Concrete │ ├── ColorManager.cs │ ├── BrandManager.cs │ ├── UserManager.cs │ ├── CustomerManager.cs │ ├── CarImageManager.cs │ ├── RentalManager.cs │ ├── AuthManager.cs │ └── CarManager.cs └── DependencyResolvers │ └── Autofac │ └── AutofacBusinessModule.cs ├── .gitattributes ├── ReCapProject.sln └── .gitignore /WebAPI/images/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hakanciritt/ReCapProject/HEAD/WebAPI/images/default.png -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hakanciritt/ReCapProject/HEAD/WebAPI/wwwroot/Images/default.png -------------------------------------------------------------------------------- /WebAPI/images/13c4abe4-17d2-434b-9e63-eea42dd8ac50.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hakanciritt/ReCapProject/HEAD/WebAPI/images/13c4abe4-17d2-434b-9e63-eea42dd8ac50.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/Images/13c4abe4-17d2-434b-9e63-eea42dd8ac50.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hakanciritt/ReCapProject/HEAD/WebAPI/wwwroot/Images/13c4abe4-17d2-434b-9e63-eea42dd8ac50.jpg -------------------------------------------------------------------------------- /Core/Entities/IDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities 6 | { 7 | public interface IDto 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Core/Entities/IEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities 6 | { 7 | public interface IEntity 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /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/Utilities/Results/IDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public interface IDataResult : IResult 8 | { 9 | 10 | T Data { get; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Utilities/Results/IResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public interface IResult 8 | { 9 | bool Success { get; } 10 | string Message { get; } 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IBrandDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface IBrandDal : IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IColorDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface IColorDal : IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICarImageDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface ICarImageDal : IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Entities/DTOs/UserForLoginDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Entities.DTOs 6 | { 7 | public class UserForLoginDto 8 | { 9 | public string Email { get; set; } 10 | public string Password { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /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/Concrete/Brand.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Brand : IEntity 9 | { 10 | public int Id { get; set; } 11 | public string Name { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Entities/Concrete/Color.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Color : IEntity 9 | { 10 | public int Id { get; set; } 11 | public string Name { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/AccessToken.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Security.JWT 6 | { 7 | public class AccessToken 8 | { 9 | public string Token { get; set; } 10 | public DateTime Expiration { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/ITokenHelper.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Security.JWT 7 | { 8 | public interface ITokenHelper 9 | { 10 | AccessToken CreateToken(User user, List operationClaims); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Entities/DTOs/CustomerDetailDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Entities.DTOs 6 | { 7 | public class CustomerDetailDto 8 | { 9 | public int Id { get; set; } 10 | public string FullName { get; set; } 11 | public string CompanyName { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /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 8 | { 9 | public int Id { get; set; } 10 | public int UserId { get; set; } 11 | public int OperationClaimId { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Entities/Concrete/Customer.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Customer : IEntity 9 | { 10 | public int Id { get; set; } 11 | public int UserId { get; set; } 12 | public string CompanyName { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICustomerDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Abstract 9 | { 10 | public interface ICustomerDal : IEntityRepository 11 | { 12 | List CustomerDetail(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IUserDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Core.Entities.Concrete; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Abstract 9 | { 10 | public interface IUserDal:IEntityRepository 11 | { 12 | List GetClaims(User user); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/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.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFramework 9 | { 10 | public class EfBrandDal : EfEntityRepositoryBase, IBrandDal 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /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.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFramework 9 | { 10 | public class EfColorDal : EfEntityRepositoryBase , IColorDal 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/Utilities/Results/ErrorResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class ErrorResult: Result 8 | { 9 | public ErrorResult():base(false) 10 | { 11 | 12 | } 13 | public ErrorResult(string message):base(false,message) 14 | { 15 | 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IRentalDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Core.Utilities.Results; 3 | using Entities.Concrete; 4 | using Entities.DTOs; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace DataAccess.Abstract 10 | { 11 | public interface IRentalDal : IEntityRepository 12 | { 13 | List RentalDetail(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Entities/DTOs/UserForRegisterDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Entities.DTOs 6 | { 7 | public class UserForRegisterDto 8 | { 9 | public string Email { get; set; } 10 | public string Password { get; set; } 11 | public string FirstName { get; set; } 12 | public string LastName { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Core/Utilities/Results/SuccessResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class SuccessResult : Result 8 | { 9 | public SuccessResult():base(true) 10 | { 11 | 12 | } 13 | public SuccessResult(string message):base(true,message) 14 | { 15 | 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Entities/Concrete/CarImage.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class CarImage : IEntity 9 | { 10 | public int Id { get; set; } 11 | public int CarId { get; set; } 12 | public string ImagePath { get; set; } 13 | public DateTime Date { get; set; } 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/TokenOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Security.JWT 6 | { 7 | public class TokenOptions 8 | { 9 | public string Audience { get; set; } 10 | public string Issuer { get; set; } 11 | public int AccessTokenExpiration { get; set; } 12 | public string SecurityKey { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/DataAccess.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /WebAPI/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "TokenOptions": { 3 | "Audience": "hakan@hakan.com", 4 | "Issuer": "hakan@hakan.com", 5 | "AccessTokenExpiration": 10, 6 | "SecurityKey": "mysupersecretkeymysupersecretkey" 7 | }, 8 | "Logging": { 9 | "LogLevel": { 10 | "Default": "Information", 11 | "Microsoft": "Warning", 12 | "Microsoft.Hosting.Lifetime": "Information" 13 | } 14 | }, 15 | "AllowedHosts": "*" 16 | } 17 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/BrandValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Entities.Concrete; 5 | using FluentValidation; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class BrandValidator : AbstractValidator 10 | { 11 | public BrandValidator() 12 | { 13 | RuleFor(x => x.Name).MinimumLength(2); 14 | 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Entities/Concrete/Rental.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Rental : IEntity 9 | { 10 | public int Id { get; set; } 11 | public int CarId { get; set; } 12 | public int CustomerId { get; set; } 13 | public DateTime RentDate { get; set; } 14 | public DateTime ReturnDate { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Core/Extensions/ExceptionMiddlewareExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Extensions 7 | { 8 | public static class ExceptionMiddlewareExtensions 9 | { 10 | public static void ConfigureCustomExceptionMiddleware(this IApplicationBuilder app) 11 | { 12 | app.UseMiddleware(); 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Business/Abstract/IBrandService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface IBrandService 10 | { 11 | IResult Add(Brand brand); 12 | IResult Update(Brand brand); 13 | IResult Delete(Brand brand); 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int brandId); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Business/Abstract/IColorService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface IColorService 10 | { 11 | IResult Add(Color color); 12 | IResult Delete(Color color); 13 | IResult Update(Color color); 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int colorId); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Entities/Entities.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/CustomerValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Entities.Concrete; 5 | using FluentValidation; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class CustomerValidator : AbstractValidator 10 | { 11 | public CustomerValidator() 12 | { 13 | RuleFor(x => x.UserId).NotEmpty(); 14 | RuleFor(x => x.UserId).GreaterThan(0); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Encryption/SigningCredentialsHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IdentityModel.Tokens; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Security.Encryption 7 | { 8 | public class SigningCredentialsHelper 9 | { 10 | public static SigningCredentials CreateSigningCredentials(SecurityKey securityKey) 11 | { 12 | return new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256Signature); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Core/DataAccess/IEntityRepository.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq.Expressions; 5 | using System.Text; 6 | 7 | namespace Core.DataAccess 8 | { 9 | public interface IEntityRepository where T : class, IEntity, new() 10 | { 11 | void Add(T entity); 12 | void Update(T entity); 13 | void Delete(T entity); 14 | List GetAll(Expression> filter = null); 15 | T Get(Expression> filter); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Core/IoC/ServiceTool.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.IoC 7 | { 8 | public class ServiceTool 9 | { 10 | public static IServiceProvider ServiceProvider { get; private set; } 11 | 12 | public static IServiceCollection Create(IServiceCollection services) 13 | { 14 | ServiceProvider = services.BuildServiceProvider(); 15 | return services; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities.Concrete 6 | { 7 | public class User : IEntity 8 | { 9 | public int Id { get; set; } 10 | public string FirstName { get; set; } 11 | public string LastName { get; set; } 12 | public string Email { get; set; } 13 | public byte[] PasswordHash { get; set; } 14 | public byte[] PasswordSalt { get; set; } 15 | public bool Status { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Core/Utilities/Results/DataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class DataResult : Result, IDataResult 8 | { 9 | public DataResult(T data, bool success, string message) : base(success, message) 10 | { 11 | Data = data; 12 | } 13 | public DataResult(T data, bool success) : base(success) 14 | { 15 | Data = data; 16 | } 17 | public T Data { get; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Entities/DTOs/RentalDetailsDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Entities.DTOs 6 | { 7 | public class RentalDetailDto 8 | { 9 | //CarId yerine BrandName, CustomerId yerine FirstName + LastName şeklinde gösteriniz 10 | public string BrandName { get; set; } 11 | public string CompanyName { get; set; } 12 | public string CustomerName { get; set; } 13 | public DateTime RentDate { get; set; } 14 | public DateTime ReturnDate { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Business/Abstract/ICarImageService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface ICarImageService 10 | { 11 | IResult Add(CarImage carImage); 12 | IResult Update(CarImage carImage); 13 | IResult Delete(CarImage carImage); 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int id); 16 | IDataResult> GetByCarId(int id); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Business/Abstract/IUserService.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Core.Utilities.Results; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace Business.Abstract 9 | { 10 | public interface IUserService 11 | { 12 | IResult Add(User user); 13 | IResult Update(User user); 14 | IResult Delete(User user); 15 | IDataResult> GetAll(); 16 | User GetByMail(string email); 17 | IDataResult> GetClaims(User user); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Core/Utilities/Business/BusinessRules.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Business 7 | { 8 | public class BusinessRules 9 | { 10 | public static IResult Run(params IResult[] logics) 11 | { 12 | foreach (var logic in logics) 13 | { 14 | if (!logic.Success) 15 | { 16 | return logic; 17 | } 18 | } 19 | return null; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Utilities/Results/Result.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class Result : IResult 8 | { 9 | public Result(bool success) 10 | { 11 | Success = success; 12 | } 13 | public Result(bool success, string message) : this(success) 14 | { 15 | Success = success; 16 | Message = message; 17 | 18 | } 19 | public bool Success { get; } 20 | 21 | public string Message { get; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/MethodInterceptionBaseAttribute.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Interceptors 7 | { 8 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] 9 | public abstract class MethodInterceptionBaseAttribute : Attribute, IInterceptor 10 | { 11 | public int Priority { get; set; } 12 | 13 | public virtual void Intercept(IInvocation invocation) 14 | { 15 | 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/ColorValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Entities.Concrete; 5 | using FluentValidation; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class ColorValidator : AbstractValidator 10 | { 11 | public ColorValidator() 12 | { 13 | RuleFor(x => x.Name).MinimumLength(3).WithMessage("Minimum 3 karakter uzunluğunda olmalıdır"); 14 | RuleFor(x => x.Name).NotEmpty().WithMessage("Renk alanı boş geçilemez"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/UserValidator.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Entities.Concrete; 3 | using FluentValidation; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace Business.ValidationRules.FluentValidation 9 | { 10 | public class UserValidator : AbstractValidator 11 | { 12 | public UserValidator() 13 | { 14 | RuleFor(x => x.FirstName).MinimumLength(4); 15 | RuleFor(x => x.FirstName).NotEmpty(); 16 | RuleFor(x => x.LastName).NotEmpty(); 17 | 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Business/Abstract/ICustomerService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace Business.Abstract 9 | { 10 | public interface ICustomerService 11 | { 12 | IResult Add(Customer customer); 13 | IResult Delete(Customer customer); 14 | IResult Update(Customer customer); 15 | IDataResult> GetAll(); 16 | IDataResult GetById(int customerId); 17 | IDataResult> GetDetails(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Business/Abstract/IAuthService.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Core.Utilities.Results; 3 | using Core.Utilities.Security.JWT; 4 | using Entities.DTOs; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace Business.Abstract 10 | { 11 | public interface IAuthService 12 | { 13 | IDataResult Register(UserForRegisterDto userForRegisterDto, string password); 14 | IDataResult Login(UserForLoginDto userForLoginDto); 15 | IResult UserExists(string email); 16 | IDataResult CreateAccessToken(User user); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICarDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using DataAccess.Concrete.EntityFramework; 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 | List CarDetails(); 15 | List GetCarDetails(Expression> filter = null); 16 | CarDetailDto GetCarDetail(Expression> filter); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Entities/Concrete/Car.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Car : IEntity 9 | { 10 | //Id, BrandId, ColorId, ModelYear, DailyPrice, Description 11 | public int Id { get; set; } 12 | public string CarName { get; set; } 13 | public int BrandId { get; set; } 14 | public int ColorId { get; set; } 15 | public DateTime ModelYear { get; set; } 16 | public decimal DailyPrice { get; set; } 17 | public string Description { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Business/Abstract/IRentalService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace Business.Abstract 9 | { 10 | public interface IRentalService 11 | { 12 | IResult Add(Rental rental); 13 | IResult Delete(Rental rental); 14 | IResult Update(Rental rental); 15 | IDataResult> GetAll(); 16 | IDataResult GetById(int rentalId); 17 | IDataResult> RentalDetail(); 18 | IResult CheckIfCarRent(Rental rental); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Validation/ValidationTool.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.CrossCuttingConcerns.Validation 7 | { 8 | public static class ValidationTool 9 | { 10 | public static void Validate(IValidator validator, object entity) 11 | { 12 | var context = new ValidationContext(entity); 13 | var result = validator.Validate(context); 14 | if (!result.IsValid) 15 | { 16 | throw new ValidationException(result.Errors); 17 | } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Core/Extensions/ErrorDetails.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation.Results; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Core.Extensions 8 | { 9 | public class ErrorDetails 10 | { 11 | public string Message { get; set; } 12 | public int StatusCode { get; set; } 13 | 14 | public override string ToString() 15 | { 16 | return JsonConvert.SerializeObject(this); 17 | } 18 | 19 | } 20 | public class ValidationErrorDetails : ErrorDetails 21 | { 22 | public IEnumerable Errors { get; set; } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/RentalValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Entities.Concrete; 5 | using FluentValidation; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class RentalValidator :AbstractValidator 10 | { 11 | public RentalValidator() 12 | { 13 | RuleFor(x => x.RentDate).NotEmpty().WithMessage("Kiralama tarihi boş geçilemez"); 14 | RuleFor(x => x.ReturnDate).NotEmpty().WithMessage("İade tarihi boş geçilemez"); 15 | RuleFor(x => x.CarId).GreaterThan(0).NotEmpty(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Core/Utilities/Results/ErrorDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class ErrorDataResult : DataResult 8 | { 9 | public ErrorDataResult(T data, string message) : base(data, false, message) 10 | { 11 | 12 | } 13 | public ErrorDataResult(T data) : base(data, false) 14 | { 15 | 16 | } 17 | public ErrorDataResult(string message) : base(default, false, message) 18 | { 19 | 20 | } 21 | public ErrorDataResult() : base(default, false) 22 | { 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Core/Utilities/Results/SuccessDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class SuccessDataResult : DataResult 8 | { 9 | public SuccessDataResult(T data) : base(data, true) 10 | { 11 | 12 | } 13 | public SuccessDataResult(T data, string message) : base(data, true, message) 14 | { 15 | 16 | } 17 | public SuccessDataResult(string message) : base(default, true, message) 18 | { 19 | 20 | } 21 | public SuccessDataResult() : base(default, true) 22 | { 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Entities/DTOs/CarDetailDto.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class CarDetailDto : IDto 9 | { 10 | public int Id { get; set; } 11 | public string CarName { get; set; } 12 | public string BrandName { get; set; } 13 | public string ColorName { get; set; } 14 | public decimal DailyPrice { get; set; } 15 | public DateTime ModelYear { get; set; } 16 | public string Description { get; set; } 17 | public string ImagePath { get; set; } 18 | public int BrandId { get; set; } 19 | public int ColorId { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Core/Extensions/ClaimPrincipalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Claims; 5 | using System.Text; 6 | 7 | namespace Core.Extensions 8 | { 9 | public static class ClaimsPrincipalExtensions 10 | { 11 | public static List Claims(this ClaimsPrincipal claimsPrincipal, string claimType) 12 | { 13 | var result = claimsPrincipal?.FindAll(claimType)?.Select(x => x.Value).ToList(); 14 | return result; 15 | } 16 | 17 | public static List ClaimRoles(this ClaimsPrincipal claimsPrincipal) 18 | { 19 | return claimsPrincipal?.Claims(ClaimTypes.Role); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Utilities/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.Utilities.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 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/CarValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | 4 | namespace Business.ValidationRules.FluentValidation 5 | { 6 | public class CarValidator : AbstractValidator 7 | { 8 | public CarValidator() 9 | { 10 | RuleFor(x => x.DailyPrice).GreaterThan(0); 11 | RuleFor(x => x.BrandId).NotEmpty().WithMessage("Marka alanı boş geçilemez"); 12 | RuleFor(x => x.ColorId).NotEmpty().WithMessage("Renk alanı boş geçilemez"); 13 | RuleFor(x => x.ModelYear).NotEmpty().WithMessage("Model yılı boş geçilemez"); 14 | RuleFor(x => x.Description).MinimumLength(20).WithMessage("En az 20 karakter uzunluğunda olmalıdır"); 15 | RuleFor(x => x.Description).NotEmpty().WithMessage("Açıklama alanı boş geçilemez"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Core/Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /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 | 22 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/AspectInterceptorSelector.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | 8 | namespace Core.Utilities.Interceptors 9 | { 10 | public class AspectInterceptorSelector : IInterceptorSelector 11 | { 12 | public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) 13 | { 14 | var classAttributes = type.GetCustomAttributes 15 | (true).ToList(); 16 | var methodAttributes = type.GetMethod(method.Name) 17 | .GetCustomAttributes(true); 18 | classAttributes.AddRange(methodAttributes); 19 | 20 | return classAttributes.OrderBy(x => x.Priority).ToArray(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /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:53964", 8 | "sslPort": 44312 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 | -------------------------------------------------------------------------------- /Business/Abstract/ICarService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace Business.Abstract 9 | { 10 | public interface ICarService 11 | { 12 | IDataResult> GetCarsByBrandId(int brandId); 13 | IDataResult> GetCarsByColorId(int colorId); 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int carId); 16 | IResult Add(Car car); 17 | IResult Update(Car car); 18 | IResult Delete(Car car); 19 | IDataResult> GetCarDetails(); 20 | IDataResult GetByIdCarDetails(int id); 21 | IDataResult> GetCarDetailsBrandName(string brandName); 22 | IDataResult> GetCarDetailsColorName(string colorName); 23 | IDataResult> GetByColorAndBrand(int brandId, int colorId); 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/CarContext.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 CarContext : DbContext 11 | { 12 | public DbSet Cars { get; set; } 13 | public DbSet Colors { get; set; } 14 | public DbSet Brands { get; set; } 15 | public DbSet Customers { get; set; } 16 | public DbSet Rentals { get; set; } 17 | public DbSet CarImages { get; set; } 18 | public DbSet OperationClaims { get; set; } 19 | public DbSet Users { get; set; } 20 | public DbSet UserOperationClaims { get; set; } 21 | 22 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 23 | { 24 | optionsBuilder.UseSqlServer(@"server=DESKTOP-MCV13KF\SQLEXPRESS;database=Car;Trusted_connection=true;"); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfUserDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using Core.Entities.Concrete; 3 | using DataAccess.Abstract; 4 | using Entities.Concrete; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | using System.Linq; 9 | 10 | namespace DataAccess.Concrete.EntityFramework 11 | { 12 | public class EfUserDal : EfEntityRepositoryBase, IUserDal 13 | { 14 | public List GetClaims(User user) 15 | { 16 | using (var context = new CarContext()) 17 | { 18 | var result = from operationClaim in context.OperationClaims 19 | join userOperationClaim in context.UserOperationClaims 20 | on operationClaim.Id equals userOperationClaim.OperationClaimId 21 | where userOperationClaim.UserId == user.Id 22 | select new OperationClaim { Id = operationClaim.Id, Name = operationClaim.Name }; 23 | return result.ToList(); 24 | 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /WebAPI/WebAPI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | true 15 | PreserveNewest 16 | 17 | 18 | true 19 | PreserveNewest 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Core/Utilities/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.Utilities.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 | -------------------------------------------------------------------------------- /WebAPI/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.Hosting; 4 | using Microsoft.Extensions.Logging; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | using Autofac.Extensions.DependencyInjection; 10 | using Autofac; 11 | using Business.DependencyResolvers.Autofac; 12 | 13 | namespace WebAPI 14 | { 15 | public class Program 16 | { 17 | public static void Main(string[] args) 18 | { 19 | CreateHostBuilder(args).Build().Run(); 20 | } 21 | 22 | public static IHostBuilder CreateHostBuilder(string[] args) => 23 | Host.CreateDefaultBuilder(args) 24 | .UseServiceProviderFactory(new AutofacServiceProviderFactory()) 25 | .ConfigureContainer(x => 26 | { 27 | x.RegisterModule(new AutofacBusinessModule()); 28 | }) 29 | .ConfigureWebHostDefaults(webBuilder => 30 | { 31 | webBuilder.UseStartup(); 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Hashing/HashingHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Security.Cryptography; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Security.Hashing 7 | { 8 | public class HashingHelper 9 | { 10 | public static void CreatePasswordHash(string password, out byte[] passwordHash, out byte[] passwordSalt) 11 | { 12 | using (var hmac = new HMACSHA512()) 13 | { 14 | passwordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(password)); 15 | passwordSalt = hmac.Key; 16 | } 17 | } 18 | public static bool VerifyPasswordHash(string password, byte[] passwordHash, byte[] passwordSalt) 19 | { 20 | using (var hmac = new HMACSHA512(passwordSalt)) 21 | { 22 | var computedHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(password)); 23 | for (int i = 0; i < computedHash.Length; i++) 24 | { 25 | if (computedHash[i] != passwordHash[i]) 26 | { 27 | return false; 28 | } 29 | } 30 | return true; 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCustomerDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using Core.Entities.Concrete; 3 | using DataAccess.Abstract; 4 | using Entities.Concrete; 5 | using Entities.DTOs; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Text; 10 | 11 | namespace DataAccess.Concrete.EntityFramework 12 | { 13 | public class EfCustomerDal : EfEntityRepositoryBase, ICustomerDal 14 | { 15 | public List CustomerDetail() 16 | { 17 | using (CarContext context=new CarContext()) 18 | { 19 | var result = from customer in context.Customers 20 | join user in context.Users.Cast() 21 | on customer.UserId equals user.Id 22 | select new CustomerDetailDto 23 | { 24 | Id = customer.Id, 25 | FullName = user.FirstName + " " + user.LastName, 26 | CompanyName = customer.CompanyName 27 | }; 28 | return result.ToList(); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /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 const string BrandAdded = "Marka Eklendi"; 12 | public const string CarUpdated = "Araba başarıyla güncellendi"; 13 | public const string Added = "Marka Eklendi"; 14 | public const string Deleted = "Silindi"; 15 | public const string Updated = "Güncellendi"; 16 | public const string ImageInsertionLimitExceeded = "Resim yükleme sınırı aşıldı"; 17 | public const string UserRegistered = "Başarıyla kaydolundu"; 18 | public const string UserNotFound = "Kullanıcı bulunamadı"; 19 | public const string PasswordError = "Şifre eşleşmiyor"; 20 | public const string SuccessfulLogin = "Başarıyla giriş yapıldı"; 21 | public const string UserAlreadyExists = "Kullanıcı zaten mevcut"; 22 | public const string AccessTokenCreated = "Token oluşturuldu"; 23 | public const string AuthorizationDenied = "Yetkisiz deneme"; 24 | public const string RentStatus = "Araç belirtilen tarih aralığında başkası tarafından kiralanmış"; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Business/BusinessAspects/Autofac/SecuredOperation.cs: -------------------------------------------------------------------------------- 1 | using Core.IoC; 2 | using Core.Utilities.Interceptors; 3 | using Microsoft.AspNetCore.Http; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using Castle.DynamicProxy; 9 | using Business.Constants; 10 | using Core.Extensions; 11 | 12 | namespace Business.BusinessAspects.Autofac 13 | { 14 | public class SecuredOperation : MethodInterception 15 | { 16 | private string[] _roles; 17 | private IHttpContextAccessor _httpContextAccessor; 18 | 19 | public SecuredOperation(string roles) 20 | { 21 | _roles = roles.Split(','); 22 | _httpContextAccessor = ServiceTool.ServiceProvider.GetService(); 23 | 24 | } 25 | 26 | protected override void OnBefore(IInvocation invocation) 27 | { 28 | var roleClaims = _httpContextAccessor.HttpContext.User.ClaimRoles(); 29 | foreach (var role in _roles) 30 | { 31 | if (roleClaims.Contains(role)) 32 | { 33 | return; 34 | } 35 | } 36 | throw new Exception(Messages.AuthorizationDenied); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/MethodInterception.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Interceptors 7 | { 8 | public abstract class MethodInterception : MethodInterceptionBaseAttribute 9 | { 10 | protected virtual void OnBefore(IInvocation invocation) { } 11 | protected virtual void OnAfter(IInvocation invocation) { } 12 | protected virtual void OnException(IInvocation invocation, System.Exception e) { } 13 | protected virtual void OnSuccess(IInvocation invocation) { } 14 | public override void Intercept(IInvocation invocation) 15 | { 16 | var isSuccess = true; 17 | OnBefore(invocation); 18 | try 19 | { 20 | invocation.Proceed(); 21 | } 22 | catch (Exception e) 23 | { 24 | isSuccess = false; 25 | OnException(invocation, e); 26 | throw; 27 | } 28 | finally 29 | { 30 | if (isSuccess) 31 | { 32 | OnSuccess(invocation); 33 | } 34 | } 35 | OnAfter(invocation); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Core/Utilities/FileHelper/FileHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Text; 6 | 7 | namespace Core.Utilities.FileHelper 8 | { 9 | public static class FileHelper 10 | { 11 | public static string Add(IFormFile file, string path) 12 | { 13 | var newGuidPath = Guid.NewGuid() + Path.GetExtension(file.FileName); 14 | string newPath = path + "\\" + newGuidPath; 15 | if (file == null) 16 | { 17 | return "default.png"; 18 | } 19 | 20 | using (var stream = System.IO.File.Create(newPath)) 21 | { 22 | file.CopyTo(stream); 23 | stream.Flush(); 24 | } 25 | return newGuidPath; 26 | } 27 | 28 | public static void Delete(string path) 29 | { 30 | System.IO.File.Delete(path); 31 | } 32 | 33 | public static string Update(IFormFile file, string path, string imagePath) 34 | { 35 | string updateImagePath = Path.Combine(path, imagePath); 36 | string newGuid = Guid.NewGuid() + Path.GetExtension(file.FileName); 37 | string newGuidPath = path + "\\" + newGuid; 38 | System.IO.File.Move(updateImagePath, newGuidPath); 39 | 40 | return newGuid; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Business/Concrete/ColorManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Business.ValidationRules.FluentValidation; 4 | using Core.Aspects.Autofac.Validation; 5 | using Core.Utilities.Results; 6 | using DataAccess.Abstract; 7 | using Entities.Concrete; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Text; 11 | 12 | namespace Business.Concrete 13 | { 14 | public class ColorManager : IColorService 15 | { 16 | private IColorDal _colorDal; 17 | public ColorManager(IColorDal colorDal) 18 | { 19 | _colorDal = colorDal; 20 | } 21 | [ValidationAspect(typeof(ColorValidator))] 22 | public IResult Add(Color color) 23 | { 24 | _colorDal.Add(color); 25 | return new SuccessResult(Messages.Added); 26 | } 27 | 28 | public IResult Delete(Color color) 29 | { 30 | _colorDal.Delete(color); 31 | return new SuccessResult(Messages.Deleted); 32 | } 33 | 34 | public IDataResult> GetAll() 35 | { 36 | return new SuccessDataResult>(_colorDal.GetAll()); 37 | } 38 | 39 | public IDataResult GetById(int colorId) 40 | { 41 | return new SuccessDataResult(_colorDal.Get(x => x.Id == colorId)); 42 | } 43 | 44 | public IResult Update(Color color) 45 | { 46 | _colorDal.Update(color); 47 | return new SuccessResult(Messages.Updated); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Business/Concrete/BrandManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.BusinessAspects.Autofac; 3 | using Business.Constants; 4 | using Business.ValidationRules.FluentValidation; 5 | using Core.Aspects.Autofac.Validation; 6 | using Core.Utilities.Results; 7 | using DataAccess.Abstract; 8 | using Entities.Concrete; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Text; 12 | 13 | namespace Business.Concrete 14 | { 15 | public class BrandManager : IBrandService 16 | { 17 | private IBrandDal _brandDal; 18 | public BrandManager(IBrandDal brandDal) 19 | { 20 | _brandDal = brandDal; 21 | } 22 | 23 | //[SecuredOperation("Brand.add,admin")] 24 | [ValidationAspect(typeof(BrandValidator))] 25 | public IResult Add(Brand brand) 26 | { 27 | _brandDal.Add(brand); 28 | return new SuccessResult(Messages.BrandAdded); 29 | } 30 | 31 | public IResult Delete(Brand brand) 32 | { 33 | _brandDal.Delete(brand); 34 | return new SuccessResult(Messages.Deleted); 35 | } 36 | 37 | public IDataResult GetById(int brandId) 38 | { 39 | return new SuccessDataResult(_brandDal.Get(x => x.Id == brandId)); 40 | } 41 | 42 | public IDataResult> GetAll() 43 | { 44 | return new SuccessDataResult>(_brandDal.GetAll()); 45 | } 46 | 47 | public IResult Update(Brand brand) 48 | { 49 | _brandDal.Update(brand); 50 | return new SuccessResult(Messages.Updated); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfRentalDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using Entities.DTOs; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | using System.Linq; 9 | 10 | namespace DataAccess.Concrete.EntityFramework 11 | { 12 | public class EfRentalDal : EfEntityRepositoryBase, IRentalDal 13 | { 14 | public List RentalDetail() 15 | { 16 | using (CarContext context = new CarContext()) 17 | { 18 | var result = from re in context.Rentals 19 | join ca in context.Cars 20 | on re.CarId equals ca.Id 21 | join b in context.Brands 22 | on ca.BrandId equals b.Id 23 | join cu in context.Customers 24 | on re.CustomerId equals cu.Id 25 | join us in context.Users 26 | on cu.UserId equals us.Id 27 | select new RentalDetailDto 28 | { 29 | CustomerName = us.FirstName + " " + us.LastName, 30 | BrandName = b.Name, 31 | RentDate = re.RentDate, 32 | ReturnDate = re.ReturnDate, 33 | CompanyName = cu.CompanyName 34 | }; 35 | 36 | return result.ToList(); 37 | 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Business/Concrete/UserManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Business.ValidationRules.FluentValidation; 4 | using Core.Aspects.Autofac.Validation; 5 | using Core.Entities.Concrete; 6 | using Core.Utilities.Results; 7 | using DataAccess.Abstract; 8 | using Entities.Concrete; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Text; 12 | 13 | namespace Business.Concrete 14 | { 15 | public class UserManager : IUserService 16 | { 17 | private readonly IUserDal _userDal; 18 | public UserManager(IUserDal userDal) 19 | { 20 | _userDal = userDal; 21 | } 22 | [ValidationAspect(typeof(UserValidator))] 23 | public IResult Add(User user) 24 | { 25 | _userDal.Add(user); 26 | return new SuccessResult(Messages.Added); 27 | } 28 | 29 | public IResult Delete(User user) 30 | { 31 | _userDal.Delete(user); 32 | return new SuccessResult(Messages.Deleted); 33 | } 34 | 35 | public IDataResult> GetAll() 36 | { 37 | return new SuccessDataResult>(_userDal.GetAll()); 38 | } 39 | 40 | public User GetByMail(string email) 41 | { 42 | return _userDal.Get(u => u.Email == email); 43 | } 44 | 45 | public IDataResult> GetClaims(User user) 46 | { 47 | return new SuccessDataResult>(_userDal.GetClaims(user)); 48 | } 49 | 50 | public IResult Update(User user) 51 | { 52 | _userDal.Update(user); 53 | return new SuccessResult(Messages.Updated); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Business/Concrete/CustomerManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Business.ValidationRules.FluentValidation; 4 | using Core.Aspects.Autofac.Validation; 5 | using Core.Utilities.Results; 6 | using DataAccess.Abstract; 7 | using Entities.Concrete; 8 | using Entities.DTOs; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Text; 12 | 13 | namespace Business.Concrete 14 | { 15 | public class CustomerManager : ICustomerService 16 | { 17 | private readonly ICustomerDal _customerDal; 18 | public CustomerManager(ICustomerDal customerDal) 19 | { 20 | _customerDal = customerDal; 21 | } 22 | [ValidationAspect(typeof(CustomerValidator))] 23 | public IResult Add(Customer customer) 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 | 36 | public IDataResult> GetAll() 37 | { 38 | return new SuccessDataResult>(_customerDal.GetAll()); 39 | } 40 | 41 | public IDataResult GetById(int customerId) 42 | { 43 | return new SuccessDataResult(_customerDal.Get(x => x.Id == customerId)); 44 | } 45 | 46 | public IDataResult> GetDetails() 47 | { 48 | return new SuccessDataResult>(_customerDal.CustomerDetail()); 49 | } 50 | 51 | public IResult Update(Customer customer) 52 | { 53 | _customerDal.Update(customer); 54 | return new SuccessResult(Messages.Updated); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Validation/ValidationAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.CrossCuttingConcerns.Validation; 3 | using Core.Utilities.Interceptors; 4 | using FluentValidation; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | namespace Core.Aspects.Autofac.Validation 11 | { 12 | public class ValidationAspect : MethodInterception 13 | { 14 | private Type _validatorType; 15 | public ValidationAspect(Type validatorType) 16 | { 17 | //eğer gönderilen validator type IValiadtory type değilse ona kız diyoruz burada 18 | if (!typeof(IValidator).IsAssignableFrom(validatorType)) 19 | { 20 | throw new System.Exception("Bu bir doğrulama sınıfı değil"); 21 | } 22 | //eğer hata almaz isek gelen validatory tipi buraya ata 23 | _validatorType = validatorType; 24 | } 25 | protected override void OnBefore(IInvocation invocation) 26 | { 27 | //reflection çalışma anında bir şeyleri çalıştırabilmemizi sağlar 28 | var validator = (IValidator)Activator.CreateInstance(_validatorType); 29 | //validation type ın base tipi nin generic argümanlarından ilkini al dedik yani AbstractValidator 30 | //gibi burada ilk generic parametreyi aldık 31 | var entityType = _validatorType.BaseType.GetGenericArguments()[0]; 32 | //invocation metod demek metodun parametrelerine bak entity type denk gelen yani producta eşit olan parametreleri bul 33 | 34 | var entities = invocation.Arguments.Where(t => t.GetType() == entityType); 35 | //her birini tek tek gez validator toolu kullanarak validate et dedik. 36 | foreach (var entity in entities) 37 | { 38 | ValidationTool.Validate(validator, entity); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /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 : ControllerBase 15 | { 16 | private IAuthService _authService; 17 | 18 | public AuthController(IAuthService authService) 19 | { 20 | _authService = authService; 21 | } 22 | 23 | [HttpPost("login")] 24 | public ActionResult Login(UserForLoginDto userForLoginDto) 25 | { 26 | var userToLogin = _authService.Login(userForLoginDto); 27 | if (!userToLogin.Success) 28 | { 29 | return BadRequest(userToLogin.Message); 30 | } 31 | 32 | var result = _authService.CreateAccessToken(userToLogin.Data); 33 | if (result.Success) 34 | { 35 | return Ok(result); 36 | } 37 | 38 | return BadRequest(result.Message); 39 | } 40 | 41 | [HttpPost("register")] 42 | public ActionResult Register(UserForRegisterDto userForRegisterDto) 43 | { 44 | var userExists = _authService.UserExists(userForRegisterDto.Email); 45 | if (!userExists.Success) 46 | { 47 | return BadRequest(userExists.Message); 48 | } 49 | 50 | var registerResult = _authService.Register(userForRegisterDto, userForRegisterDto.Password); 51 | var result = _authService.CreateAccessToken(registerResult.Data); 52 | if (result.Success) 53 | { 54 | return Ok(result); 55 | } 56 | 57 | return BadRequest(result.Message); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Core/Extensions/ExceptionMiddleware.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | using FluentValidation.Results; 3 | using Microsoft.AspNetCore.Http; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Net; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Core.Extensions 11 | { 12 | public class ExceptionMiddleware 13 | { 14 | private RequestDelegate _next; 15 | 16 | public ExceptionMiddleware(RequestDelegate next) 17 | { 18 | _next = next; 19 | 20 | } 21 | 22 | public async Task InvokeAsync(HttpContext httpContext) 23 | { 24 | try 25 | { 26 | await _next(httpContext); 27 | } 28 | catch (Exception e) 29 | { 30 | await HandleExceptionAsync(httpContext, e); 31 | } 32 | } 33 | 34 | private Task HandleExceptionAsync(HttpContext httpContext, Exception e) 35 | { 36 | httpContext.Response.ContentType = "application/json"; 37 | httpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; 38 | IEnumerable errors; 39 | 40 | string message = "Internal Server Error"; 41 | if (e.GetType() == typeof(ValidationException)) 42 | { 43 | message = e.Message; 44 | errors = ((ValidationException)e).Errors; 45 | httpContext.Response.StatusCode = 400; 46 | 47 | return httpContext.Response.WriteAsync(new ValidationErrorDetails 48 | { 49 | Message = message, 50 | StatusCode = 400, 51 | Errors = errors 52 | }.ToString()); 53 | } 54 | 55 | return httpContext.Response.WriteAsync(new ErrorDetails 56 | { 57 | StatusCode = httpContext.Response.StatusCode, 58 | Message = message 59 | }.ToString()); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Core/DataAccess/EntityFramework/EfEntityRepositoryBase.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using Microsoft.EntityFrameworkCore; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Linq.Expressions; 7 | using System.Text; 8 | 9 | namespace Core.DataAccess.EntityFramework 10 | { 11 | public class EfEntityRepositoryBase : IEntityRepository 12 | where TEntity : class, IEntity, new() 13 | where TContext : DbContext, new() 14 | { 15 | public void Add(TEntity entity) 16 | { 17 | using (TContext context = new TContext()) 18 | { 19 | var addedEntity = context.Entry(entity); 20 | addedEntity.State = EntityState.Added; 21 | context.SaveChanges(); 22 | } 23 | } 24 | 25 | public void Delete(TEntity entity) 26 | { 27 | using (TContext context = new TContext()) 28 | { 29 | var deletedEntity = context.Entry(entity); 30 | deletedEntity.State = EntityState.Deleted; 31 | context.SaveChanges(); 32 | } 33 | } 34 | 35 | public TEntity Get(Expression> filter) 36 | { 37 | using (TContext context = new TContext()) 38 | { 39 | return context.Set().SingleOrDefault(filter); 40 | } 41 | } 42 | 43 | public List GetAll(Expression> filter = null) 44 | { 45 | using (TContext context = new TContext()) 46 | { 47 | return filter == null 48 | ? context.Set().ToList() 49 | : context.Set().Where(filter).ToList(); 50 | } 51 | } 52 | 53 | public void Update(TEntity entity) 54 | { 55 | using (TContext context = new TContext()) 56 | { 57 | var updatedEntity = context.Entry(entity); 58 | updatedEntity.State = EntityState.Modified; 59 | context.SaveChanges(); 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /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 | private readonly IBrandService _brandService; 17 | public BrandsController(IBrandService brandService) 18 | { 19 | _brandService = brandService; 20 | } 21 | [HttpGet("getall")] 22 | public IActionResult GetAll() 23 | { 24 | var result = _brandService.GetAll(); 25 | if (result.Success) 26 | { 27 | return Ok(result); 28 | } 29 | return BadRequest(result); 30 | } 31 | [HttpPost("add")] 32 | public IActionResult Add(Brand brand) 33 | { 34 | var result = _brandService.Add(brand); 35 | if (result.Success) 36 | { 37 | return Ok(result); 38 | } 39 | return BadRequest(result); 40 | } 41 | [HttpGet("getbyid")] 42 | public IActionResult GetById(int id) 43 | { 44 | var result = _brandService.GetById(id); 45 | if (result.Success) 46 | { 47 | return Ok(result); 48 | } 49 | return BadRequest(result); 50 | } 51 | [HttpPost("delete")] 52 | public IActionResult Delete(Brand brand) 53 | { 54 | var result = _brandService.Delete(brand); 55 | if (result.Success) 56 | { 57 | return Ok(result); 58 | } 59 | return BadRequest(result); 60 | } 61 | [HttpPost("update")] 62 | public IActionResult Update(Brand brand) 63 | { 64 | var result = _brandService.Update(brand); 65 | if (result.Success) 66 | { 67 | return Ok(result); 68 | } 69 | return BadRequest(result); 70 | } 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /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 | private readonly IColorService _colorService; 17 | public ColorsController(IColorService colorService) 18 | { 19 | _colorService = colorService; 20 | } 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 | return BadRequest(result); 31 | } 32 | [HttpPost("add")] 33 | public IActionResult Add(Color color) 34 | { 35 | var result = _colorService.Add(color); 36 | if (result.Success) 37 | { 38 | return Ok(result); 39 | } 40 | return BadRequest(result); 41 | } 42 | [HttpGet("getbyid")] 43 | public IActionResult GetById(int id) 44 | { 45 | var result = _colorService.GetById(id); 46 | if (result.Success) 47 | { 48 | return Ok(result); 49 | } 50 | return BadRequest(result); 51 | } 52 | [HttpPost("delete")] 53 | public IActionResult Delete(Color color) 54 | { 55 | var result = _colorService.Delete(color); 56 | if (result.Success) 57 | { 58 | return Ok(result); 59 | } 60 | return BadRequest(result); 61 | } 62 | [HttpPost("update")] 63 | public IActionResult Update(Color color) 64 | { 65 | var result = _colorService.Update(color); 66 | if (result.Success) 67 | { 68 | return Ok(result); 69 | } 70 | return BadRequest(result); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Business/Concrete/CarImageManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Core.Utilities.Business; 4 | using Core.Utilities.Results; 5 | using DataAccess.Abstract; 6 | using Entities.Concrete; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.IO; 10 | using System.Text; 11 | 12 | namespace Business.Concrete 13 | { 14 | public class CarImageManager : ICarImageService 15 | { 16 | private readonly ICarImageDal _carImageDal; 17 | public CarImageManager(ICarImageDal carImageDal) 18 | { 19 | _carImageDal = carImageDal; 20 | } 21 | 22 | public IResult Add(CarImage carImage) 23 | { 24 | var result = BusinessRules.Run(CheckCarImageCount(carImage.CarId)); 25 | if (result != null) 26 | { 27 | return result; 28 | } 29 | _carImageDal.Add(carImage); 30 | 31 | return new SuccessResult(); 32 | } 33 | 34 | public IResult Delete(CarImage carImage) 35 | { 36 | _carImageDal.Delete(carImage); 37 | return new SuccessResult(); 38 | } 39 | 40 | public IDataResult> GetAll() 41 | { 42 | return new SuccessDataResult>(_carImageDal.GetAll()); 43 | } 44 | 45 | public IDataResult GetById(int id) 46 | { 47 | return new SuccessDataResult(_carImageDal.Get(x => x.Id == id)); 48 | } 49 | 50 | public IDataResult> GetByCarId(int id) 51 | { 52 | return new SuccessDataResult>(_carImageDal.GetAll(x => x.CarId == id)); 53 | } 54 | 55 | public IResult Update(CarImage carImage) 56 | { 57 | _carImageDal.Update(carImage); 58 | return new SuccessResult(); 59 | } 60 | private IResult CheckCarImageCount(int carId) 61 | { 62 | var result = _carImageDal.GetAll(x => x.CarId == carId); 63 | if (result.Count >= 5) 64 | { 65 | return new ErrorResult(Messages.ImageInsertionLimitExceeded); 66 | } 67 | return new SuccessResult(); 68 | } 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Business/Concrete/RentalManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Business.ValidationRules.FluentValidation; 4 | using Core.Aspects.Autofac.Validation; 5 | using Core.Utilities.Business; 6 | using Core.Utilities.Results; 7 | using DataAccess.Abstract; 8 | using Entities.Concrete; 9 | using Entities.DTOs; 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Linq; 13 | using System.Text; 14 | 15 | namespace Business.Concrete 16 | { 17 | public class RentalManager : IRentalService 18 | { 19 | private readonly IRentalDal _rentalDal; 20 | public RentalManager(IRentalDal rentalDal) 21 | { 22 | _rentalDal = rentalDal; 23 | } 24 | [ValidationAspect(typeof(RentalValidator))] 25 | public IResult Add(Rental rental) 26 | { 27 | _rentalDal.Add(rental); 28 | return new SuccessResult(Messages.Added); 29 | } 30 | 31 | public IResult CheckIfCarRent(Rental rental) 32 | { 33 | var carCheck = _rentalDal.Get(x => x.CarId == rental.CarId && rental.RentDate > x.RentDate && 34 | rental.ReturnDate < x.ReturnDate); 35 | if (carCheck != null) 36 | { 37 | return new ErrorResult(Messages.RentStatus); 38 | } 39 | return new SuccessResult(); 40 | } 41 | 42 | public IResult Delete(Rental rental) 43 | { 44 | _rentalDal.Delete(rental); 45 | return new SuccessResult(Messages.Deleted); 46 | } 47 | 48 | public IDataResult> GetAll() 49 | { 50 | return new SuccessDataResult>(_rentalDal.GetAll()); 51 | } 52 | 53 | public IDataResult GetById(int rentalId) 54 | { 55 | return new SuccessDataResult(_rentalDal.Get(x => x.Id == rentalId)); 56 | } 57 | 58 | public IDataResult> RentalDetail() 59 | { 60 | return new SuccessDataResult>(_rentalDal.RentalDetail()); 61 | } 62 | 63 | public IResult Update(Rental rental) 64 | { 65 | _rentalDal.Update(rental); 66 | return new SuccessResult(Messages.Updated); 67 | } 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CustomersController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class CustomersController : ControllerBase 15 | { 16 | private readonly ICustomerService _customerService; 17 | public CustomersController(ICustomerService customerService) 18 | { 19 | _customerService = customerService; 20 | } 21 | [HttpGet("getall")] 22 | public IActionResult GetAll() 23 | { 24 | var result = _customerService.GetDetails(); 25 | if (result.Success) 26 | { 27 | return Ok(result); 28 | } 29 | return BadRequest(result); 30 | } 31 | [HttpPost("add")] 32 | public IActionResult Add(Customer customer) 33 | { 34 | var result = _customerService.Add(customer); 35 | if (result.Success) 36 | { 37 | return Ok(result); 38 | } 39 | return BadRequest(result); 40 | } 41 | [HttpPost("getbyid")] 42 | public IActionResult GetById(int id) 43 | { 44 | var result = _customerService.GetById(id); 45 | if (result.Success) 46 | { 47 | return Ok(result); 48 | } 49 | return BadRequest(result); 50 | } 51 | [HttpPost("delete")] 52 | public IActionResult Delete(Customer customer) 53 | { 54 | var result = _customerService.Delete(customer); 55 | if (result.Success) 56 | { 57 | return Ok(result); 58 | } 59 | return BadRequest(result); 60 | } 61 | [HttpPost("update")] 62 | public IActionResult Update(Customer customer) 63 | { 64 | var result = _customerService.Update(customer); 65 | if (result.Success) 66 | { 67 | return Ok(result); 68 | } 69 | return BadRequest(result); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Business/DependencyResolvers/Autofac/AutofacBusinessModule.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Extras.DynamicProxy; 3 | using Business.Abstract; 4 | using Business.Concrete; 5 | using Castle.DynamicProxy; 6 | using Core.Utilities.Interceptors; 7 | using Core.Utilities.Security.JWT; 8 | using DataAccess.Abstract; 9 | using DataAccess.Concrete.EntityFramework; 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 | builder.RegisterType().As().SingleInstance(); 29 | builder.RegisterType().As().SingleInstance(); 30 | builder.RegisterType().As().SingleInstance(); 31 | builder.RegisterType().As().SingleInstance(); 32 | builder.RegisterType().As().SingleInstance(); 33 | builder.RegisterType().As().SingleInstance(); 34 | builder.RegisterType().As().SingleInstance(); 35 | builder.RegisterType().As().SingleInstance(); 36 | 37 | var assembly = System.Reflection.Assembly.GetExecutingAssembly(); 38 | 39 | builder.RegisterAssemblyTypes(assembly).AsImplementedInterfaces() 40 | .EnableInterfaceInterceptors(new ProxyGenerationOptions() 41 | { 42 | Selector = new AspectInterceptorSelector() 43 | }).SingleInstance(); 44 | 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /WebAPI/Controllers/UsersController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Core.Entities.Concrete; 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 UsersController : ControllerBase 16 | { 17 | private readonly IUserService _userService; 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 | [HttpPost("add")] 34 | public IActionResult Add(User user) 35 | { 36 | var result = _userService.Add(user); 37 | if (result.Success) 38 | { 39 | return Ok(result); 40 | } 41 | return BadRequest(result); 42 | } 43 | [HttpPost("getbyid")] 44 | public IActionResult GetById(string email) 45 | { 46 | var result = _userService.GetByMail(email); 47 | if (result != null) 48 | { 49 | return Ok(result); 50 | } 51 | return BadRequest(result); 52 | } 53 | [HttpGet("getbymail")] 54 | public IActionResult GetByMail(string email) 55 | { 56 | var result = _userService.GetByMail(email); 57 | if (result != null) 58 | { 59 | return Ok(result); 60 | } 61 | return BadRequest(result); 62 | } 63 | [HttpPost("delete")] 64 | public IActionResult Delete(User user) 65 | { 66 | var result = _userService.Delete(user); 67 | if (result.Success) 68 | { 69 | return Ok(result); 70 | } 71 | return BadRequest(result); 72 | } 73 | [HttpPost("update")] 74 | public IActionResult Update(User user) 75 | { 76 | var result = _userService.Update(user); 77 | if (result.Success) 78 | { 79 | return Ok(result); 80 | } 81 | return BadRequest(result); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /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 | private readonly IRentalService _rentalService; 17 | public RentalsController(IRentalService rentalService) 18 | { 19 | _rentalService = rentalService; 20 | } 21 | [HttpGet("getall")] 22 | public IActionResult GetAll() 23 | { 24 | var result = _rentalService.RentalDetail(); 25 | if (result.Success) 26 | { 27 | return Ok(result); 28 | } 29 | return BadRequest(result); 30 | } 31 | [HttpPost("add")] 32 | public IActionResult Add(Rental rental) 33 | { 34 | var result = _rentalService.Add(rental); 35 | if (result.Success) 36 | { 37 | return Ok(result); 38 | } 39 | return BadRequest(result); 40 | } 41 | [HttpPost("getbyid")] 42 | public IActionResult GetById(int id) 43 | { 44 | var result = _rentalService.GetById(id); 45 | if (result.Success) 46 | { 47 | return Ok(result); 48 | } 49 | return BadRequest(result); 50 | } 51 | [HttpPost("delete")] 52 | public IActionResult Delete(Rental rental) 53 | { 54 | var result = _rentalService.Delete(rental); 55 | if (result.Success) 56 | { 57 | return Ok(result); 58 | } 59 | return BadRequest(result); 60 | } 61 | [HttpPost("update")] 62 | public IActionResult Update(Rental rental) 63 | { 64 | var result = _rentalService.Update(rental); 65 | if (result.Success) 66 | { 67 | return Ok(result); 68 | } 69 | return BadRequest(result); 70 | } 71 | [HttpPost("checkifcarrent")] 72 | public IActionResult CheckIfCarRent(Rental rental) 73 | { 74 | var result = _rentalService.CheckIfCarRent(rental); 75 | if (result.Success) 76 | { 77 | return Ok(result); 78 | } 79 | return BadRequest(result); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /.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; 5 | using Core.Utilities.Security.Hashing; 6 | using Core.Utilities.Security.JWT; 7 | using Entities.DTOs; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Text; 11 | 12 | namespace Business.Concrete 13 | { 14 | public class AuthManager : IAuthService 15 | { 16 | IUserService _userService; 17 | ITokenHelper _tokenHelper; 18 | public AuthManager(IUserService userService, ITokenHelper tokenHelper) 19 | { 20 | _userService = userService; 21 | _tokenHelper = tokenHelper; 22 | } 23 | public IDataResult CreateAccessToken(User user) 24 | { 25 | 26 | var claims = _userService.GetClaims(user); 27 | var accessToken = _tokenHelper.CreateToken(user, claims.Data); 28 | return new SuccessDataResult(accessToken, Messages.AccessTokenCreated); 29 | } 30 | 31 | public IDataResult Login(UserForLoginDto userForLoginDto) 32 | { 33 | var userToCheck = _userService.GetByMail(userForLoginDto.Email); 34 | if (userToCheck == null) 35 | { 36 | return new ErrorDataResult(Messages.UserNotFound); 37 | } 38 | 39 | if (!HashingHelper.VerifyPasswordHash(userForLoginDto.Password, userToCheck.PasswordHash, userToCheck.PasswordSalt)) 40 | { 41 | return new ErrorDataResult(Messages.PasswordError); 42 | } 43 | 44 | return new SuccessDataResult(userToCheck, Messages.SuccessfulLogin); 45 | } 46 | 47 | public IDataResult Register(UserForRegisterDto userForRegisterDto, string password) 48 | { 49 | 50 | byte[] passwordHash, passwordSalt; 51 | HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt); 52 | var user = new User 53 | { 54 | Email = userForRegisterDto.Email, 55 | FirstName = userForRegisterDto.FirstName, 56 | LastName = userForRegisterDto.LastName, 57 | PasswordHash = passwordHash, 58 | PasswordSalt = passwordSalt, 59 | Status = true 60 | }; 61 | _userService.Add(user); 62 | return new SuccessDataResult(user, Messages.UserRegistered); 63 | 64 | } 65 | 66 | public IResult UserExists(string email) 67 | { 68 | if (_userService.GetByMail(email) != null) 69 | { 70 | return new ErrorResult(Messages.UserAlreadyExists); 71 | } 72 | return new SuccessResult(); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CarsController.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 CarsController : ControllerBase 15 | { 16 | private readonly ICarService _carService; 17 | public CarsController(ICarService carService) 18 | { 19 | _carService = carService; 20 | } 21 | 22 | [HttpGet("getall")] 23 | public IActionResult GetAll() 24 | { 25 | var result = _carService.GetCarDetails(); 26 | if (result.Success) 27 | { 28 | return Ok(result); 29 | } 30 | return BadRequest(result); 31 | } 32 | [HttpPost("add")] 33 | public IActionResult Add(Car car) 34 | { 35 | var result = _carService.Add(car); 36 | if (result.Success) 37 | { 38 | return Ok(result); 39 | } 40 | return BadRequest(result); 41 | } 42 | [HttpGet("getbycarid")] 43 | public IActionResult GetByCarId(int carId) 44 | { 45 | var result = _carService.GetByIdCarDetails(carId); 46 | if (result.Success) 47 | { 48 | return Ok(result); 49 | } 50 | return BadRequest(result); 51 | } 52 | [HttpGet("getbyid")] 53 | public IActionResult GetById(int id) 54 | { 55 | var result = _carService.GetById(id); 56 | if (result.Success) 57 | { 58 | return Ok(result); 59 | } 60 | return BadRequest(result); 61 | } 62 | [HttpGet("getbycolorandbrandid")] 63 | public IActionResult GetByColorAndBrandId(int brandId, int colorId) 64 | { 65 | var result = _carService.GetByColorAndBrand(brandId, colorId); 66 | if (result.Success) 67 | { 68 | return Ok(result); 69 | } 70 | return BadRequest(result); 71 | } 72 | [HttpPost("delete")] 73 | public IActionResult Delete(Car car) 74 | { 75 | var result = _carService.Delete(car); 76 | if (result.Success) 77 | { 78 | return Ok(result); 79 | } 80 | return BadRequest(result); 81 | } 82 | [HttpPost("update")] 83 | public IActionResult Update(Car car) 84 | { 85 | var result = _carService.Update(car); 86 | if (result.Success) 87 | { 88 | return Ok(result); 89 | } 90 | return BadRequest(result); 91 | } 92 | 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /ReCapProject.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30907.101 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "Entities\Entities.csproj", "{526CCF61-0024-48C3-B792-03C582EB38CD}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAccess", "DataAccess\DataAccess.csproj", "{499C60D8-171A-48AC-BAF2-437ACC9C5263}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Business", "Business\Business.csproj", "{6EDBFC8C-E6B0-47B2-BCF3-6CB592AB4D03}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{2843BC27-9004-45F7-A208-5D4B53CBE303}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebAPI", "WebAPI\WebAPI.csproj", "{59032895-B388-4384-86DC-9A420BFC1181}" 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Any CPU = Debug|Any CPU 19 | Release|Any CPU = Release|Any CPU 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {526CCF61-0024-48C3-B792-03C582EB38CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {526CCF61-0024-48C3-B792-03C582EB38CD}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {526CCF61-0024-48C3-B792-03C582EB38CD}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {526CCF61-0024-48C3-B792-03C582EB38CD}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {499C60D8-171A-48AC-BAF2-437ACC9C5263}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {499C60D8-171A-48AC-BAF2-437ACC9C5263}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {499C60D8-171A-48AC-BAF2-437ACC9C5263}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {499C60D8-171A-48AC-BAF2-437ACC9C5263}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {6EDBFC8C-E6B0-47B2-BCF3-6CB592AB4D03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {6EDBFC8C-E6B0-47B2-BCF3-6CB592AB4D03}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {6EDBFC8C-E6B0-47B2-BCF3-6CB592AB4D03}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {6EDBFC8C-E6B0-47B2-BCF3-6CB592AB4D03}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {2843BC27-9004-45F7-A208-5D4B53CBE303}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {2843BC27-9004-45F7-A208-5D4B53CBE303}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {2843BC27-9004-45F7-A208-5D4B53CBE303}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {2843BC27-9004-45F7-A208-5D4B53CBE303}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {59032895-B388-4384-86DC-9A420BFC1181}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {59032895-B388-4384-86DC-9A420BFC1181}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {59032895-B388-4384-86DC-9A420BFC1181}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {59032895-B388-4384-86DC-9A420BFC1181}.Release|Any CPU.Build.0 = Release|Any CPU 42 | EndGlobalSection 43 | GlobalSection(SolutionProperties) = preSolution 44 | HideSolutionNode = FALSE 45 | EndGlobalSection 46 | GlobalSection(ExtensibilityGlobals) = postSolution 47 | SolutionGuid = {7E482852-7DAA-4579-88FD-59DE4439B2CA} 48 | EndGlobalSection 49 | EndGlobal 50 | -------------------------------------------------------------------------------- /WebAPI/Startup.cs: -------------------------------------------------------------------------------- 1 | using Autofac.Extensions.DependencyInjection; 2 | using Core.Extensions; 3 | using Core.IoC; 4 | using Core.Utilities.Security.Encryption; 5 | using Core.Utilities.Security.JWT; 6 | using Microsoft.AspNetCore.Authentication.JwtBearer; 7 | using Microsoft.AspNetCore.Builder; 8 | using Microsoft.AspNetCore.Hosting; 9 | using Microsoft.AspNetCore.Http; 10 | using Microsoft.AspNetCore.HttpsPolicy; 11 | using Microsoft.AspNetCore.Mvc; 12 | using Microsoft.Extensions.Configuration; 13 | using Microsoft.Extensions.DependencyInjection; 14 | using Microsoft.Extensions.Hosting; 15 | using Microsoft.Extensions.Logging; 16 | using Microsoft.IdentityModel.Tokens; 17 | using System; 18 | using System.Collections.Generic; 19 | using System.Linq; 20 | using System.Threading.Tasks; 21 | 22 | namespace WebAPI 23 | { 24 | public class Startup 25 | { 26 | public readonly IConfiguration Configuration; 27 | public Startup(IConfiguration configuration) 28 | { 29 | Configuration = configuration; 30 | } 31 | 32 | // This method gets called by the runtime. Use this method to add services to the container. 33 | public void ConfigureServices(IServiceCollection services) 34 | { 35 | services.AddSingleton(); 36 | 37 | services.AddAutofac(); 38 | 39 | services.AddCors(); 40 | 41 | services.AddControllers(); 42 | 43 | var tokenOptions = Configuration.GetSection("TokenOptions").Get(); 44 | 45 | services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) 46 | .AddJwtBearer(options => 47 | { 48 | options.TokenValidationParameters = new TokenValidationParameters 49 | { 50 | ValidateIssuer = true, 51 | ValidateAudience = true, 52 | ValidateLifetime = true, 53 | ValidIssuer = tokenOptions.Issuer, 54 | ValidAudience = tokenOptions.Audience, 55 | ValidateIssuerSigningKey = true, 56 | IssuerSigningKey = SecurityKeyHelper.CreateSecurityKey(tokenOptions.SecurityKey) 57 | }; 58 | }); 59 | ServiceTool.Create(services); 60 | } 61 | 62 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 63 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 64 | { 65 | if (env.IsDevelopment()) 66 | { 67 | app.UseDeveloperExceptionPage(); 68 | } 69 | app.ConfigureCustomExceptionMiddleware(); 70 | 71 | 72 | app.UseStaticFiles(); 73 | app.UseCors(builder => builder.WithOrigins("http://localhost:4200").AllowAnyHeader()); 74 | 75 | app.UseHttpsRedirection(); 76 | 77 | app.UseRouting(); 78 | 79 | app.UseAuthorization(); 80 | 81 | app.UseEndpoints(endpoints => 82 | { 83 | endpoints.MapControllers(); 84 | }); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Business/Concrete/CarManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.BusinessAspects.Autofac; 3 | using Business.Constants; 4 | using Business.ValidationRules.FluentValidation; 5 | using Core.Aspects.Autofac.Validation; 6 | using Core.Utilities.Results; 7 | using DataAccess.Abstract; 8 | using Entities.Concrete; 9 | using Entities.DTOs; 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Text; 13 | 14 | namespace Business.Concrete 15 | { 16 | public class CarManager : ICarService 17 | { 18 | 19 | private ICarDal _carDal; 20 | public CarManager(ICarDal carDal) 21 | { 22 | _carDal = carDal; 23 | } 24 | [SecuredOperation("admin")] 25 | [ValidationAspect(typeof(CarValidator))] 26 | public IResult Add(Car car) 27 | { 28 | 29 | _carDal.Add(car); 30 | return new SuccessResult(Messages.Added); 31 | } 32 | 33 | public IResult Delete(Car car) 34 | { 35 | _carDal.Delete(car); 36 | return new SuccessResult(Messages.Deleted); 37 | } 38 | 39 | public IDataResult GetById(int carId) 40 | { 41 | return new SuccessDataResult(_carDal.Get(x => x.Id == carId)); 42 | } 43 | 44 | public IDataResult> GetAll() 45 | { 46 | return new SuccessDataResult>(_carDal.GetAll()); 47 | } 48 | 49 | public IDataResult> GetCarsByBrandId(int brandId) 50 | { 51 | return new SuccessDataResult>(_carDal.GetAll(x => x.BrandId == brandId)); 52 | } 53 | 54 | public IDataResult> GetCarsByColorId(int colorId) 55 | { 56 | return new SuccessDataResult>(_carDal.GetAll(x => x.ColorId == colorId)); 57 | } 58 | public IDataResult> GetByColorAndBrand(int brandId, int colorId) 59 | { 60 | return new SuccessDataResult> 61 | (_carDal.GetCarDetails(x => x.BrandId == brandId || x.ColorId == colorId)); 62 | } 63 | 64 | public IResult Update(Car car) 65 | { 66 | _carDal.Update(car); 67 | return new SuccessResult(Messages.CarUpdated); 68 | } 69 | 70 | public IDataResult> GetCarDetails() 71 | { 72 | return new SuccessDataResult>(_carDal.CarDetails()); 73 | } 74 | 75 | public IDataResult GetByIdCarDetails(int id) 76 | { 77 | return new SuccessDataResult(_carDal.GetCarDetail(x => x.Id == id)); 78 | } 79 | 80 | public IDataResult> GetCarDetailsBrandName(string brandName) 81 | { 82 | return new SuccessDataResult> 83 | (_carDal.GetCarDetails(x => x.BrandName == brandName)); 84 | } 85 | 86 | public IDataResult> GetCarDetailsColorName(string colorName) 87 | { 88 | return new SuccessDataResult> 89 | (_carDal.GetCarDetails(x => x.ColorName == colorName)); 90 | } 91 | 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/JwtHelper.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Core.Utilities.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 | { 37 | Token = token, 38 | Expiration = _accessTokenExpiration 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.Id.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 | public static class ClaimsPrincipalExtensions 68 | { 69 | public static List Claims(this ClaimsPrincipal claimsPrincipal, string claimType) 70 | { 71 | var result = claimsPrincipal?.FindAll(claimType)?.Select(x => x.Value).ToList(); 72 | return result; 73 | } 74 | 75 | public static List ClaimRoles(this ClaimsPrincipal claimsPrincipal) 76 | { 77 | return claimsPrincipal?.Claims(ClaimTypes.Role); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /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 System.IO; 11 | using Core.Utilities.FileHelper; 12 | 13 | namespace WebAPI.Controllers 14 | { 15 | [Route("api/[controller]")] 16 | [ApiController] 17 | public class CarImagesController : ControllerBase 18 | { 19 | 20 | private readonly ICarImageService _carImageService; 21 | private readonly IWebHostEnvironment _environment; 22 | public CarImagesController(ICarImageService carImageService, IWebHostEnvironment webHostEnvironment) 23 | { 24 | _carImageService = carImageService; 25 | _environment = webHostEnvironment; 26 | } 27 | [HttpGet("getall")] 28 | public IActionResult GetAll() 29 | { 30 | 31 | var result = _carImageService.GetAll(); 32 | if (result.Success) 33 | { 34 | return Ok(result); 35 | } 36 | return BadRequest(result); 37 | } 38 | [HttpGet("getbycarid")] 39 | public IActionResult GetByCarId(int id) 40 | { 41 | var result = _carImageService.GetByCarId(id); 42 | if (result.Success) 43 | { 44 | return Ok(result); 45 | } 46 | return BadRequest(result); 47 | } 48 | [HttpPost("add")] 49 | public IActionResult Add([FromForm(Name = ("Image"))] IFormFile file, [FromForm] CarImage carImage) 50 | { 51 | string path = _environment.WebRootPath + "\\Images"; 52 | var guidPath = FileHelper.Add(file, path); 53 | var result = _carImageService.Add(new CarImage 54 | { 55 | CarId = carImage.CarId, 56 | Date = DateTime.Now, 57 | ImagePath = guidPath 58 | }); 59 | 60 | if (result.Success) 61 | { 62 | return Ok(result); 63 | } 64 | return BadRequest(result); 65 | } 66 | [HttpPost("delete")] 67 | public IActionResult Delete(CarImage carImage) 68 | { 69 | string path = _environment.WebRootPath + "\\Images"; 70 | FileHelper.Delete(path + "\\" + carImage.ImagePath); 71 | 72 | var result = _carImageService.Delete(carImage); 73 | if (result.Success) 74 | { 75 | return Ok(result); 76 | } 77 | return BadRequest(result); 78 | } 79 | [HttpPost("update")] 80 | public IActionResult Update([FromForm] CarImage carImage, [FromForm(Name = ("Image"))] IFormFile file) 81 | { 82 | string path = _environment.WebRootPath + "\\Images"; 83 | 84 | string newGuid = FileHelper.Update(file, path, carImage.ImagePath); 85 | 86 | carImage.ImagePath = newGuid; 87 | carImage.Date = DateTime.Now; 88 | var result = _carImageService.Update(carImage); 89 | 90 | if (result.Success) 91 | { 92 | return Ok(result); 93 | } 94 | return BadRequest(result); 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCarDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using Entities.DTOs; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Linq.Expressions; 9 | using System.Text; 10 | 11 | namespace DataAccess.Concrete.EntityFramework 12 | { 13 | public class EfCarDal : EfEntityRepositoryBase, ICarDal 14 | { 15 | public List CarDetails() 16 | { 17 | using (CarContext context = new CarContext()) 18 | { 19 | // CarName, BrandName, ColorName, DailyPrice 20 | var result = (from car in context.Cars.Cast() 21 | join brand in context.Brands 22 | on car.BrandId equals brand.Id 23 | join col in context.Colors 24 | on car.ColorId equals col.Id 25 | join carImage in context.CarImages 26 | on car.Id equals carImage.CarId 27 | select new CarDetailDto 28 | { 29 | Id = car.Id, 30 | CarName = car.CarName, 31 | BrandName = brand.Name, 32 | BrandId = brand.Id, 33 | ColorName = col.Name, 34 | ColorId = col.Id, 35 | DailyPrice = car.DailyPrice, 36 | ModelYear = car.ModelYear, 37 | Description = car.Description, 38 | ImagePath = carImage.ImagePath 39 | }).ToList(); 40 | 41 | return result; 42 | } 43 | 44 | } 45 | 46 | public List GetCarDetails(Expression> filter = null) 47 | { 48 | using (CarContext context = new CarContext()) 49 | { 50 | // CarName, BrandName, ColorName, DailyPrice 51 | var result = (from car in context.Cars.Cast() 52 | join brand in context.Brands 53 | on car.BrandId equals brand.Id 54 | join col in context.Colors 55 | on car.ColorId equals col.Id 56 | join carImage in context.CarImages 57 | on car.Id equals carImage.CarId 58 | select new CarDetailDto 59 | { 60 | Id = car.Id, 61 | CarName = car.CarName, 62 | BrandName = brand.Name, 63 | BrandId = brand.Id, 64 | ColorName = col.Name, 65 | ColorId = col.Id, 66 | DailyPrice = car.DailyPrice, 67 | ModelYear = car.ModelYear, 68 | Description = car.Description, 69 | ImagePath = carImage.ImagePath 70 | }).Where(filter).ToList(); 71 | 72 | return result; 73 | } 74 | } 75 | public CarDetailDto GetCarDetail(Expression> filter = null) 76 | { 77 | using (CarContext context = new CarContext()) 78 | { 79 | // CarName, BrandName, ColorName, DailyPrice 80 | var result = (from car in context.Cars.Cast() 81 | join brand in context.Brands 82 | on car.BrandId equals brand.Id 83 | join col in context.Colors 84 | on car.ColorId equals col.Id 85 | join carImage in context.CarImages 86 | on car.Id equals carImage.CarId 87 | select new CarDetailDto 88 | { 89 | Id = car.Id, 90 | CarName = car.CarName, 91 | BrandName = brand.Name, 92 | BrandId = brand.Id, 93 | ColorName = col.Name, 94 | ColorId = col.Id, 95 | DailyPrice = car.DailyPrice, 96 | ModelYear = car.ModelYear, 97 | Description = car.Description, 98 | ImagePath = carImage.ImagePath 99 | }).FirstOrDefault(filter); 100 | 101 | return result; 102 | } 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /.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 --------------------------------------------------------------------------------