├── WebAPI ├── appsettings.json ├── wwwroot │ └── uploads │ │ ├── 32dae69b-5342-481b-b94b-9ba4071abb3bbmw5.jpg │ │ ├── 4d2ac079-87ae-4503-871d-3279ca93c4a6bmw3.jpg │ │ ├── 8a5b12f4-a7ba-4ea4-9af7-222bd6df526dlogo.jpg │ │ ├── ca07543d-fec9-460c-8667-49a205190563bmw1.jpg │ │ ├── ccfb4a1f-0dde-4e3f-8dee-8c498777fadabmw4.jpg │ │ ├── de4f45de-17b9-40d3-a810-c53918d41792bmw2.jpg │ │ └── ea6f4fbf-4c25-4b85-8c3f-a79bedc7af00bmw.jpg ├── appsettings.Development.json ├── Models │ └── CarImage.cs ├── WeatherForecast.cs ├── WebAPI.csproj ├── Properties │ └── launchSettings.json ├── Program.cs ├── Controllers │ ├── WeatherForecastController.cs │ ├── UsersController.cs │ ├── AuthController.cs │ ├── BrandsController.cs │ ├── ColorsController.cs │ ├── CustomersController.cs │ ├── RentalsController.cs │ ├── CarImagesController.cs │ └── CarsController.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 │ │ ├── Result.cs │ │ ├── DataResult.cs │ │ ├── ErrorDataResult.cs │ │ └── SuccessDataResult.cs │ ├── IoC │ │ ├── ICoreModule.cs │ │ └── ServiceTool.cs │ ├── Security │ │ ├── JWT │ │ │ ├── AccessToken.cs │ │ │ ├── ITokenHelper.cs │ │ │ ├── TokenOptions.cs │ │ │ └── JwtHelper.cs │ │ ├── Encryption │ │ │ ├── SecurityKeyHelper.cs │ │ │ └── SigningCredentialsHelper.cs │ │ └── Hashing │ │ │ └── HashingHelper.cs │ ├── Interceptors │ │ ├── MethodInterceptionBaseAttribute.cs │ │ ├── AspectInterceptorSelector.cs │ │ └── MethodInterception.cs │ └── Business │ │ └── BusinessRules.cs ├── Extensions │ ├── ExceptionMiddlewareExtensions.cs │ ├── ErrorDetails.cs │ ├── ServiceCollectionExtensions.cs │ ├── ClaimsPrincipalExtensions.cs │ ├── ClaimExtensions.cs │ └── ExceptionMiddleware.cs ├── DataAccess │ ├── IEntityRepository.cs │ └── EntityFramework │ │ └── EfEntityRepositoryBase.cs ├── CrossCuttingConcerns │ ├── Validation │ │ └── ValidationTool.cs │ └── Caching │ │ ├── ICacheManager.cs │ │ └── Microsoft │ │ └── MemoryCacheManager.cs ├── DependencyResolvers │ └── CoreModule.cs ├── Aspects │ └── Autofac │ │ ├── Caching │ │ ├── CacheRemoveAspect.cs │ │ └── CacheAspect.cs │ │ ├── Transaction │ │ └── TransactionScopeAspect.cs │ │ ├── Performance │ │ └── PerformanceAspect.cs │ │ └── Validation │ │ └── ValidationAspect.cs └── Core.csproj ├── DataAccess ├── Abstract │ ├── IBrandDal.cs │ ├── IColorDal.cs │ ├── ICarImageDal.cs │ ├── ICarDal.cs │ ├── IRentalDal.cs │ ├── ICustomerDal.cs │ └── IUserDal.cs ├── Concrete │ ├── EntityFramework │ │ ├── EfCarImageDal.cs │ │ ├── EfBrandDal.cs │ │ ├── EfColorDal.cs │ │ ├── EfUserDal.cs │ │ ├── RentaCarContext.cs │ │ ├── EfCustomerdal.cs │ │ ├── EfRentalDal.cs │ │ └── EfCarDal.cs │ └── InMemory │ │ └── InMemoryCarDal.cs └── DataAccess.csproj ├── Entities ├── DTOs │ ├── UserForLoginDto.cs │ ├── CustomerDetailDto.cs │ ├── UserForRegisterDto.cs │ ├── RentalCarDetailDto.cs │ └── CarDetailDto.cs ├── Concrete │ ├── CarImage.cs │ ├── Color.cs │ ├── Customer.cs │ ├── Brand.cs │ ├── Rental.cs │ └── Car.cs └── Entities.csproj ├── Business ├── ValidationRules │ └── FluentValidation │ │ ├── CarImageValidator.cs │ │ ├── CustomerValidator.cs │ │ ├── ColorValidator.cs │ │ ├── BrandValidator.cs │ │ ├── RentalValidator.cs │ │ ├── UserValidator.cs │ │ └── CarValidator.cs ├── Abstract │ ├── IColorService.cs │ ├── ICarImageService.cs │ ├── IBrandService.cs │ ├── ICustomerService.cs │ ├── IUserService.cs │ ├── IAuthService.cs │ ├── IRentalService.cs │ └── ICarService.cs ├── Business.csproj ├── BusinessAspects │ └── Autofac │ │ └── SecuredOperation.cs ├── Concrete │ ├── ColorManager.cs │ ├── CustomerManager.cs │ ├── CarManager.cs │ ├── UserManager.cs │ ├── RentalManager.cs │ ├── BrandManager.cs │ ├── AuthManager.cs │ └── CarImageManager.cs ├── DependencyResolvers │ └── Autofac │ │ └── AutofacBusinessModule.cs └── Constants │ └── Messages.cs ├── ConsoleUI ├── ConsoleUI.csproj └── Program.cs ├── .gitattributes ├── README.md ├── ReCapProject.sln └── .gitignore /WebAPI/appsettings.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrknBerk/ReCapProject/HEAD/WebAPI/appsettings.json -------------------------------------------------------------------------------- /Core/Entities/IDto.cs: -------------------------------------------------------------------------------- 1 | namespace Core.Entities 2 | { 3 | public interface IDto 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /WebAPI/wwwroot/uploads/32dae69b-5342-481b-b94b-9ba4071abb3bbmw5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrknBerk/ReCapProject/HEAD/WebAPI/wwwroot/uploads/32dae69b-5342-481b-b94b-9ba4071abb3bbmw5.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/uploads/4d2ac079-87ae-4503-871d-3279ca93c4a6bmw3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrknBerk/ReCapProject/HEAD/WebAPI/wwwroot/uploads/4d2ac079-87ae-4503-871d-3279ca93c4a6bmw3.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/uploads/8a5b12f4-a7ba-4ea4-9af7-222bd6df526dlogo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrknBerk/ReCapProject/HEAD/WebAPI/wwwroot/uploads/8a5b12f4-a7ba-4ea4-9af7-222bd6df526dlogo.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/uploads/ca07543d-fec9-460c-8667-49a205190563bmw1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrknBerk/ReCapProject/HEAD/WebAPI/wwwroot/uploads/ca07543d-fec9-460c-8667-49a205190563bmw1.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/uploads/ccfb4a1f-0dde-4e3f-8dee-8c498777fadabmw4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrknBerk/ReCapProject/HEAD/WebAPI/wwwroot/uploads/ccfb4a1f-0dde-4e3f-8dee-8c498777fadabmw4.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/uploads/de4f45de-17b9-40d3-a810-c53918d41792bmw2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrknBerk/ReCapProject/HEAD/WebAPI/wwwroot/uploads/de4f45de-17b9-40d3-a810-c53918d41792bmw2.jpg -------------------------------------------------------------------------------- /WebAPI/wwwroot/uploads/ea6f4fbf-4c25-4b85-8c3f-a79bedc7af00bmw.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FrknBerk/ReCapProject/HEAD/WebAPI/wwwroot/uploads/ea6f4fbf-4c25-4b85-8c3f-a79bedc7af00bmw.jpg -------------------------------------------------------------------------------- /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 | T Data { get; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Core/Utilities/Results/IResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public interface IResult 8 | { 9 | bool Success { get; } 10 | string Message { get; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Core/Utilities/IoC/ICoreModule.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.IoC 7 | { 8 | public interface ICoreModule 9 | { 10 | void Load(IServiceCollection serviceCollection); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Utilities/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 | -------------------------------------------------------------------------------- /Entities/DTOs/UserForLoginDto.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class UserForLoginDto : IDto 9 | { 10 | public string Email { get; set; } 11 | public string Password { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /WebAPI/Models/CarImage.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace WebAPI.Models 8 | { 9 | public class CarImage 10 | { 11 | public IFormFile Files { get; set; } 12 | public int CarId { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICarDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Abstract 9 | { 10 | public interface ICarDal :IEntityRepository 11 | { 12 | List GetCarDetails(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /WebAPI/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebAPI 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/UserOperationClaim.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities.Concrete 6 | { 7 | public class UserOperationClaim : IEntity 8 | { 9 | public int Id { get; set; } 10 | public int UserId { get; set; } 11 | public int OperationClaimId { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /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);//Token üretecek mekanizmamız 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IRentalDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Abstract 9 | { 10 | public interface IRentalDal :IEntityRepository 11 | { 12 | List GetRentalCarDetails(); 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 GetCustomerDetails(); 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);//join atacam 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Core/Utilities/Results/ErrorResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class ErrorResult : Result 8 | { 9 | public ErrorResult(string message) : base(false, message) 10 | { 11 | 12 | } 13 | public ErrorResult() : base(false) 14 | { 15 | 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Core/Utilities/Results/SuccessResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class SuccessResult :Result 8 | { 9 | public SuccessResult(string message) :base(true,message) 10 | { 11 | 12 | } 13 | public SuccessResult():base(true) 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/TokenOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Security.JWT 6 | { 7 | public class TokenOptions 8 | { 9 | public string Audience { get; set; } 10 | public string Issuer { get; set; } 11 | public int AccessTokenExpiration { get; set; } 12 | public string SecurityKey { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Entities/DTOs/CustomerDetailDto.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 CustomerDetailDto : IDto 9 | { 10 | public string FirstName { get; set; } 11 | public string LastName { get; set; } 12 | public string Email { get; set; } 13 | public string CompanyName { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Entities/DTOs/UserForRegisterDto.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class UserForRegisterDto : IDto 9 | { 10 | public string Email { get; set; } 11 | public string Password { get; set; } 12 | public string FirstName { get; set; } 13 | public string LastName { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Core/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 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/CarImageValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class CarImageValidator : AbstractValidator 10 | { 11 | public CarImageValidator() 12 | { 13 | // RuleFor(c => c.CarId).NotEmpty(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/CustomerValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class CustomerValidator : AbstractValidator 10 | { 11 | public CustomerValidator() 12 | { 13 | RuleFor(c => c.UserId).NotEmpty(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Entities/Concrete/Color.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.ComponentModel.DataAnnotations.Schema; 6 | using System.Text; 7 | 8 | namespace Entities.Concrete 9 | { 10 | public class Color:IEntity 11 | { 12 | public int ColorId { get; set; } 13 | public string ColorName { get; set; } 14 | public bool GetState { get; set; } 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 | -------------------------------------------------------------------------------- /DataAccess/DataAccess.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Business/Abstract/IColorService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.Abstract 8 | { 9 | public interface IColorService 10 | { 11 | IResult Add(Color color); 12 | IResult Update(Color color); 13 | IResult Delete(Color color); 14 | IDataResult> GetAll(); 15 | IDataResult GetById(int colorId); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Entities/DTOs/RentalCarDetailDto.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 RentalCarDetailDto : IDto 9 | { 10 | public string BrandName { get; set; } 11 | public string FirstName { get; set; } 12 | public string LastName { get; set; } 13 | public DateTime RentDate { get; set; } 14 | public DateTime? ReturnDate { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfBrandDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using Microsoft.EntityFrameworkCore; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Linq.Expressions; 9 | using System.Text; 10 | 11 | namespace DataAccess.Concrete.EntityFramework 12 | { 13 | public class EfBrandDal : EfEntityRepositoryBase, IBrandDal 14 | { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/ColorValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class ColorValidator : AbstractValidator 10 | { 11 | public ColorValidator() 12 | { 13 | RuleFor(c => c.ColorName).Length(3, 50).WithMessage("Renk adı max 50 karakter olmalı"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfColorDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using Microsoft.EntityFrameworkCore; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Linq.Expressions; 9 | using System.Text; 10 | 11 | namespace DataAccess.Concrete.EntityFramework 12 | { 13 | public class EfColorDal : EfEntityRepositoryBase, IColorDal 14 | { 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/BrandValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class BrandValidator : AbstractValidator 10 | { 11 | public BrandValidator() 12 | { 13 | RuleFor(b => b.BrandName).Length(2, 50).WithMessage("Maksimum 50 karakter uzunluğunda olmalı"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Encryption/SigningCredentialsHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IdentityModel.Tokens; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Security.Encryption 7 | { 8 | public class SigningCredentialsHelper 9 | { 10 | public static SigningCredentials CreateSigningCredentials(SecurityKey securityKey) 11 | { 12 | return new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha512Signature); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Entities/Concrete/Customer.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.ComponentModel.DataAnnotations.Schema; 6 | using System.Text; 7 | 8 | namespace Entities.Concrete 9 | { 10 | public class Customer :IEntity 11 | { 12 | public int CustomerId { get; set; } 13 | public int UserId { get; set; } 14 | public string CompanyName { get; set; } 15 | public bool GetState { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/MethodInterceptionBaseAttribute.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | 4 | namespace Core.Utilities.Interceptors 5 | { 6 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] 7 | public abstract class MethodInterceptionBaseAttribute : Attribute, IInterceptor 8 | { 9 | public int Priority { get; set; } 10 | 11 | public virtual void Intercept(IInvocation invocation) 12 | { 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /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> GetImageByCarId(int carId); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Core/Utilities/Results/Result.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class Result : IResult 8 | { 9 | public Result(bool success, string message):this(success) 10 | { 11 | Message = message; 12 | } 13 | public Result(bool success) 14 | { 15 | Success = success; 16 | } 17 | public bool Success { get; } 18 | public string Message { get; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities.Concrete 6 | { 7 | public class User : IEntity 8 | { 9 | public int Id { get; set; } 10 | public string FirstName { get; set; } 11 | public string LastName { get; set; } 12 | public string Email { get; set; } 13 | public byte[] PasswordSalt { get; set; } 14 | public byte[] PasswordHash { get; set; } 15 | public bool Status { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /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 | IResult AddTransactionTests(Brand brand); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Core/Utilities/Results/DataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class DataResult : Result,IDataResult 8 | { 9 | public DataResult(T data,bool success,string message):base(success,message) 10 | { 11 | Data = data; 12 | } 13 | public DataResult(T data,bool success):base(success) 14 | { 15 | Data = data; 16 | } 17 | public T Data { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Core/Utilities/IoC/ServiceTool.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.IoC 7 | { 8 | public static class ServiceTool 9 | { 10 | public static IServiceProvider ServiceProvider { get; private set; } 11 | 12 | public static IServiceCollection Create(IServiceCollection services) 13 | { 14 | ServiceProvider = services.BuildServiceProvider(); 15 | return services; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /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 Update(Customer customer); 14 | IResult Delete(Customer customer); 15 | IDataResult> GetAll(); 16 | IDataResult> GetCustomerDetails(); 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 | List GetClaims(User user); 13 | User GetByMail(string email); 14 | IDataResult> GetAll(); 15 | IResult Add(User user); 16 | IResult Update(User user); 17 | IResult Delete(User user); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/RentalValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class RentalValidator :AbstractValidator 10 | { 11 | public RentalValidator() 12 | { 13 | RuleFor(r => r.CarId).NotEmpty(); 14 | RuleFor(r => r.CustomerId).NotEmpty(); 15 | RuleFor(r => r.RentDate).NotEmpty(); 16 | } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Entities/Concrete/Brand.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.ComponentModel.DataAnnotations.Schema; 6 | using System.Text; 7 | 8 | namespace Entities.Concrete 9 | { 10 | public class Brand:IEntity 11 | { 12 | //MODEL ADINDA BİR TABLO OLUŞTURUP BRAND IN MODELLERİ OLACAK CAR TABLOSUNDA MODEL OLACAK 13 | public int BrandId { get; set; } 14 | public string BrandName { get; set; } 15 | public bool GetState { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /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/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 | T GetById(Expression> filter); 12 | List GetAll(Expression> filter=null); 13 | void Add(T entity); 14 | T Get(Expression> filter); 15 | void Update(T entity); 16 | void Delete(T entity); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /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(u => u.FirstName).Length(2, 50); 15 | RuleFor(u => u.LastName).Length(2, 50); 16 | RuleFor(u => u.Email).EmailAddress(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Entities/Concrete/Rental.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.ComponentModel.DataAnnotations.Schema; 6 | using System.Text; 7 | 8 | namespace Entities.Concrete 9 | { 10 | public class Rental : IEntity 11 | { 12 | public int Id { get; set; } 13 | public int CarId { get; set; } 14 | public int CustomerId { get; set; } 15 | public DateTime RentDate { get; set; } 16 | public DateTime? ReturnDate { get; set; } 17 | public bool GetState { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /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 | //CarName-BrandName-ColorName-DailyPrice 11 | public int CarId { get; set; } 12 | public int BrandId { get; set; } 13 | public int ColorId { get; set; } 14 | public string Description { get; set; } 15 | public string BrandName { get; set; } 16 | public string ColorName { get; set; } 17 | public decimal DailyPrice { get; set; } 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 | -------------------------------------------------------------------------------- /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 RentCarId(int carId);//Araç kiralama kontrol 13 | IResult RentAdd(Rental rental);//Araç kiralama 14 | IResult Update(Rental rental); 15 | IResult Delete(Rental rental); 16 | 17 | IDataResult> GetAll(); 18 | IDataResult> GetRentalCarDetails(); 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 | public override string ToString() 14 | { 15 | return JsonConvert.SerializeObject(this); 16 | } 17 | } 18 | 19 | public class ValidationErrorDetails : ErrorDetails 20 | { 21 | public IEnumerable Errors { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Entities/Concrete/Car.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.ComponentModel.DataAnnotations.Schema; 6 | using System.Text; 7 | 8 | namespace Entities.Concrete 9 | { 10 | public class Car:IEntity 11 | { 12 | public int CarId { get; set; } 13 | public int BrandId { get; set; } 14 | public int ColorId { get; set; } 15 | public string ModelYear { get; set; } 16 | public decimal DailyPrice { get; set; } 17 | public string Description { get; set; } 18 | public bool GetState { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /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/CrossCuttingConcerns/Caching/ICacheManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Caching 6 | { 7 | public interface ICacheManager 8 | { 9 | /*duration cache de ne kadar duracak */ 10 | T Get(string key); 11 | object Get(string key);//Generic olmayan kısım yukarıdakini böyle yazabiliriz ama dönüşüm yapmak lazım 12 | void Add(string key, object value, int duration); 13 | bool IsAdd(string key);//veritabanında var mı yoksa ekle 14 | void Remove(string key); 15 | void RemoveByPattern(string pattern);//regex pattern versem 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Core/Utilities/Results/SuccessDataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class SuccessDataResult : DataResult 8 | { 9 | public SuccessDataResult(T data, string message) : base(data, true, message) 10 | { 11 | 12 | } 13 | public SuccessDataResult(T data) : base(data, true) 14 | { 15 | 16 | } 17 | public SuccessDataResult(string message) : base(default, true, message) 18 | { 19 | 20 | } 21 | public SuccessDataResult() : base(default, true) 22 | { 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Core/Extensions/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.IoC; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Core.Extensions 8 | { 9 | public static class ServiceCollectionExtensions 10 | { 11 | public static IServiceCollection AddDependencyResolvers 12 | (this IServiceCollection serviceCollection, ICoreModule[] modules) 13 | { 14 | foreach (var module in modules) 15 | { 16 | module.Load(serviceCollection); 17 | } 18 | 19 | return ServiceTool.Create(serviceCollection); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Business/ValidationRules/FluentValidation/CarValidator.cs: -------------------------------------------------------------------------------- 1 | using Entities.Concrete; 2 | using FluentValidation; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Business.ValidationRules.FluentValidation 8 | { 9 | public class CarValidator : AbstractValidator 10 | { 11 | public CarValidator() 12 | { 13 | RuleFor(c => c.BrandId).NotEmpty(); 14 | RuleFor(c => c.ColorId).NotEmpty(); 15 | RuleFor(c => c.ModelYear).NotEmpty(); 16 | RuleFor(c => c.Description).NotEmpty(); 17 | RuleFor(c => c.DailyPrice).GreaterThanOrEqualTo(0); 18 | RuleFor(c => c.Description).Length(2, 50); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Core/Extensions/ClaimsPrincipalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Claims; 5 | using System.Text; 6 | 7 | namespace Core.Entities.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/DependencyResolvers/CoreModule.cs: -------------------------------------------------------------------------------- 1 | using Core.CrossCuttingConcerns.Caching; 2 | using Core.CrossCuttingConcerns.Caching.Microsoft; 3 | using Core.Utilities.IoC; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | 10 | namespace Core.DependencyResolvers 11 | { 12 | public class CoreModule : ICoreModule 13 | { 14 | public void Load(IServiceCollection serviceCollection) 15 | { 16 | serviceCollection.AddMemoryCache(); 17 | serviceCollection.AddSingleton(); 18 | serviceCollection.AddSingleton(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ConsoleUI/ConsoleUI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | all 11 | runtime; build; native; contentfiles; analyzers; buildtransitive 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /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> GetAll(); 13 | IDataResult> GetCarsByBrandId(int brandId); 14 | IResult AddedCar(Car car); 15 | IResult Update(Car car); 16 | IResult Delete(Car car); 17 | IDataResult> GetCarsByColorId(int colorId); 18 | IDataResult> GetCarDetails(); 19 | 20 | IDataResult> GetListByBrand(int brandId); 21 | IDataResult> GetListByColor(int colorId); 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /WebAPI/WebAPI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Caching/CacheRemoveAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.CrossCuttingConcerns.Caching; 3 | using Core.Utilities.Interceptors; 4 | using Core.Utilities.IoC; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | 10 | namespace Core.Aspects.Autofac.Caching 11 | { 12 | public class CacheRemoveAspect : MethodInterception 13 | { 14 | private string _pattern; 15 | private ICacheManager _cacheManager; 16 | 17 | public CacheRemoveAspect(string pattern) 18 | { 19 | _pattern = pattern; 20 | _cacheManager = ServiceTool.ServiceProvider.GetService(); 21 | } 22 | 23 | protected override void OnSuccess(IInvocation invocation) 24 | { 25 | _cacheManager.RemoveByPattern(_pattern); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/AspectInterceptorSelector.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | 8 | namespace Core.Utilities.Interceptors 9 | { 10 | public class AspectInterceptorSelector : IInterceptorSelector 11 | { 12 | public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) 13 | { 14 | var classAttributes = type.GetCustomAttributes 15 | (true).ToList(); 16 | var methodAttributes = type.GetMethod(method.Name) 17 | .GetCustomAttributes(true); 18 | classAttributes.AddRange(methodAttributes); 19 | 20 | return classAttributes.OrderBy(x => x.Priority).ToArray(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Transaction/TransactionScopeAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.Utilities.Interceptors; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using System.Transactions; 7 | 8 | namespace Core.Aspects.Autofac.Transaction 9 | { 10 | public class TransactionScopeAspect : MethodInterception 11 | { 12 | public override void Intercept(IInvocation invocation) 13 | { 14 | using (TransactionScope transactionScope = new TransactionScope()) 15 | { 16 | try 17 | { 18 | invocation.Proceed(); 19 | transactionScope.Complete(); 20 | } 21 | catch (System.Exception e) 22 | { 23 | transactionScope.Dispose(); 24 | throw; 25 | } 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /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:53144", 8 | "sslPort": 44307 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/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 | 23 | -------------------------------------------------------------------------------- /Core/Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /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.Entities.Extensions 9 | { 10 | public static class ClaimExtensions 11 | { 12 | public static void AddEmail(this ICollection claims, string email) 13 | { 14 | claims.Add(new Claim(JwtRegisteredClaimNames.Email, email)); 15 | } 16 | 17 | public static void AddName(this ICollection claims, string name) 18 | { 19 | claims.Add(new Claim(ClaimTypes.Name, name)); 20 | } 21 | 22 | public static void AddNameIdentifier(this ICollection claims, string nameIdentifier) 23 | { 24 | claims.Add(new Claim(ClaimTypes.NameIdentifier, nameIdentifier)); 25 | } 26 | 27 | public static void AddRoles(this ICollection claims, string[] roles) 28 | { 29 | roles.ToList().ForEach(role => claims.Add(new Claim(ClaimTypes.Role, role))); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfUserDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using 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 RentaCarContext()) 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 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/RentaCarContext.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Entities.Concrete; 3 | using Microsoft.EntityFrameworkCore; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFramework 9 | { 10 | public class RentaCarContext : DbContext 11 | { 12 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 13 | { 14 | optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-6OOMP6V\SQLEXPRESS;Initial Catalog=RentaCar;Integrated Security=True"); 15 | } 16 | 17 | 18 | public DbSet Cars { get; set; } 19 | public DbSet Brands { get; set; } 20 | public DbSet Colors { get; set; } 21 | public DbSet Customers { get; set; } 22 | public DbSet Rentals { get; set; } 23 | public DbSet CarImages { get; set; } 24 | public DbSet OperationClaims { get; set; } 25 | public DbSet Users { get; set; } 26 | public DbSet UserOperationClaims { get; set; } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /WebAPI/Program.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Extensions.DependencyInjection; 3 | using Business.DependencyResolvers.Autofac; 4 | using Microsoft.AspNetCore.Hosting; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.Extensions.Hosting; 7 | using Microsoft.Extensions.Logging; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | using System.Threading.Tasks; 12 | 13 | namespace WebAPI 14 | { 15 | public class Program 16 | { 17 | public static void Main(string[] args) 18 | { 19 | CreateHostBuilder(args).Build().Run(); 20 | } 21 | 22 | public static IHostBuilder CreateHostBuilder(string[] args) => 23 | Host.CreateDefaultBuilder(args) 24 | .UseServiceProviderFactory(new AutofacServiceProviderFactory()) 25 | .ConfigureContainer(builder => { 26 | builder.RegisterModule(new AutofacBusinessModule()); 27 | }) 28 | .ConfigureWebHostDefaults(webBuilder => 29 | { 30 | webBuilder.UseStartup(); 31 | }); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/MethodInterception.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | 4 | namespace Core.Utilities.Interceptors 5 | { 6 | public abstract class MethodInterception : MethodInterceptionBaseAttribute 7 | { 8 | protected virtual void OnBefore(IInvocation invocation) { } 9 | protected virtual void OnAfter(IInvocation invocation) { } 10 | protected virtual void OnException(IInvocation invocation, System.Exception e) { } 11 | protected virtual void OnSuccess(IInvocation invocation) { } 12 | public override void Intercept(IInvocation invocation) 13 | { 14 | var isSuccess = true; 15 | OnBefore(invocation); 16 | try 17 | { 18 | invocation.Proceed(); 19 | } 20 | catch (Exception e) 21 | { 22 | isSuccess = false; 23 | OnException(invocation, e); 24 | throw; 25 | } 26 | finally 27 | { 28 | if (isSuccess) 29 | { 30 | OnSuccess(invocation); 31 | } 32 | } 33 | OnAfter(invocation); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Performance/PerformanceAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.Utilities.Interceptors; 3 | using Core.Utilities.IoC; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Diagnostics; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using System.Text; 9 | 10 | namespace Core.Aspects.Autofac.Performance 11 | { 12 | public class PerformanceAspect : MethodInterception 13 | { 14 | private int _interval; 15 | private Stopwatch _stopwatch; 16 | 17 | public PerformanceAspect(int interval) 18 | { 19 | _interval = interval; 20 | _stopwatch = ServiceTool.ServiceProvider.GetService(); 21 | } 22 | 23 | 24 | protected override void OnBefore(IInvocation invocation) 25 | { 26 | _stopwatch.Start(); 27 | } 28 | 29 | protected override void OnAfter(IInvocation invocation) 30 | { 31 | if (_stopwatch.Elapsed.TotalSeconds > _interval) 32 | { 33 | Debug.WriteLine($"Performance : {invocation.Method.DeclaringType.FullName}.{invocation.Method.Name}-->{_stopwatch.Elapsed.TotalSeconds}"); 34 | } 35 | _stopwatch.Reset(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/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 _validorType; 15 | public ValidationAspect(Type validatorType) 16 | { 17 | if (!typeof(IValidator).IsAssignableFrom(validatorType)) 18 | { 19 | throw new System.Exception("Bu bir validation"); 20 | } 21 | _validorType = validatorType; 22 | } 23 | protected override void OnBefore(IInvocation invocation) 24 | { 25 | var validator = (IValidator)Activator.CreateInstance(_validorType); 26 | var entityType = _validorType.BaseType.GetGenericArguments()[0]; 27 | var entities = invocation.Arguments.Where(t => t.GetType() == entityType); 28 | foreach (var entity in entities) 29 | { 30 | ValidationTool.Validate(validator, entity); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCustomerdal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using Entities.DTOs; 5 | using System.Linq; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | 10 | namespace DataAccess.Concrete.EntityFramework 11 | { 12 | public class EfCustomerdal : EfEntityRepositoryBase, ICustomerDal 13 | { 14 | public List GetCustomerDetails() 15 | { 16 | using (RentaCarContext context = new RentaCarContext()) 17 | { 18 | var result = from customer in context.Customers 19 | join user in context.Users 20 | on customer.UserId equals user.Id 21 | select new CustomerDetailDto 22 | { 23 | CompanyName = customer.CompanyName, 24 | FirstName = user.FirstName, 25 | LastName = user.LastName, 26 | Email = user.Email 27 | }; 28 | return result.ToList(); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /WebAPI/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace WebAPI.Controllers 9 | { 10 | [ApiController] 11 | [Route("[controller]")] 12 | public class WeatherForecastController : ControllerBase 13 | { 14 | private static readonly string[] Summaries = new[] 15 | { 16 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 17 | }; 18 | 19 | private readonly ILogger _logger; 20 | 21 | public WeatherForecastController(ILogger logger) 22 | { 23 | _logger = logger; 24 | } 25 | 26 | [HttpGet] 27 | public IEnumerable Get() 28 | { 29 | var rng = new Random(); 30 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 31 | { 32 | Date = DateTime.Now.AddDays(index), 33 | TemperatureC = rng.Next(-20, 55), 34 | Summary = Summaries[rng.Next(Summaries.Length)] 35 | }) 36 | .ToArray(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Business/BusinessAspects/Autofac/SecuredOperation.cs: -------------------------------------------------------------------------------- 1 | using Business.Constants; 2 | using Castle.DynamicProxy; 3 | using Core.Entities.Extensions; 4 | using Core.Utilities.Interceptors; 5 | using Core.Utilities.IoC; 6 | using Microsoft.AspNetCore.Http; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Text; 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;//metodu çalıştırmaya devam et 34 | } 35 | } 36 | throw new Exception(Messages.AuthorizationDenied); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Hashing/HashingHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Security.Hashing 6 | { 7 | public class HashingHelper 8 | { 9 | public static void CreatePasswordHash(string password, out byte[] passwordHash, out byte[] passwordSalt) 10 | { 11 | using (var hmac = new System.Security.Cryptography.HMACSHA512()) 12 | { 13 | passwordSalt = hmac.Key;//şifreyi çözerken salt ihtiyacımız olacak her kullanıcı için bir key oluşturduk 14 | passwordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(password)); 15 | } 16 | } 17 | public static bool VerifyPasswordHash(string password, byte[] passwordHash, byte[] passwordSalt) 18 | { 19 | //out olmamalı bu değerleri biz vericeğiz 20 | using (var hmac = new System.Security.Cryptography.HMACSHA512(passwordSalt)) 21 | { 22 | var computedHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(password)); 23 | for (int i = 0; i < computedHash.Length; i++) 24 | { 25 | if (computedHash[i] != passwordHash[i]) 26 | { 27 | return false; 28 | } 29 | } 30 | return true; 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Caching/CacheAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.CrossCuttingConcerns.Caching; 3 | using Core.Utilities.Interceptors; 4 | using Core.Utilities.IoC; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Text; 10 | 11 | namespace Core.Aspects.Autofac.Caching 12 | { 13 | public class CacheAspect : MethodInterception 14 | { 15 | private int _duration; 16 | private ICacheManager _cacheManager; 17 | 18 | public CacheAspect(int duration = 60) 19 | { 20 | _duration = duration; 21 | _cacheManager = ServiceTool.ServiceProvider.GetService(); 22 | } 23 | 24 | public override void Intercept(IInvocation invocation) 25 | { 26 | var methodName = string.Format($"{invocation.Method.ReflectedType.FullName}.{invocation.Method.Name}"); 27 | var arguments = invocation.Arguments.ToList(); 28 | var key = $"{methodName}({string.Join(",", arguments.Select(x => x?.ToString() ?? ""))})"; 29 | if (_cacheManager.IsAdd(key)) 30 | { 31 | invocation.ReturnValue = _cacheManager.Get(key); 32 | return; 33 | } 34 | invocation.Proceed(); 35 | _cacheManager.Add(key, invocation.ReturnValue, _duration); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /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.Linq; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | 10 | namespace DataAccess.Concrete.EntityFramework 11 | { 12 | public class EfRentalDal : EfEntityRepositoryBase, IRentalDal 13 | { 14 | public List GetRentalCarDetails() 15 | { 16 | using (RentaCarContext context = new RentaCarContext()) 17 | { 18 | var result = from rental in context.Rentals 19 | join brand in context.Brands 20 | on rental.CarId equals brand.BrandId 21 | join user in context.Users 22 | on rental.CustomerId equals user.Id 23 | select new RentalCarDetailDto 24 | { 25 | BrandName = brand.BrandName, 26 | FirstName = user.FirstName, 27 | LastName = user.LastName, 28 | RentDate = rental.RentDate, 29 | ReturnDate = rental.ReturnDate 30 | }; 31 | return result.ToList(); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFramework/EfCarDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using Entities.DTOs; 5 | using Microsoft.EntityFrameworkCore; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Linq.Expressions; 10 | using System.Text; 11 | 12 | namespace DataAccess.Concrete.EntityFramework 13 | { 14 | public class EfCarDal : EfEntityRepositoryBase, ICarDal 15 | { 16 | public List GetCarDetails() 17 | { 18 | using (RentaCarContext context = new RentaCarContext()) 19 | { 20 | var result = from car in context.Cars 21 | join brand in context.Brands 22 | on car.BrandId equals brand.BrandId 23 | join color in context.Colors 24 | on car.ColorId equals color.ColorId 25 | select new CarDetailDto 26 | { 27 | CarId=car.CarId, 28 | Description = car.Description, 29 | BrandName= brand.BrandName, 30 | DailyPrice =car.DailyPrice, 31 | ColorName =color.ColorName, 32 | BrandId=brand.BrandId, 33 | ColorId=color.ColorId 34 | }; 35 | return result.ToList(); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /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 | 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==true) 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 ==true) 38 | { 39 | return Ok(result); 40 | } 41 | return BadRequest(result); 42 | } 43 | [HttpPost("delete")] 44 | public IActionResult Delete(User user) 45 | { 46 | var result = _userService.Delete(user); 47 | if (result.Success==true) 48 | { 49 | return Ok(result); 50 | } 51 | return BadRequest(result); 52 | } 53 | [HttpPost("update")] 54 | public IActionResult Update(User user) 55 | { 56 | var result = _userService.Update(user); 57 | if (result.Success ==true) 58 | { 59 | return Ok(result); 60 | } 61 | return BadRequest(result); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /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.Data); 36 | } 37 | 38 | return BadRequest(result.Message); 39 | } 40 | 41 | [HttpPost("register")] 42 | public ActionResult Register(UserForRegisterDto userForRegisterDto) 43 | { 44 | var userExists = _authService.UserExists(userForRegisterDto.Email); 45 | if (!userExists.Success) 46 | { 47 | return BadRequest(userExists.Message); 48 | } 49 | 50 | var registerResult = _authService.Register(userForRegisterDto, userForRegisterDto.Password); 51 | var result = _authService.CreateAccessToken(registerResult.Data); 52 | if (result.Success) 53 | { 54 | return Ok(result.Data); 55 | } 56 | 57 | return BadRequest(result.Message); 58 | } 59 | } 60 | } 61 | 62 | -------------------------------------------------------------------------------- /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 | public async Task InvokeAsync(HttpContext httpContext) 22 | { 23 | try 24 | { 25 | await _next(httpContext); 26 | } 27 | catch (Exception e) 28 | { 29 | await HandleExceptionAsync(httpContext, e); 30 | } 31 | } 32 | 33 | private Task HandleExceptionAsync(HttpContext httpContext, Exception e) 34 | { 35 | httpContext.Response.ContentType = "application/json"; 36 | httpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; 37 | 38 | string message = "Internal Server Error"; 39 | IEnumerable errors; 40 | if (e.GetType() == typeof(ValidationException)) 41 | { 42 | message = e.Message; 43 | errors = ((ValidationException)e).Errors; 44 | httpContext.Response.StatusCode = 400; 45 | 46 | return httpContext.Response.WriteAsync(new ValidationErrorDetails 47 | { 48 | StatusCode = 400, 49 | Message = message, 50 | Errors = errors 51 | }.ToString()); 52 | 53 | } 54 | 55 | return httpContext.Response.WriteAsync(new ErrorDetails 56 | { 57 | StatusCode = httpContext.Response.StatusCode, 58 | Message = message 59 | }.ToString()); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /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.Business; 6 | using Core.Utilities.Results; 7 | using DataAccess.Abstract; 8 | using Entities.Concrete; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | 14 | namespace Business.Concrete 15 | { 16 | public class ColorManager : IColorService 17 | { 18 | IColorDal _colorDal; 19 | 20 | public ColorManager(IColorDal colorDal) 21 | { 22 | _colorDal = colorDal; 23 | } 24 | 25 | [ValidationAspect(typeof(ColorValidator))] 26 | public IResult Add(Color color) 27 | { 28 | IResult result= BusinessRules.Run(CheckIfColorNameExists(color.ColorName)); 29 | if(result != null) 30 | { 31 | return result; 32 | } 33 | _colorDal.Add(color); 34 | return new SuccessResult(Messages.ColorAdded); 35 | } 36 | 37 | public IResult Delete(Color color) 38 | { 39 | _colorDal.Delete(color); 40 | return new SuccessResult(Messages.ColorDeleted); 41 | } 42 | 43 | public IDataResult> GetAll() 44 | { 45 | return new SuccessDataResult>(_colorDal.GetAll().FindAll(c => c.GetState ==true)); 46 | } 47 | 48 | public IDataResult GetById(int colorId) 49 | { 50 | return new SuccessDataResult(_colorDal.GetById(c => c.ColorId == colorId)); 51 | } 52 | 53 | public IResult Update(Color color) 54 | { 55 | _colorDal.Update(color); 56 | return new SuccessResult(Messages.ColorUpdated); 57 | } 58 | private IResult CheckIfColorNameExists(string colorName) 59 | { 60 | var result = _colorDal.GetAll(c => c.ColorName == colorName).Any(); 61 | if (result) 62 | { 63 | return new ErrorResult(Messages.ColorNameExists); 64 | } 65 | return new SuccessResult(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /DataAccess/Concrete/InMemory/InMemoryCarDal.cs: -------------------------------------------------------------------------------- 1 | using DataAccess.Abstract; 2 | using Entities.Concrete; 3 | using Entities.DTOs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Linq.Expressions; 8 | using System.Text; 9 | 10 | namespace DataAccess.Concrete.InMemory 11 | { 12 | public class InMemoryCarDal : ICarDal 13 | { 14 | List _cars; 15 | public InMemoryCarDal() 16 | { 17 | _cars = new List 18 | { 19 | new Car 20 | { 21 | CarId=1, 22 | BrandId=1, 23 | ColorId=1, 24 | ModelYear="2018", 25 | DailyPrice=100, 26 | Description="Kiralık", 27 | } 28 | }; 29 | } 30 | 31 | public void Add(Car car) 32 | { 33 | _cars.Add(car); 34 | } 35 | 36 | public void Delete(Car car) 37 | { 38 | Car carToDelete = _cars.SingleOrDefault(c => c.CarId == car.CarId); 39 | _cars.Remove(carToDelete); 40 | } 41 | 42 | public Car Get(Expression> filter) 43 | { 44 | throw new NotImplementedException(); 45 | } 46 | 47 | public List GetAll() 48 | { 49 | return _cars; 50 | } 51 | 52 | public List GetAll(Expression> filter = null) 53 | { 54 | throw new NotImplementedException(); 55 | } 56 | 57 | public Car GetById(Expression> filter) 58 | { 59 | throw new NotImplementedException(); 60 | } 61 | 62 | public List GetCarDetails() 63 | { 64 | throw new NotImplementedException(); 65 | } 66 | 67 | public void Update(Car car) 68 | { 69 | Car carToUpdate = _cars.SingleOrDefault(c => c.CarId == car.CarId); 70 | carToUpdate.BrandId = car.BrandId; 71 | carToUpdate.ColorId = car.ColorId; 72 | carToUpdate.ModelYear = car.ModelYear; 73 | carToUpdate.DailyPrice = car.DailyPrice; 74 | carToUpdate.Description = car.Description; 75 | 76 | 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /WebAPI/Controllers/BrandsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class BrandsController : ControllerBase 15 | { 16 | IBrandService _brandService; 17 | public BrandsController(IBrandService brandService) 18 | { 19 | _brandService = brandService; 20 | } 21 | 22 | [HttpGet("getall")] 23 | public IActionResult GetAll() 24 | { 25 | var result = _brandService.GetAll(); 26 | if(result.Success == true) 27 | { 28 | return Ok(result); 29 | } 30 | return BadRequest(result); 31 | } 32 | [HttpGet("getbyid")] 33 | public IActionResult GetById(int brandId) 34 | { 35 | var result = _brandService.GetById(brandId); 36 | if(result.Success == true) 37 | { 38 | return Ok(result); 39 | } 40 | return BadRequest(result); 41 | } 42 | 43 | [HttpPost("add")] 44 | public IActionResult Add(Brand brand) 45 | { 46 | var result = _brandService.Add(brand); 47 | if (result.Success == true) 48 | { 49 | return Ok(result); 50 | } 51 | return BadRequest(result); 52 | } 53 | 54 | [HttpPost("update")] 55 | public IActionResult Update(Brand brand) 56 | { 57 | var result = _brandService.Update(brand); 58 | if (result.Success == true) 59 | { 60 | return Ok(result); 61 | } 62 | return BadRequest(result); 63 | } 64 | 65 | [HttpPost("delete")] 66 | public IActionResult Delete(Brand brand) 67 | { 68 | var result = _brandService.Delete(brand); 69 | if (result.Success ==true) 70 | { 71 | return Ok(result); 72 | } 73 | return BadRequest(result); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /WebAPI/Controllers/ColorsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class ColorsController : ControllerBase 15 | { 16 | IColorService _colorService; 17 | 18 | public ColorsController(IColorService colorService) 19 | { 20 | _colorService = colorService; 21 | } 22 | 23 | [HttpGet("getall")] 24 | public IActionResult GetAll() 25 | { 26 | var result = _colorService.GetAll(); 27 | if (result.Success==true) 28 | { 29 | return Ok(result); 30 | } 31 | return BadRequest(result); 32 | } 33 | 34 | [HttpGet("getbyid")] 35 | public IActionResult GetById(int colorId) 36 | { 37 | var result = _colorService.GetById(colorId); 38 | if (result.Success==true) 39 | { 40 | return Ok(result); 41 | } 42 | return BadRequest(result); 43 | } 44 | 45 | [HttpPost("add")] 46 | public IActionResult Add(Color color) 47 | { 48 | var result = _colorService.Add(color); 49 | if (result.Success ==true) 50 | { 51 | return Ok(result); 52 | } 53 | return BadRequest(result); 54 | } 55 | 56 | 57 | [HttpPost("delete")] 58 | public IActionResult Delete(Color color) 59 | { 60 | var result = _colorService.Delete(color); 61 | if (result.Success ==true) 62 | { 63 | return Ok(result); 64 | } 65 | return BadRequest(result); 66 | } 67 | [HttpPost("update")] 68 | public IActionResult Update(Color color) 69 | { 70 | var result = _colorService.Update(color); 71 | if (result.Success ==true) 72 | { 73 | return Ok(result); 74 | } 75 | return BadRequest(result); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /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(); 21 | builder.RegisterType().As().SingleInstance(); 22 | 23 | builder.RegisterType().As(); 24 | builder.RegisterType().As().SingleInstance(); 25 | 26 | builder.RegisterType().As(); 27 | builder.RegisterType().As().SingleInstance(); 28 | 29 | builder.RegisterType().As(); 30 | builder.RegisterType().As().SingleInstance(); 31 | 32 | builder.RegisterType().As(); 33 | builder.RegisterType().As().SingleInstance(); 34 | 35 | builder.RegisterType().As(); 36 | builder.RegisterType().As().SingleInstance(); 37 | 38 | builder.RegisterType().As(); 39 | builder.RegisterType().As().SingleInstance(); 40 | 41 | builder.RegisterType().As(); 42 | builder.RegisterType().As(); 43 | 44 | var assembly = System.Reflection.Assembly.GetExecutingAssembly(); 45 | 46 | builder.RegisterAssemblyTypes(assembly).AsImplementedInterfaces() 47 | .EnableInterfaceInterceptors(new ProxyGenerationOptions() 48 | { 49 | Selector = new AspectInterceptorSelector() 50 | }).SingleInstance(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CustomersController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class CustomersController : ControllerBase 15 | { 16 | ICustomerService _customerService; 17 | public CustomersController(ICustomerService customerService) 18 | { 19 | _customerService = customerService; 20 | } 21 | [HttpGet("getall")] 22 | public IActionResult GetAll() 23 | { 24 | var result = _customerService.GetAll(); 25 | if (result.Success==true) 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==true) 36 | { 37 | return Ok(result); 38 | } 39 | return BadRequest(result); 40 | } 41 | [HttpPost("delete")] 42 | public IActionResult Delete(Customer customer) 43 | { 44 | var result = _customerService.Delete(customer); 45 | if (result.Success==true) 46 | { 47 | return Ok(result); 48 | } 49 | return BadRequest(result); 50 | } 51 | [HttpPost("update")] 52 | public IActionResult Update(Customer customer) 53 | { 54 | var result = _customerService.Update(customer); 55 | if (result.Success==true) 56 | { 57 | return Ok(result); 58 | } 59 | return BadRequest(result); 60 | } 61 | [HttpGet("getcustomerdetails")] 62 | public IActionResult GetCustomerDetails() 63 | { 64 | var result = _customerService.GetCustomerDetails(); 65 | if (result.Success ==true) 66 | { 67 | return Ok(result); 68 | } 69 | return BadRequest(result); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /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 | 26 | public void Delete(TEntity entity) 27 | { 28 | using (TContext context = new TContext()) 29 | { 30 | var deletedEntity = context.Entry(entity); 31 | deletedEntity.State = EntityState.Deleted; 32 | context.SaveChanges(); 33 | } 34 | } 35 | 36 | public List GetAll(Expression> filter = null) 37 | { 38 | using (TContext context = new TContext()) 39 | { 40 | return filter == null ? context.Set().ToList() : context.Set().Where(filter).ToList(); 41 | } 42 | } 43 | public TEntity Get(Expression> filter) 44 | { 45 | using (TContext context = new TContext()) 46 | { 47 | return context.Set().SingleOrDefault(filter); 48 | } 49 | } 50 | public TEntity GetById(Expression> filter) 51 | { 52 | using (TContext context = new TContext()) 53 | { 54 | return context.Set().SingleOrDefault(filter); 55 | } 56 | } 57 | 58 | public void Update(TEntity entity) 59 | { 60 | using (TContext context = new TContext()) 61 | { 62 | var updatedEntity = context.Entry(entity); 63 | updatedEntity.State = EntityState.Modified; 64 | context.SaveChanges(); 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /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.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 CustomerManager : ICustomerService 18 | { 19 | ICustomerDal _customerDal; 20 | public CustomerManager(ICustomerDal customerDal) 21 | { 22 | _customerDal = customerDal; 23 | } 24 | 25 | [ValidationAspect(typeof(CustomerValidator))] 26 | public IResult Add(Customer customer) 27 | { 28 | IResult result= BusinessRules.Run(CheckIfCompanyNameExists(customer.CompanyName)); 29 | if (result != null) 30 | { 31 | return result; 32 | } 33 | _customerDal.Add(customer); 34 | return new SuccessResult(Messages.CustomerAdded); 35 | } 36 | 37 | public IResult Delete(Customer customer) 38 | { 39 | _customerDal.Delete(customer); 40 | return new SuccessResult(Messages.CustomerDeleted); 41 | } 42 | 43 | public IDataResult> GetAll() 44 | { 45 | return new SuccessDataResult>(_customerDal.GetAll().FindAll(c => c.GetState==true), Messages.CustomerListed); 46 | } 47 | 48 | public IDataResult> GetCustomerDetails() 49 | { 50 | return new SuccessDataResult>(_customerDal.GetCustomerDetails()); 51 | } 52 | 53 | [ValidationAspect(typeof(CustomerValidator))] 54 | public IResult Update(Customer customer) 55 | { 56 | _customerDal.Update(customer); 57 | return new SuccessResult(Messages.CustomerUpdated); 58 | } 59 | private IResult CheckIfCompanyNameExists(string companyName) 60 | { 61 | var result = _customerDal.GetAll(c => c.CompanyName == companyName).Any(); 62 | if (result) 63 | { 64 | return new ErrorResult(Messages.CompanyNameExists); 65 | } 66 | return new SuccessResult(); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Business/Concrete/CarManager.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.Linq; 12 | using System.Text; 13 | 14 | namespace Business.Concrete 15 | { 16 | public class CarManager : ICarService 17 | { 18 | ICarDal _carDal; 19 | public CarManager(ICarDal carDal)//Constructor tanımlamadığımız zaman _carDal add,delete ulaşamyız 20 | { 21 | _carDal = carDal; 22 | } 23 | 24 | [ValidationAspect(typeof(CarValidator))] 25 | public IResult AddedCar(Car car) 26 | { 27 | _carDal.Add(car); 28 | return new SuccessResult(Messages.CarAdded); 29 | 30 | } 31 | 32 | public IResult Delete(Car car) 33 | { 34 | _carDal.Delete(car); 35 | return new SuccessResult(Messages.CarDeleted); 36 | } 37 | 38 | public IDataResult> GetAll() 39 | { 40 | return new SuccessDataResult>(_carDal.GetAll().FindAll(c => c.GetState == true), Messages.CarList); 41 | } 42 | 43 | public IDataResult> GetCarDetails() 44 | { 45 | return new SuccessDataResult>(_carDal.GetCarDetails()); 46 | } 47 | 48 | public IDataResult> GetCarsByBrandId(int brandId) 49 | { 50 | return new SuccessDataResult>(_carDal.GetAll(c => c.BrandId == brandId)); 51 | } 52 | 53 | public IDataResult> GetCarsByColorId(int colorId) 54 | { 55 | return new SuccessDataResult>(_carDal.GetAll(c => c.ColorId == colorId)); 56 | } 57 | 58 | public IDataResult> GetListByBrand(int brandId) 59 | { 60 | return new SuccessDataResult>(_carDal.GetAll(b => b.BrandId == brandId).ToList()); 61 | } 62 | 63 | public IDataResult> GetListByColor(int colorId) 64 | { 65 | return new SuccessDataResult>(_carDal.GetAll(c => c.ColorId == colorId).ToList()); 66 | } 67 | 68 | public IResult Update(Car car) 69 | { 70 | _carDal.Update(car); 71 | return new SuccessResult(Messages.CarUpdated); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /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.Business; 7 | using Core.Utilities.Results; 8 | using DataAccess.Abstract; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Linq.Expressions; 13 | using System.Text; 14 | 15 | namespace Business.Concrete 16 | { 17 | public class UserManager : IUserService 18 | { 19 | IUserDal _userDal; 20 | 21 | public UserManager(IUserDal userDal) 22 | { 23 | _userDal = userDal; 24 | } 25 | 26 | [ValidationAspect(typeof(UserValidator))] 27 | public IResult Add(User user) 28 | { 29 | //var users = _userDal.GetAll(usr => usr.Email == user.Email); 30 | //if (users.Count > 0) 31 | //{ 32 | // return new ErrorResult(Messages.UserAddedError); 33 | //} 34 | 35 | IResult result= BusinessRules.Run(CheckIfEmailExists(user.Email)); 36 | 37 | if (result != null) 38 | { 39 | return result; 40 | } 41 | 42 | _userDal.Add(user); 43 | return new SuccessResult(Messages.UserAdded); 44 | } 45 | 46 | public IResult Delete(User user) 47 | { 48 | _userDal.Delete(user); 49 | return new SuccessResult(Messages.UserDeleted); 50 | } 51 | 52 | public IDataResult> GetAll() 53 | { 54 | return new SuccessDataResult>(_userDal.GetAll(),Messages.UserListed); 55 | } 56 | 57 | public User GetByMail(string email) 58 | { 59 | return _userDal.Get(u => u.Email == email); 60 | } 61 | 62 | public List GetClaims(User user) 63 | { 64 | return _userDal.GetClaims(user); 65 | } 66 | 67 | [ValidationAspect(typeof(UserValidator))] 68 | public IResult Update(User user) 69 | { 70 | _userDal.Update(user); 71 | return new SuccessResult(Messages.UserUpdated); 72 | } 73 | 74 | private IResult CheckIfEmailExists(string email) 75 | { 76 | var result = _userDal.GetAll(u => u.Email == email).Any(); 77 | if (result) 78 | { 79 | return new ErrorResult(Messages.UserAddedError); 80 | } 81 | return new SuccessResult(); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /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.Results; 6 | using DataAccess.Abstract; 7 | using Entities.Concrete; 8 | using Entities.DTOs; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | 14 | namespace Business.Concrete 15 | { 16 | // Mesela Rental tablosuna ekleme yapmadan önde Eklenecek Car Id nin car tablosunda olup olmadığını 17 | //yada rent işlemini yapacak Customer ID nin tabloda var olup olmadığını kontrol edip ekleme işlemi yapabilirsiniz eğer sorunuzu yanlış anlamadıysam 18 | public class RentalManager : IRentalService 19 | { 20 | IRentalDal _rentalDal; 21 | 22 | public RentalManager(IRentalDal rentalDal) 23 | { 24 | _rentalDal = rentalDal; 25 | } 26 | 27 | public IResult RentCarId(int carId) 28 | { 29 | //var result = _rentalDal.GetById(r => r.CarId == carId && r.ReturnDate == null); 30 | var result = _rentalDal.GetById(r => r.CarId == carId); 31 | if (result.ReturnDate != null) 32 | { 33 | //return new ErrorResult(Messages.RentalDate); 34 | return new ErrorResult(Messages.RentalSuccesAdded); 35 | } 36 | else 37 | { 38 | //return new ErrorResult(Messages.RentalSuccesAdded); 39 | return new ErrorResult(Messages.RentalDate); 40 | } 41 | } 42 | 43 | 44 | public IResult Delete(Rental rental) 45 | { 46 | _rentalDal.Delete(rental); 47 | return new SuccessResult(Messages.RentalDeleted); 48 | } 49 | 50 | public IDataResult> GetAll() 51 | { 52 | return new SuccessDataResult>(_rentalDal.GetAll(), Messages.RentalListed); 53 | } 54 | 55 | [ValidationAspect(typeof(RentalValidator))] 56 | public IResult RentAdd(Rental rental) 57 | { 58 | _rentalDal.Add(rental); 59 | return new SuccessResult(Messages.RentalAdded); 60 | } 61 | 62 | public IResult Update(Rental rental) 63 | { 64 | _rentalDal.Update(rental); 65 | return new SuccessResult(Messages.RentalUpdated); 66 | } 67 | 68 | public IDataResult> GetRentalCarDetails() 69 | { 70 | return new SuccessDataResult>(_rentalDal.GetRentalCarDetails()); 71 | } 72 | 73 | 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /WebAPI/Controllers/RentalsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class RentalsController : ControllerBase 15 | { 16 | IRentalService _rentalService; 17 | public RentalsController(IRentalService rentalService) 18 | { 19 | _rentalService = rentalService; 20 | } 21 | [HttpGet("getall")] 22 | public IActionResult GetAll() 23 | { 24 | var result = _rentalService.GetAll(); 25 | if (result.Success == true) 26 | { 27 | return Ok(result); 28 | } 29 | return BadRequest(result); 30 | } 31 | [HttpGet("rentcarid")] 32 | public IActionResult RentCarId(int carId) 33 | { 34 | var result = _rentalService.RentCarId(carId); 35 | if (result.Success == true) 36 | { 37 | return Ok(result); 38 | } 39 | return BadRequest(result); 40 | } 41 | 42 | [HttpPost("add")] 43 | public IActionResult Add(Rental rental) 44 | { 45 | var result = _rentalService.RentAdd(rental); 46 | if (result.Success == true) 47 | { 48 | return Ok(result); 49 | } 50 | return BadRequest(result); 51 | } 52 | [HttpPost("delete")] 53 | public IActionResult Delete(Rental rental) 54 | { 55 | var result = _rentalService.Delete(rental); 56 | if (result.Success == true) 57 | { 58 | return Ok(result); 59 | } 60 | return BadRequest(result); 61 | } 62 | [HttpPost("update")] 63 | public IActionResult Update(Rental rental) 64 | { 65 | var result = _rentalService.Update(rental); 66 | if (result.Success == true) 67 | { 68 | return Ok(result); 69 | } 70 | return BadRequest(result); 71 | } 72 | 73 | [HttpGet("getrentalcardetails")] 74 | public IActionResult GetRentalCarDetails() 75 | { 76 | var result = _rentalService.GetRentalCarDetails(); 77 | if (result.Success == true) 78 | { 79 | return Ok(result); 80 | } 81 | return BadRequest(result); 82 | } 83 | 84 | 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Caching/Microsoft/MemoryCacheManager.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.IoC; 2 | using Microsoft.Extensions.Caching.Memory; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Text.RegularExpressions; 9 | 10 | namespace Core.CrossCuttingConcerns.Caching.Microsoft 11 | { 12 | public class MemoryCacheManager : ICacheManager 13 | { 14 | //Adapter Pattern 15 | IMemoryCache _memoryCache; 16 | public MemoryCacheManager() 17 | { 18 | _memoryCache = ServiceTool.ServiceProvider.GetService(); 19 | } 20 | public void Add(string key, object value, int duration) 21 | { 22 | _memoryCache.Set(key, value, TimeSpan.FromMinutes(duration)); 23 | } 24 | 25 | public T Get(string key) 26 | { 27 | return _memoryCache.Get(key); 28 | } 29 | 30 | public object Get(string key) 31 | { 32 | return _memoryCache.Get(key); 33 | } 34 | 35 | public bool IsAdd(string key) 36 | { 37 | return _memoryCache.TryGetValue(key, out _); 38 | //out _ --> bu kullanım bir şey döndürme demek istiyoruz sadece key istiyorum sen bana cache deki değeri verme 39 | } 40 | 41 | public void Remove(string key) 42 | { 43 | _memoryCache.Remove(key); 44 | } 45 | 46 | public void RemoveByPattern(string pattern) 47 | { 48 | //Çalışma anında bellekten silmeye yarıyor 49 | var cacheEntriesCollectionDefinition = typeof(MemoryCache).GetProperty("EntriesCollection", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); 50 | var cacheEntriesCollection = cacheEntriesCollectionDefinition.GetValue(_memoryCache) as dynamic; 51 | List cacheCollectionValues = new List(); 52 | 53 | foreach (var cacheItem in cacheEntriesCollection) 54 | { 55 | ICacheEntry cacheItemValue = cacheItem.GetType().GetProperty("Value").GetValue(cacheItem, null); 56 | cacheCollectionValues.Add(cacheItemValue); 57 | } 58 | 59 | var regex = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase);//pattern bu şekilde oluşturuyoruz 60 | var keysToRemove = cacheCollectionValues.Where(d => regex.IsMatch(d.Key.ToString())).Select(d => d.Key).ToList(); 61 | 62 | foreach (var key in keysToRemove) 63 | { 64 | _memoryCache.Remove(key); 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /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.IO; 9 | using System.Linq; 10 | using System.Threading.Tasks; 11 | using WebAPI.Models; 12 | 13 | namespace WebAPI.Controllers 14 | { 15 | [Route("api/[controller]")] 16 | [ApiController] 17 | public class CarImagesController : ControllerBase 18 | { 19 | public static IWebHostEnvironment _webHostEnvironment; 20 | ICarImageService _carImageService; 21 | public CarImagesController(ICarImageService carImageService, IWebHostEnvironment webHostEnvironment) 22 | { 23 | _carImageService = carImageService; 24 | _webHostEnvironment = webHostEnvironment; 25 | } 26 | 27 | [HttpPost("add")] 28 | public IActionResult Add([FromForm] Models.CarImage objectFile, [FromForm] Entities.Concrete.CarImage carImage) 29 | { 30 | 31 | if (objectFile == null) 32 | { 33 | 34 | } 35 | string path = _webHostEnvironment.WebRootPath + "\\uploads\\"; 36 | if (!Directory.Exists(path)) 37 | { 38 | Directory.CreateDirectory(path); 39 | } 40 | using (FileStream fileStream = System.IO.File.Create(path + Guid.NewGuid().ToString("D") + objectFile.Files.FileName)) 41 | { 42 | objectFile.Files.CopyTo(fileStream); 43 | fileStream.Flush(); 44 | 45 | } 46 | var result = _carImageService.Add(new Entities.Concrete.CarImage 47 | { 48 | CarId = carImage.CarId, 49 | ImagePath = path + Guid.NewGuid().ToString("D") + objectFile.Files.FileName, 50 | Date = DateTime.Now 51 | }); 52 | if (result.Success == true) 53 | { 54 | return Ok(result); 55 | } 56 | return BadRequest(result); 57 | } 58 | [HttpGet("getall")] 59 | public IActionResult GetAll() 60 | { 61 | var result = _carImageService.GetAll(); 62 | if (result.Success ==true) 63 | { 64 | return Ok(result); 65 | } 66 | return BadRequest(result); 67 | } 68 | [HttpGet("getcarıd")] 69 | public IActionResult GetCarId(int carId) 70 | { 71 | var result = _carImageService.GetImageByCarId(carId); 72 | if (result.Success ==true) 73 | { 74 | return Ok(result.Data); 75 | } 76 | return BadRequest(result); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /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.Caching; 6 | using Core.Aspects.Autofac.Performance; 7 | using Core.Aspects.Autofac.Transaction; 8 | using Core.Aspects.Autofac.Validation; 9 | using Core.Utilities.Business; 10 | using Core.Utilities.Results; 11 | using DataAccess.Abstract; 12 | using Entities.Concrete; 13 | using System; 14 | using System.Collections.Generic; 15 | using System.Linq; 16 | using System.Text; 17 | 18 | namespace Business.Concrete 19 | { 20 | public class BrandManager : IBrandService 21 | { 22 | IBrandDal _brandDal; 23 | 24 | public BrandManager(IBrandDal brandDal) 25 | { 26 | _brandDal = brandDal; 27 | } 28 | 29 | //[SecuredOperation("brand.add,admin")] 30 | [ValidationAspect(typeof(BrandValidator))] 31 | public IResult Add(Brand brand) 32 | { 33 | IResult result= BusinessRules.Run(CheckIfBrandNameExists(brand.BrandName)); 34 | if(result != null) 35 | { 36 | return result; 37 | } 38 | _brandDal.Add(brand); 39 | return new SuccessResult(Messages.BrandAdded); 40 | } 41 | 42 | [TransactionScopeAspect] 43 | public IResult AddTransactionTests(Brand brand) 44 | { 45 | _brandDal.Add(brand); 46 | _brandDal.Update(brand); 47 | return new SuccessResult(Messages.BrandUpdate); 48 | } 49 | 50 | public IResult Delete(Brand brand) 51 | { 52 | _brandDal.Delete(brand); 53 | return new SuccessResult(Messages.BrandDeleted); 54 | } 55 | 56 | //[PerformanceAspect(5)] 57 | //[CacheAspect] 58 | public IDataResult> GetAll() 59 | { 60 | return new SuccessDataResult>(_brandDal.GetAll().FindAll(b => b.GetState==true)); 61 | } 62 | 63 | public IDataResult GetById(int brandId) 64 | { 65 | return new SuccessDataResult(_brandDal.GetById(c => c.BrandId == brandId)); 66 | } 67 | 68 | [ValidationAspect(typeof(BrandValidator))] 69 | public IResult Update(Brand brand) 70 | { 71 | _brandDal.Update(brand); 72 | return new SuccessResult(Messages.BrandUpdate); 73 | } 74 | private IResult CheckIfBrandNameExists(string brandName) 75 | { 76 | var result = _brandDal.GetAll(b => b.BrandName == brandName).Any(); 77 | if (result) 78 | { 79 | return new ErrorResult(Messages.BrandAddedError); 80 | } 81 | return new SuccessResult(); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /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 | private IUserService _userService; 17 | private ITokenHelper _tokenHelper; 18 | 19 | public AuthManager(IUserService userService, ITokenHelper tokenHelper) 20 | { 21 | _userService = userService; 22 | _tokenHelper = tokenHelper; 23 | } 24 | 25 | public IDataResult Register(UserForRegisterDto userForRegisterDto, string password) 26 | { 27 | byte[] passwordHash, passwordSalt; 28 | HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt); 29 | var user = new User 30 | { 31 | Email = userForRegisterDto.Email, 32 | FirstName = userForRegisterDto.FirstName, 33 | LastName = userForRegisterDto.LastName, 34 | PasswordHash = passwordHash, 35 | PasswordSalt = passwordSalt, 36 | Status = true 37 | }; 38 | _userService.Add(user); 39 | return new SuccessDataResult(user, Messages.UserRegistered); 40 | } 41 | 42 | public IDataResult Login(UserForLoginDto userForLoginDto) 43 | { 44 | var userToCheck = _userService.GetByMail(userForLoginDto.Email); 45 | if (userToCheck == null) 46 | { 47 | return new ErrorDataResult(Messages.UserNotFound); 48 | } 49 | 50 | if (!HashingHelper.VerifyPasswordHash(userForLoginDto.Password, userToCheck.PasswordHash, userToCheck.PasswordSalt)) 51 | { 52 | return new ErrorDataResult(Messages.PasswordError); 53 | } 54 | 55 | return new SuccessDataResult(userToCheck, Messages.SuccessfulLogin); 56 | } 57 | 58 | public IResult UserExists(string email) 59 | { 60 | if (_userService.GetByMail(email) != null) 61 | { 62 | return new ErrorResult(Messages.UserAlreadyExists); 63 | } 64 | return new SuccessResult(); 65 | } 66 | 67 | public IDataResult CreateAccessToken(User user) 68 | { 69 | var claims = _userService.GetClaims(user); 70 | var accessToken = _tokenHelper.CreateToken(user, claims); 71 | return new SuccessDataResult(accessToken, Messages.AccessTokenCreated); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Core/Utilities/Security/JWT/JwtHelper.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Core.Entities.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 | /*Configuration --> appsetting.json gider */ 25 | 26 | } 27 | public AccessToken CreateToken(User user, List operationClaims) 28 | { 29 | _accessTokenExpiration = DateTime.Now.AddMinutes(_tokenOptions.AccessTokenExpiration); 30 | var securityKey = SecurityKeyHelper.CreateSecurityKey(_tokenOptions.SecurityKey); 31 | var signingCredentials = SigningCredentialsHelper.CreateSigningCredentials(securityKey); 32 | var jwt = CreateJwtSecurityToken(_tokenOptions, user, signingCredentials, operationClaims); 33 | var jwtSecurityTokenHandler = new JwtSecurityTokenHandler(); 34 | var token = jwtSecurityTokenHandler.WriteToken(jwt); 35 | 36 | return new AccessToken 37 | { 38 | Token = token, 39 | Expiration = _accessTokenExpiration 40 | }; 41 | 42 | } 43 | 44 | public JwtSecurityToken CreateJwtSecurityToken(TokenOptions tokenOptions, User user, 45 | SigningCredentials signingCredentials, List operationClaims) 46 | { 47 | var jwt = new JwtSecurityToken( 48 | issuer: tokenOptions.Issuer, 49 | audience: tokenOptions.Audience, 50 | expires: _accessTokenExpiration, 51 | notBefore: DateTime.Now, 52 | claims: SetClaims(user, operationClaims), 53 | signingCredentials: signingCredentials 54 | ); 55 | return jwt; 56 | } 57 | 58 | private IEnumerable SetClaims(User user, List operationClaims) 59 | { 60 | var claims = new List(); 61 | claims.AddNameIdentifier(user.Id.ToString()); 62 | claims.AddEmail(user.Email); 63 | claims.AddName($"{user.FirstName} {user.LastName}"); 64 | claims.AddRoles(operationClaims.Select(c => c.Name).ToArray()); 65 | 66 | return claims; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /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.Text; 10 | 11 | namespace Business.Concrete 12 | { 13 | public class CarImageManager : ICarImageService 14 | { 15 | ICarImageDal _carImageDal; 16 | public CarImageManager(ICarImageDal carImageDal) 17 | { 18 | _carImageDal = carImageDal; 19 | } 20 | 21 | public IResult Add(CarImage carImage) 22 | { 23 | IResult result = BusinessRules.Run(CheckIfCarImageLimited(carImage.CarId)); 24 | if (result != null) 25 | { 26 | return result; 27 | } 28 | _carImageDal.Add(carImage); 29 | return new SuccessResult(Messages.CarImageAdded); 30 | } 31 | 32 | public IResult Update(CarImage carImage) 33 | { 34 | throw new NotImplementedException(); 35 | } 36 | 37 | public IResult Delete(CarImage carImage) 38 | { 39 | throw new NotImplementedException(); 40 | } 41 | 42 | public IDataResult> GetAll() 43 | { 44 | return new SuccessDataResult>(_carImageDal.GetAll(), Messages.CarImageList); 45 | } 46 | 47 | public IDataResult> GetImageByCarId(int carId) 48 | { 49 | //IResult result = BusinessRules.Run(CheckIfCarIdImageExists(carId)); 50 | //if (result != null) 51 | //{ 52 | // return null; 53 | //} 54 | CheckIfCarIdImageExists(carId); 55 | return new SuccessDataResult>(_carImageDal.GetAll(c => c.CarId == carId)); 56 | } 57 | 58 | 59 | private IResult CheckIfCarImageLimited(int carId) 60 | { 61 | var result = _carImageDal.GetAll(c => c.CarId == carId).Count; 62 | if(result >= 5) 63 | { 64 | return new ErrorResult(Messages.CarImageLimited); 65 | } 66 | return new SuccessResult(); 67 | } 68 | 69 | 70 | private IResult CheckIfCarIdImageExists(int carId) 71 | { 72 | var path = AppDomain.CurrentDomain.BaseDirectory + "C:\\Users\\FurkanBerk\\source\repos\\ReCapProject\\WebAPI\\wwwroot\\uploads\\8a5b12f4-a7ba-4ea4-9af7-222bd6df526dlogo.jpg"; 73 | var result = _carImageDal.GetAll(c => c.CarId == carId).Count; 74 | if (result == 0) 75 | { 76 | return new SuccessDataResult>(new List { new CarImage { ImagePath=path } }); 77 | } 78 | return new SuccessDataResult>(_carImageDal.GetAll(c => c.CarId == carId)); 79 | 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Business/Constants/Messages.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Business.Constants 6 | { 7 | public static class Messages 8 | { 9 | public static string CarAdded = "Araba eklendi"; 10 | public static string CarDeleted = "Araba silindi"; 11 | public static string CarUpdated = "Araba güncellendi"; 12 | 13 | public static string ColorAdded = "Renk eklendi"; 14 | public static string ColorDeleted = "Renk silindi"; 15 | public static string ColorUpdated = "Renk güncellendi"; 16 | public static string ColorList = "Renkler"; 17 | public static string ColorNameExists = "Aynı isim renk vardır"; 18 | 19 | public static string BrandAdded = "Marka Eklendi"; 20 | public static string BrandDeleted = "Marka silindi"; 21 | public static string BrandUpdate = "Marka güncellendi"; 22 | public static string BrandAddedError = "Aynı isimde marka var"; 23 | 24 | public static string UserAdded = "Kullanıcı Eklendi"; 25 | public static string UserDeleted = "Kullanıcı Silindi"; 26 | public static string UserUpdated = "Kullanıcı Güncellendi"; 27 | public static string UserListed = "Kullanıcılar Listelendi"; 28 | public static string UserAddedError = "Böyle bir email var şifrenizi mi unuttunuz"; 29 | 30 | public static string CustomerAdded = "Müşteri eklendi"; 31 | public static string CustomerDeleted = "Müşteri Silindi"; 32 | public static string CustomerUpdated = "Müşteri güncellendi"; 33 | public static string CustomerListed = "Müşteri listelendi"; 34 | 35 | public static string RentalDeleted = "Kiralık Araba silindi"; 36 | public static string RentalUpdated = "Kiralık araba güncellendi"; 37 | public static string RentalListed = "Kiralık arabalar listelendi"; 38 | 39 | public static string RentalAdded = "Araba başarıyla kiralandı"; 40 | public static string RentalDate = "Teslim edilmemiş arabayı kiralayamassınız"; 41 | public static string RentalSuccesAdded = "Bu araç kiralanabilir"; 42 | 43 | public static string ProductInvalidName = "Description 2 karakterden fazla ve Dailyprice 0 dan büyük olmalı"; 44 | public static string CarList = "Car List"; 45 | public static string CompanyNameExists="Aynı isimde şirket adı var!"; 46 | 47 | public static string CarImageLimited="Araba resmi 5 den fazla olamaz"; 48 | public static string CarImageAdded="Araba resmi başarıyla eklendi"; 49 | public static string CarImageList="Araba resimleri listelendi"; 50 | public static string CarImageUpdated="Araba resmi güncellendi"; 51 | public static string CarImageDeleted="Araba resmi silindi"; 52 | public static string CarIdImageExists="Araba resmi yok"; 53 | 54 | 55 | public static string AuthorizationDenied = "Yetkiniz yok"; 56 | public static string UserRegistered = "Başarıyla kayıt olundu"; 57 | public static string UserNotFound = "Kullanıcı bulunamadı"; 58 | public static string PasswordError = "Şifre hatası"; 59 | public static string SuccessfulLogin = "Giriş başarılı"; 60 | public static string UserAlreadyExists = "Aynı isimde kullanıcı var"; 61 | public static string AccessTokenCreated = "Token oluşturuldu"; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /WebAPI/Startup.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Concrete; 3 | using Core.DependencyResolvers; 4 | using Core.Extensions; 5 | using Core.Utilities.IoC; 6 | using Core.Utilities.Security.Encryption; 7 | using Core.Utilities.Security.JWT; 8 | using DataAccess.Abstract; 9 | using DataAccess.Concrete.EntityFramework; 10 | using Microsoft.AspNetCore.Authentication.JwtBearer; 11 | using Microsoft.AspNetCore.Builder; 12 | using Microsoft.AspNetCore.Hosting; 13 | using Microsoft.AspNetCore.Http; 14 | using Microsoft.AspNetCore.HttpsPolicy; 15 | using Microsoft.AspNetCore.Mvc; 16 | using Microsoft.Extensions.Configuration; 17 | using Microsoft.Extensions.DependencyInjection; 18 | using Microsoft.Extensions.Hosting; 19 | using Microsoft.Extensions.Logging; 20 | using Microsoft.IdentityModel.Tokens; 21 | using System; 22 | using System.Collections.Generic; 23 | using System.Linq; 24 | using System.Threading.Tasks; 25 | 26 | namespace WebAPI 27 | { 28 | public class Startup 29 | { 30 | public Startup(IConfiguration configuration) 31 | { 32 | Configuration = configuration; 33 | } 34 | 35 | public IConfiguration Configuration { get; } 36 | 37 | // This method gets called by the runtime. Use this method to add services to the container. 38 | public void ConfigureServices(IServiceCollection services) 39 | { 40 | services.AddControllers(); 41 | services.AddSingleton(); 42 | services.AddCors(); 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 | services.AddDependencyResolvers(new ICoreModule[] 60 | { 61 | new CoreModule() 62 | }); 63 | ServiceTool.Create(services); 64 | 65 | } 66 | 67 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 68 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 69 | { 70 | if (env.IsDevelopment()) 71 | { 72 | app.UseDeveloperExceptionPage(); 73 | } 74 | app.ConfigureCustomExceptionMiddleware(); 75 | 76 | app.UseCors(builder => builder.WithOrigins("http://localhost:4200").AllowAnyHeader()); 77 | 78 | app.UseHttpsRedirection(); 79 | 80 | app.UseRouting(); 81 | 82 | app.UseAuthentication();//middleware deniyor 83 | 84 | app.UseAuthorization(); 85 | 86 | app.UseEndpoints(endpoints => 87 | { 88 | endpoints.MapControllers(); 89 | }); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ReCapProject 2 | Araç Kiralama Projesi 3 | 4 | ## Proje Detayları 5 | Yepyeni bir proje oluşturunuz. Adı **ReCapProject** olacak. 6 | 7 | **Entities**, **DataAccess**, **Business** ve **Console** **katmanlarını** oluşturunuz. 8 | 9 | Bir araba nesnesi oluşturunuz. **"Car"** 10 | 11 | Özellik olarak : **Id**, **BrandId**, **ColorId**, **ModelYear**, **DailyPrice**, **Description** alanlarını ekleyiniz. (Brand = Marka) 12 | 13 | **InMemory** formatta **GetById**, **GetAll**, **Add**, **Update**, **Delete** oprasyonlarını yazınız. 14 | 15 | Consolda test ediniz. 16 | 17 | ## Projeye Devam 18 | Araba Kiralama projemiz üzerinde çalışmaya devam edeceğiz. 19 | 20 | **Car** nesnesine ek olarak; 21 | 22 | - **Brand** ve **Color** nesneleri ekleyiniz(Entity) 23 | 24 | 1.Brand-->Id,Name 25 | 26 | 2.Color-->Id,Name 27 | 28 | - Sql Server tarafında yeni bir veritabanı kurunuz. **Cars**,**Brands**,**Colors** tablolarını oluşturunuz. (Araştırma) 29 | 30 | - Sisteme Generic **IEntityRepository** altyapısı yazınız. 31 | 32 | - **Car**, **Brand** ve **Color** nesneleri için Entity Framework altyapısını yazınız. 33 | 34 | - **GetCarsByBrandId** , **GetCarsByColorId** servislerini yazınız. 35 | 36 | - Sisteme yeni araba eklendiğinde aşağıdaki kuralları çalıştırınız. 37 | 38 | 1.Araba ismi minimum 2 karakter olmalıdır 39 | 40 | 2.Araba günlük fiyatı 0'dan büyük olmalıdır. 41 | 42 | ###### Veritabanı İşlemleri 43 | **Entity Framework:** .Net platformunda ORM(Object Relational Mapping) araçlarından birisidir. ORM (Object Relational Mapping) ise veritabanı ile nesneye yönelik programlama (OOP) arasındaki ilişkiyi kuran teknolojidir. Yani Entity Framework, nesne tabanlı programlamada veritabanındaki tablolara uygun nesneler oluşturma tekniğidir. 44 | Entity Framework ile 3 farklı yöntem ile proje geliştirilebilir. Bu yöntemler; 45 | - Model First (New Database) 46 | - Database First (Existing Database) 47 | - Code First (New Database) 48 | 49 | Biz bu yöntemlerden **Code First** ile ilgileneceğiz. 50 | Code First, adından da anlaşılacağı üzere kod ile veritabanı ve entity modeli tasarlama yaklaşımıdır. 51 | Yapmanız gereken tek şey kodlarla entity classlarını tanımlamak olacaktır. 52 | 53 | DataAccess Class Library(.Net Standard) projesine sağ tıklayıp **Manage Nuget Packages** diyoruz **Browse** da **Microsoft.EntityFrameworkCore.SqlServer** 3.1.11 versiyonu ve **Microsoft.EntityFrameworkCore.Tools** 3.1.11 versiyonlarını indiyoruz 54 | 55 | ConsoleUI Class Library(.Net Standart) projesine sağ tıklayıp **Manage Nuget Packages** diyoruz **Browse** da **Microsoft.EntityFrameworkCore.Design** 3.1.11 veriyonunu indiriyoruz 56 | 57 | **Tools->Manage Nuget Packages->Package Manager Console** açıyoruz ve 58 | ``` 59 | Add-Migration RentaCar 60 | ``` 61 | RentaCar veritabanı ismimi RentaCar yerine başka isimler verebilirsiniz 62 | 63 | ``` 64 | update-database 65 | ``` 66 | ile veritabanımızı güncelliyoruz 67 | 68 | ## Projeye Devam 69 | 70 | - CarRental Projenizde **Core** katmanı oluşturunuz. 71 | 72 | - **IEntity**, **IDto**, **IEntityRepository**, **EfEntityRepositoryBase** dosyalarınızı 9. gün dersindeki gibi oluşturup ekleyiniz. 73 | 74 | - **Car**, **Brand**, **Color** sınıflarınız için tüm CRUD operasyonlarını hazır hale getiriniz. 75 | 76 | - Console'da Tüm CRUD operasyonlarınızı **Car, Brand, Model** nesneleriniz için test ediniz. **GetAll, GetById, Insert, Update, Delete**. 77 | 78 | - Arabaları şu bilgiler olacak şekilde listeleyiniz. **CarName**, **BrandName**, **ColorName**, **DailyPrice**. 79 | > (İpucu : IDto oluşturup 3 tabloya join yazınız) 80 | -------------------------------------------------------------------------------- /ReCapProject.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30717.126 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAccess", "DataAccess\DataAccess.csproj", "{11358DCF-2AF9-4D6A-81F6-B5A505C79026}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "Entities\Entities.csproj", "{5C5E99CD-AD46-481A-ADF2-AF8FAD28CCAC}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Business", "Business\Business.csproj", "{1B2F0F00-D13D-4586-BAB8-80842960F165}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleUI", "ConsoleUI\ConsoleUI.csproj", "{82A97F2C-A73A-4535-B8D5-E7673C2AB42E}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{39BFDE51-AA56-4E66-88AC-4A592EDA19BD}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPI", "WebAPI\WebAPI.csproj", "{3AFB85F8-2E7C-4C15-BFCA-96C5D3A69D36}" 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 20 | Debug|Any CPU = Debug|Any CPU 21 | Release|Any CPU = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 24 | {11358DCF-2AF9-4D6A-81F6-B5A505C79026}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {11358DCF-2AF9-4D6A-81F6-B5A505C79026}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {11358DCF-2AF9-4D6A-81F6-B5A505C79026}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {11358DCF-2AF9-4D6A-81F6-B5A505C79026}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {5C5E99CD-AD46-481A-ADF2-AF8FAD28CCAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {5C5E99CD-AD46-481A-ADF2-AF8FAD28CCAC}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {5C5E99CD-AD46-481A-ADF2-AF8FAD28CCAC}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {5C5E99CD-AD46-481A-ADF2-AF8FAD28CCAC}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {1B2F0F00-D13D-4586-BAB8-80842960F165}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {1B2F0F00-D13D-4586-BAB8-80842960F165}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {1B2F0F00-D13D-4586-BAB8-80842960F165}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {1B2F0F00-D13D-4586-BAB8-80842960F165}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {82A97F2C-A73A-4535-B8D5-E7673C2AB42E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {82A97F2C-A73A-4535-B8D5-E7673C2AB42E}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {82A97F2C-A73A-4535-B8D5-E7673C2AB42E}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {82A97F2C-A73A-4535-B8D5-E7673C2AB42E}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {39BFDE51-AA56-4E66-88AC-4A592EDA19BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {39BFDE51-AA56-4E66-88AC-4A592EDA19BD}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {39BFDE51-AA56-4E66-88AC-4A592EDA19BD}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {39BFDE51-AA56-4E66-88AC-4A592EDA19BD}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {3AFB85F8-2E7C-4C15-BFCA-96C5D3A69D36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {3AFB85F8-2E7C-4C15-BFCA-96C5D3A69D36}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {3AFB85F8-2E7C-4C15-BFCA-96C5D3A69D36}.Release|Any CPU.ActiveCfg = Release|Any CPU 47 | {3AFB85F8-2E7C-4C15-BFCA-96C5D3A69D36}.Release|Any CPU.Build.0 = Release|Any CPU 48 | EndGlobalSection 49 | GlobalSection(SolutionProperties) = preSolution 50 | HideSolutionNode = FALSE 51 | EndGlobalSection 52 | GlobalSection(ExtensibilityGlobals) = postSolution 53 | SolutionGuid = {DE80E16C-E175-4BE8-A4AC-03C533FB7EE5} 54 | EndGlobalSection 55 | EndGlobal 56 | -------------------------------------------------------------------------------- /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 | ICarService _carService; 17 | public CarsController(ICarService carService) 18 | { 19 | _carService = carService; 20 | } 21 | [HttpGet("getall")] 22 | public IActionResult GetAll() 23 | { 24 | var result = _carService.GetAll(); 25 | if (result.Success==true) 26 | { 27 | return Ok(result); 28 | } 29 | return BadRequest(result); 30 | } 31 | 32 | [HttpGet("getcardetails")] 33 | public IActionResult GetCarDetails() 34 | { 35 | var result = _carService.GetCarDetails(); 36 | if (result.Success==true) 37 | { 38 | return Ok(result); 39 | } 40 | return BadRequest(result); 41 | } 42 | [HttpGet("getbrandid")] 43 | public IActionResult GetBrandId(int brandId) 44 | { 45 | var result = _carService.GetCarsByBrandId(brandId); 46 | if (result.Success==true) 47 | { 48 | return Ok(result); 49 | } 50 | return BadRequest(result); 51 | } 52 | [HttpGet("getcolorid")] 53 | public IActionResult GetColorId(int colorId) 54 | { 55 | var result = _carService.GetCarsByColorId(colorId); 56 | if (result.Success==true) 57 | { 58 | return Ok(result); 59 | } 60 | return BadRequest(result); 61 | } 62 | [HttpPost("add")] 63 | public IActionResult Add(Car car) 64 | { 65 | var result = _carService.AddedCar(car); 66 | if (result.Success==true) 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==true) 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==true) 87 | { 88 | return Ok(result); 89 | } 90 | return BadRequest(result); 91 | } 92 | 93 | [HttpGet("getlistbybrand")] 94 | public IActionResult GetListByBrand(int brandId) 95 | { 96 | var result = _carService.GetListByBrand(brandId); 97 | if (result.Success == true) 98 | { 99 | return Ok(result); 100 | } 101 | return BadRequest(result); 102 | } 103 | 104 | [HttpGet("getlistbycolor")] 105 | public IActionResult GetListByColor(int colorId) 106 | { 107 | var result = _carService.GetListByColor(colorId); 108 | if (result.Success==true) 109 | { 110 | return Ok(result); 111 | } 112 | return BadRequest(result); 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /ConsoleUI/Program.cs: -------------------------------------------------------------------------------- 1 | using Business.Concrete; 2 | using Business.Constants; 3 | using DataAccess.Concrete.EntityFramework; 4 | using DataAccess.Concrete.InMemory; 5 | using Entities.Concrete; 6 | using System; 7 | 8 | namespace ConsoleUI 9 | { 10 | class Program 11 | { 12 | public static bool döngü; 13 | public static int secim; 14 | static void Main(string[] args) 15 | { 16 | 17 | Console.WriteLine("1-Renk İşlemleri"); 18 | Console.WriteLine("2-Marka İşlemleri"); 19 | Console.WriteLine("3-Araba İşlemleri"); 20 | Console.WriteLine("4-Kullanıcı İşlemleri"); 21 | Console.WriteLine("5-Müşteri İşlemleri"); 22 | Console.WriteLine("6-Araç Kiralama İşlemleri"); 23 | Console.WriteLine("7-Çıkış\n"); 24 | döngü = true; 25 | 26 | while (döngü) 27 | { 28 | Console.WriteLine("Yukarıdaki menüden seçiniz"); 29 | secim = Convert.ToInt32(Console.ReadLine()); 30 | switch (secim) 31 | { 32 | case 1: 33 | ColorOperations(); 34 | döngü = true; 35 | break; 36 | case 2: 37 | BrandOperations(); 38 | döngü = true; 39 | break; 40 | case 3: 41 | döngü = true; 42 | break; 43 | case 4: 44 | döngü = true; 45 | break; 46 | case 5: 47 | döngü = true; 48 | break; 49 | case 6: 50 | döngü = true; 51 | break; 52 | case 7: 53 | döngü = false; 54 | break; 55 | default: 56 | Console.WriteLine("1 ile 7 arasında seçim yapınız"); 57 | döngü = true; 58 | break; 59 | } 60 | } 61 | 62 | 63 | Console.ReadLine(); 64 | } 65 | public static void ColorOperations() 66 | { 67 | Console.ForegroundColor = ConsoleColor.Magenta; 68 | Console.WriteLine("1-Renk listele"); 69 | Console.WriteLine("2-Renk ekle"); 70 | Console.WriteLine("3-Renk güncelle"); 71 | Console.WriteLine("4-Renk sil"); 72 | Console.WriteLine("5-Üst menüye dön\n"); 73 | döngü = true; 74 | while (döngü) 75 | { 76 | ColorManager colorManager = new ColorManager(new EfColorDal()); 77 | Color color = new Color(); 78 | Console.WriteLine("Yukarıdaki menüden seçiniz"); 79 | secim = Convert.ToInt32(Console.ReadLine()); 80 | switch (secim) 81 | { 82 | case 1: 83 | ColorList(colorManager); 84 | break; 85 | case 2: 86 | Console.WriteLine("Renk ismi giriniz"); 87 | color.ColorName = Console.ReadLine(); 88 | color.GetState = true; 89 | var colorAdded =colorManager.Add(color); 90 | if (colorAdded.Success==true) 91 | { 92 | Console.WriteLine(Messages.ColorAdded); 93 | } 94 | break; 95 | case 3: 96 | ColorList(colorManager); 97 | Console.WriteLine("Yukarıdan güncellenecek renk id sini seçiniz"); 98 | color.ColorId = Convert.ToInt32(Console.ReadLine()); 99 | Console.WriteLine("Renk ismi"); 100 | color.ColorName = Console.ReadLine(); 101 | color.GetState = true; 102 | var colorUpdated = colorManager.Update(color); 103 | if (colorUpdated.Success==true) 104 | { 105 | Console.WriteLine(Messages.ColorUpdated); 106 | } 107 | break; 108 | case 4: 109 | ColorList(colorManager); 110 | Console.WriteLine("Yukarıdan silinecek renk id sinizi seçiniz"); 111 | color.ColorId = Convert.ToInt32(Console.ReadLine()); 112 | color.GetState = false; 113 | var colorDelete = colorManager.Delete(color); 114 | if (colorDelete.Success==true) 115 | { 116 | Console.WriteLine(Messages.ColorDeleted); 117 | } 118 | break; 119 | case 5: 120 | döngü = false; 121 | break; 122 | default: 123 | Console.WriteLine(""); 124 | break; 125 | } 126 | } 127 | Console.ForegroundColor = ConsoleColor.White; 128 | } 129 | 130 | private static void ColorList(ColorManager colorManager) 131 | { 132 | var colorList = colorManager.GetAll(); 133 | if (colorList.Success == true) 134 | { 135 | Console.WriteLine(Messages.ColorList); 136 | foreach (var colorlist in colorList.Data) 137 | { 138 | Console.WriteLine("Renk Id:{0} Renk Adı:{1}", colorlist.ColorId, colorlist.ColorName); 139 | } 140 | } 141 | } 142 | 143 | public static void BrandOperations() 144 | { 145 | Console.WriteLine("Brand İşlemleri"); 146 | } 147 | 148 | } 149 | 150 | } 151 | -------------------------------------------------------------------------------- /.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 --------------------------------------------------------------------------------