├── SQLQuery2.sql ├── WebAPI ├── wwwroot │ └── uploads │ │ ├── DefaultCar.jfif │ │ ├── 27_2_2021_c87083fa-4c69-4569-b034-fd37f6c8fdc3.jfif │ │ ├── 27_2_2021_fa6fbdb0-9985-4045-88f6-2d0f4159cb51.jfif │ │ └── 2_3_2021_38e4ee37-cfd4-4c0f-b25b-39a565fb904a.jfif ├── appsettings.Development.json ├── WeatherForecast.cs ├── appsettings.json ├── Properties │ └── launchSettings.json ├── WebAPI.csproj ├── Program.cs ├── Controllers │ ├── WeatherForecastController.cs │ ├── AuthController.cs │ ├── UsersController.cs │ ├── BrandsController.cs │ ├── ColorsController.cs │ ├── CustomersController.cs │ ├── RentalsController.cs │ ├── CarsController.cs │ └── CarImagesController.cs ├── log4net.config └── Startup.cs ├── Core ├── Entities │ ├── IDto.cs │ ├── IEntity.cs │ └── Concrete │ │ ├── OperationClaim.cs │ │ ├── UserOperationClaim.cs │ │ └── User.cs ├── Utilities │ ├── Results │ │ ├── IDataResult.cs │ │ ├── IResult.cs │ │ ├── ErrorResult.cs │ │ ├── SuccessResult.cs │ │ ├── DataResult.cs │ │ ├── Result.cs │ │ ├── ErrorDataResult.cs │ │ └── SuccessDataResult.cs │ ├── IoC │ │ ├── ICoreModule.cs │ │ └── ServiceTool.cs │ ├── Security │ │ ├── Jwt │ │ │ ├── AccessToken.cs │ │ │ ├── ITokenHelper.cs │ │ │ ├── TokenOptions.cs │ │ │ └── JwtHelper.cs │ │ ├── Encryption │ │ │ ├── SecurityKeyHelper.cs │ │ │ └── SigningCredentialsHelper.cs │ │ └── Hashing │ │ │ └── HashingHelper.cs │ ├── Messages │ │ └── AspectMessages.cs │ ├── Interceptors │ │ ├── MethodInterceptionBaseAttribute.cs │ │ ├── AspectInterceptorSelector.cs │ │ └── MethodInterception.cs │ ├── Business │ │ └── BusinessRules.cs │ └── FileOperation │ │ └── FileOperation.cs ├── CrossCuttingConcerns │ ├── Logging │ │ ├── LogDetailWithException.cs │ │ ├── LogDetail.cs │ │ ├── Log4Net │ │ │ ├── Loggers │ │ │ │ ├── FileLogger.cs │ │ │ │ └── DatabaseLogger.cs │ │ │ ├── SerializableLogEvent.cs │ │ │ ├── Layouts │ │ │ │ └── JsonLayout.cs │ │ │ └── LoggerServiceBase.cs │ │ └── LogParameter.cs │ ├── Caching │ │ ├── ICacheManager.cs │ │ └── Microsoft │ │ │ └── MemoryCacheManager.cs │ └── Validation │ │ └── ValidationTool.cs ├── Extensions │ ├── ErrorDetails.cs │ ├── ServiceCollectionExtensions.cs │ ├── ClaimsPrincipalExtensions.cs │ └── ClaimExtensions.cs ├── DataAccess │ ├── IEntityRepository.cs │ └── EntityFramework │ │ └── EfEntityRepositoryBase.cs ├── DependencyResolvers │ └── CoreModule.cs ├── Aspects │ └── Autofac │ │ ├── Caching │ │ ├── CacheRemoveAspect.cs │ │ └── CacheAspect.cs │ │ ├── Transaction │ │ └── TransactionScopeAspect.cs │ │ ├── Performance │ │ └── PerformanceAspect.cs │ │ ├── Validation │ │ └── ValidationAspect.cs │ │ └── Logging │ │ └── LogAspect.cs └── Core.csproj ├── Entities ├── Entities.csproj ├── Concrete │ ├── Brand.cs │ ├── Color.cs │ ├── Customer.cs │ ├── CarImage.cs │ ├── Rental.cs │ └── Car.cs └── DTOs │ ├── UserForLoginDto.cs │ ├── UserForRegisterDto.cs │ └── CarDetailDto.cs ├── DataAccess ├── Abstract │ ├── IBrandDal.cs │ ├── IColorDal.cs │ ├── IRentalDal.cs │ ├── ICarImageDal.cs │ ├── ICustomerDal.cs │ ├── IUserDal.cs │ └── ICarDal.cs ├── Concrete │ ├── EntityFrameWork │ │ ├── EfBrandDal.cs │ │ ├── EfColorDal.cs │ │ ├── EfRentalDal.cs │ │ ├── EfCustomerDal.cs │ │ ├── EfCarImageDal.cs │ │ ├── SouthwindContext.cs │ │ ├── EfUserDal.cs │ │ └── EfCarDal.cs │ └── InMemory │ │ └── InMemoryCarDal.cs └── DataAccess.csproj ├── CarImagesDBCreate.sql ├── SQLQuery1_recap.sql ├── dbo.Users.sql ├── ConsoleUI ├── ConsoleUI.csproj └── Program.cs ├── Business ├── ValidationRules │ └── FluentValidation │ │ ├── BrandValidator.cs │ │ ├── ColorValidator.cs │ │ ├── RentalValidator.cs │ │ ├── CarImageValidator.cs │ │ ├── CustomerValidator.cs │ │ ├── CarValidator.cs │ │ └── UserValidator.cs ├── Abstract │ ├── IBrandService.cs │ ├── IColorService.cs │ ├── IUserService.cs │ ├── IRentalService.cs │ ├── ICustomerService.cs │ ├── IAuthService.cs │ ├── ICarImageService.cs │ └── ICarService.cs ├── Business.csproj ├── BusinessAspects │ └── Autofac │ │ └── SecuredOperation.cs ├── DependencyResolvers │ └── Autofac │ │ └── AutofacBusinessModule.cs ├── Concrete │ ├── BrandManager.cs │ ├── ColorManager.cs │ ├── CustomerManager.cs │ ├── AuthManager.cs │ ├── UserManager.cs │ ├── CarManager.cs │ ├── RentalManager.cs │ └── CarImageManager.cs └── Constants │ └── Messages.cs ├── SQLQueryNewTable Create.sql ├── .gitattributes ├── ReCapProject.sln └── .gitignore /SQLQuery2.sql: -------------------------------------------------------------------------------- 1 | EXEC sp_rename 'Cars.Description', 'Name', 'COLUMN' 2 | 3 | 4 | Drop Table Cars; -------------------------------------------------------------------------------- /WebAPI/wwwroot/uploads/DefaultCar.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zciklacekic/ReCapProject/HEAD/WebAPI/wwwroot/uploads/DefaultCar.jfif -------------------------------------------------------------------------------- /Core/Entities/IDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Entities 6 | { 7 | public interface IDto 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /WebAPI/wwwroot/uploads/27_2_2021_c87083fa-4c69-4569-b034-fd37f6c8fdc3.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zciklacekic/ReCapProject/HEAD/WebAPI/wwwroot/uploads/27_2_2021_c87083fa-4c69-4569-b034-fd37f6c8fdc3.jfif -------------------------------------------------------------------------------- /WebAPI/wwwroot/uploads/27_2_2021_fa6fbdb0-9985-4045-88f6-2d0f4159cb51.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zciklacekic/ReCapProject/HEAD/WebAPI/wwwroot/uploads/27_2_2021_fa6fbdb0-9985-4045-88f6-2d0f4159cb51.jfif -------------------------------------------------------------------------------- /WebAPI/wwwroot/uploads/2_3_2021_38e4ee37-cfd4-4c0f-b25b-39a565fb904a.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zciklacekic/ReCapProject/HEAD/WebAPI/wwwroot/uploads/2_3_2021_38e4ee37-cfd4-4c0f-b25b-39a565fb904a.jfif -------------------------------------------------------------------------------- /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/Entities/Concrete/OperationClaim.cs: -------------------------------------------------------------------------------- 1 | namespace Core.Entities.Concrete 2 | { 3 | public class OperationClaim:IEntity 4 | { 5 | public int Id { get; set; } 6 | public string Name { get; set; } 7 | 8 | } 9 | } 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 | 13 | -------------------------------------------------------------------------------- /Core/Utilities/Results/IResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public interface IResult 8 | { 9 | bool Success { get; } 10 | string Message { get; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Entities/Entities.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/UserOperationClaim.cs: -------------------------------------------------------------------------------- 1 | namespace Core.Entities.Concrete 2 | { 3 | public class UserOperationClaim:IEntity 4 | { 5 | public int Id { get; set; } 6 | public int UserId { get; set; } 7 | public int OperationClaimId { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /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/IRentalDal.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 IRentalDal: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 | -------------------------------------------------------------------------------- /DataAccess/Abstract/ICustomerDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Entities.Concrete; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataAccess.Abstract 8 | { 9 | public interface ICustomerDal:IEntityRepository 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Entities/Concrete/Brand.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Brand:IEntity 9 | { 10 | public int Id { get; set; } 11 | public string Name { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Entities/Concrete/Color.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Color:IEntity 9 | { 10 | public int Id { get; set; } 11 | public string Name { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/Utilities/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 collection); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataAccess/Abstract/IUserDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess; 2 | using Core.Entities.Concrete; 3 | using System.Collections.Generic; 4 | 5 | namespace DataAccess.Abstract 6 | { 7 | public interface IUserDal : IEntityRepository 8 | { 9 | List GetClaims(User user); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Logging/LogDetailWithException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Logging 6 | { 7 | public class LogDetailWithException : LogDetail 8 | { 9 | public string ExceptionMessage { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /CarImagesDBCreate.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE CarImages ( 2 | Id int, 3 | CarId int, 4 | ImagePath varchar(255), 5 | Date DateTime 6 | ); 7 | 8 | ALTER TABLE CarImages 9 | ALTER COLUMN Id int NOT NULL; 10 | 11 | ALTER TABLE CarImages 12 | ADD PRIMARY KEY (Id); 13 | ALTER TABLE CarImages 14 | ADD FOREIGN KEY (CarId) REFERENCES Cars(Id); -------------------------------------------------------------------------------- /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 | } 14 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Jwt/ITokenHelper.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Utilities.Security.Jwt 7 | { 8 | public interface ITokenHelper 9 | { 10 | AccessToken CreateToken(User user, List operationClaims); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /SQLQuery1_recap.sql: -------------------------------------------------------------------------------- 1 | create database southwind 2 | CREATE TABLE Cars ( 3 | Id int, 4 | BrandId int, 5 | ColorId int, 6 | ModelYear int, 7 | DailyPrice int, 8 | Name varchar(255) 9 | ); 10 | CREATE TABLE Brands ( 11 | Id int, 12 | Name varchar(255) 13 | ); 14 | CREATE TABLE Colors ( 15 | Id int, 16 | Name varchar(255) 17 | ); -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Logging/LogDetail.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Logging 6 | { 7 | public class LogDetail 8 | { 9 | public string MethodName { get; set; } 10 | public List LogParameters { get; set; } 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Entities/DTOs/UserForRegisterDto.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | 3 | namespace Entities.DTOs 4 | { 5 | public class UserForRegisterDto : IDto 6 | { 7 | public string Email { get; set; } 8 | public string Password { get; set; } 9 | public string FirstName { get; set; } 10 | public string LastName { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /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 | } 16 | -------------------------------------------------------------------------------- /WebAPI/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebAPI 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Entities/Concrete/Customer.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Customer:IEntity 9 | { 10 | public int Id { get; set; } 11 | public int UserId { get; set; } 12 | public string CompanyName { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Logging/Log4Net/Loggers/FileLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Logging.Log4Net.Loggers 6 | { 7 | public class FileLogger : LoggerServiceBase 8 | { 9 | public FileLogger() : base("JsonFileLogger") 10 | { 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Logging/LogParameter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Logging 6 | { 7 | public class LogParameter 8 | { 9 | public string Name { get; set; } 10 | public object Value { get; set; } 11 | public string Type { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/Utilities/Messages/AspectMessages.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Messages 6 | { 7 | public static class AspectMessages 8 | { 9 | public static string WrongValidationType = "Wrong Validation Type"; 10 | public static string WrongLoggerType = "Wrong Logger Type"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Logging/Log4Net/Loggers/DatabaseLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Logging.Log4Net.Loggers 6 | { 7 | public class DatabaseLogger : LoggerServiceBase 8 | { 9 | public DatabaseLogger() : base("DatabaseLogger") 10 | { 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFrameWork/EfBrandDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFrameWork 9 | { 10 | public class EfBrandDal : EfEntityRepositoryBase, IBrandDal 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFrameWork/EfColorDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFrameWork 9 | { 10 | public class EfColorDal : EfEntityRepositoryBase, IColorDal 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /dbo.Users.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [dbo].[Users] ( 2 | [Id] INT NOT NULL IDENTITY, 3 | [FirstName] VARCHAR (50) NOT NULL, 4 | [LastName] VARCHAR (50) NOT NULL, 5 | [Email] VARCHAR (50) NOT NULL, 6 | [PasswordHash] BINARY(500) NOT NULL, 7 | [PasswordSalt] BINARY(500) NOT NULL, 8 | [Status] BIT NOT NULL, 9 | CONSTRAINT [PK_Users] PRIMARY KEY ([Id]) 10 | ); 11 | 12 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFrameWork/EfRentalDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFrameWork 9 | { 10 | public class EfRentalDal : EfEntityRepositoryBase, IRentalDal 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/Utilities/Results/ErrorResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class ErrorResult : Result 8 | { 9 | public ErrorResult(string message) : base(false, message) 10 | { 11 | 12 | } 13 | public ErrorResult() : base(false) 14 | { 15 | 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFrameWork/EfCustomerDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using DataAccess.Abstract; 3 | using Entities.Concrete; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace DataAccess.Concrete.EntityFrameWork 9 | { 10 | public class EfCustomerDal : EfEntityRepositoryBase, ICustomerDal 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Entities/Concrete/CarImage.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class CarImage:IEntity 9 | { 10 | public int Id { get; set; } 11 | public int CarId { get; set; } 12 | public string ImagePath { get; set; } 13 | public DateTime Date { get; set; } 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Encryption/SecurityKeyHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IdentityModel.Tokens; 2 | using System.Text; 3 | 4 | namespace Core.Utilities.Security.Encryption 5 | { 6 | public class SecurityKeyHelper 7 | { 8 | public static SecurityKey CreateSecurityKey(string securitykey) 9 | { 10 | return new SymmetricSecurityKey(Encoding.UTF8.GetBytes(securitykey)); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Encryption/SigningCredentialsHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IdentityModel.Tokens; 2 | 3 | namespace Core.Utilities.Security.Encryption 4 | { 5 | public class SigningCredentialsHelper 6 | { 7 | public static SigningCredentials CreateSigningCredentials(SecurityKey security) 8 | { 9 | return new SigningCredentials(security, SecurityAlgorithms.HmacSha512Signature); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Entities/Concrete/Rental.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Rental:IEntity 9 | { 10 | public int Id { get; set; } 11 | public int CarId { get; set; } 12 | public int CustomerId { get; set; } 13 | public DateTime RentDate { get; set; } 14 | public DateTime ReturnDate { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /WebAPI/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "TokenOptions": { 3 | "Audience": "zciklacekic@ciklacekic.com", 4 | "Issuer": "zciklacekic@ciklacekic.com", 5 | "AccessTokenExpiration": 20, 6 | "SecurityKey": "mysupersecretkeymysupersecretkey" 7 | }, 8 | "Logging": { 9 | "LogLevel": { 10 | "Default": "Information", 11 | "Microsoft": "Warning", 12 | "Microsoft.Hosting.Lifetime": "Information" 13 | } 14 | }, 15 | "AllowedHosts": "*" 16 | } 17 | -------------------------------------------------------------------------------- /ConsoleUI/ConsoleUI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Core/Extensions/ErrorDetails.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Extensions 7 | { 8 | public class ErrorDetails 9 | { 10 | public string Message { get; set; } 11 | public int StatusCode { get; set; } 12 | 13 | public override string ToString() 14 | { 15 | return JsonConvert.SerializeObject(this); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Entities/DTOs/CarDetailDto.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.DTOs 7 | { 8 | public class CarDetailDto : IDto 9 | { 10 | public int CarId { get; set; } 11 | public string CarName { get; set; } 12 | public string BrandName { get; set; } 13 | public string ColorName { get; set; } 14 | public int DailyPrice { get; set; } 15 | } 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /DataAccess/DataAccess.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Entities/Concrete/Car.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Concrete 7 | { 8 | public class Car:IEntity 9 | { 10 | public int Id { get; set; } 11 | public int BrandId { get; set; } 12 | public int ColorId { get; set; } 13 | public int ModelYear { get; set; } 14 | public int DailyPrice { get; set; } 15 | public string Name { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Caching/ICacheManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.CrossCuttingConcerns.Caching 6 | { 7 | public interface ICacheManager 8 | { 9 | T Get(string key); 10 | object Get(string key); 11 | void Add(string key, object data, int duration); 12 | bool IsAdd(string key); 13 | void Remove(string key); 14 | void RemoveByPattern(string pattern); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /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(p => p.Name).NotEmpty(); 14 | RuleFor(p => p.Name).MinimumLength(2); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /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(p => p.Name).NotEmpty(); 14 | RuleFor(p => p.Name).MinimumLength(2); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFrameWork/EfCarImageDal.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 EfCarImageDal : EfEntityRepositoryBase, ICarImageDal 14 | { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | List GetAll(Expression> filter = null); 12 | T Get(Expression> filter); 13 | void Add(T entity); 14 | void Update(T entity); 15 | void Delete(T entity); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /SQLQueryNewTable Create.sql: -------------------------------------------------------------------------------- 1 | --create table Users (Id int,FirstName varchar,LastName varchar,Email varchar, Password varchar); 2 | --create table Customers (Id int,UserId int,CompanyName varchar); 3 | --create table Rentals (Id int,CarId int,CustomerId int,RentDate datetime,ReturnData datetime); 4 | ALTER TABLE Rentals 5 | ALTER COLUMN RentDate datetime2; 6 | --ALTER TABLE Colors 7 | --ADD PRIMARY KEY (Id); 8 | --ALTER TABLE Customers 9 | --ADD FOREIGN KEY (UserId) REFERENCES Users(Id); 10 | --EXEC sp_rename 'Rentals.ReturnData', 'ReturnDate', 'COLUMN'; -------------------------------------------------------------------------------- /Core/Utilities/Results/DataResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Results 6 | { 7 | public class DataResult : Result, IDataResult 8 | { 9 | public DataResult(T data, bool success, string message) : base(success, message) 10 | { 11 | Data = data; 12 | } 13 | public DataResult(T data, bool success) : base(success) 14 | { 15 | Data = data; 16 | } 17 | public T Data { get; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /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 | 18 | public bool Success { get; } 19 | 20 | public string Message { get; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Utilities/IoC/ServiceTool.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.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/IBrandService.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 IBrandService 11 | { 12 | IDataResult> GetAll(); 13 | IDataResult GetById(int brandId); 14 | IResult Add(Brand brand); 15 | IResult Delete(Brand brand); 16 | IResult Update(Brand brand); 17 | IResult IsExist(int brandId); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Business/Abstract/IColorService.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 IColorService 11 | { 12 | IDataResult> GetAll(); 13 | IDataResult GetById(int colorId); 14 | IResult Add(Color color); 15 | IResult Delete(Color color); 16 | IResult Update(Color color); 17 | IResult IsExist(int colorId); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /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(p => p.CarId).NotEmpty(); 14 | RuleFor(p => p.CustomerId).NotEmpty(); 15 | RuleFor(p => p.RentDate).NotEmpty(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Core/Entities/Concrete/User.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.Entities.Concrete 7 | { 8 | public class User:IEntity 9 | { 10 | public int Id { get; set; } 11 | public string FirstName { get; set; } 12 | public string LastName { get; set; } 13 | public string Email { get; set; } 14 | public byte[] PasswordHash { get; set; } 15 | public byte[] PasswordSalt { get; set; } 16 | public bool Status { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /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(p => p.CarId).NotEmpty(); 14 | //RuleFor(p => p.ImagePath).NotEmpty(); 15 | //RuleFor(p=>p.Date).NotEmpty(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Business/Abstract/IUserService.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Core.Utilities.Results; 3 | using System.Collections.Generic; 4 | 5 | namespace Business.Abstract 6 | { 7 | public interface IUserService 8 | { 9 | IDataResult> GetAll(); 10 | IDataResult GetById(int userId); 11 | IDataResult GetByMail(string email); 12 | IDataResult> GetClaims(User user); 13 | IResult Add(User user); 14 | IResult Delete(User user); 15 | IResult Update(User user); 16 | } 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 | IDataResult> GetAll(); 13 | IDataResult GetById(int rentalId); 14 | IResult Add(Rental rental); 15 | IResult Delete(Rental rental); 16 | IResult Update(Rental rental); 17 | IResult EndRental(Rental rental); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Logging/Log4Net/SerializableLogEvent.cs: -------------------------------------------------------------------------------- 1 | using log4net.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Core.CrossCuttingConcerns.Logging.Log4Net 7 | { 8 | [Serializable] 9 | public class SerializableLogEvent 10 | { 11 | private LoggingEvent _loggingEvent; 12 | 13 | public SerializableLogEvent(LoggingEvent loggingEvent) 14 | { 15 | _loggingEvent = loggingEvent; 16 | } 17 | 18 | public object Message => _loggingEvent.MessageObject; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /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(p => p.UserId).NotEmpty(); 14 | RuleFor(p => p.CompanyName).NotEmpty(); 15 | RuleFor(p => p.CompanyName).MinimumLength(2); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /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 | } 24 | -------------------------------------------------------------------------------- /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 | IDataResult> GetAll(); 13 | IDataResult GetById(int customerId); 14 | IResult Add(Customer customer); 15 | IResult Delete(Customer customer); 16 | IResult Update(Customer customer); 17 | IResult IsExist(int customerId); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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(this IServiceCollection services, 12 | ICoreModule[] modules) 13 | { 14 | foreach (var module in modules) 15 | { 16 | module.Load(services); 17 | } 18 | 19 | return ServiceTool.Create(services); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /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/ClaimsPrincipalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Security.Claims; 4 | 5 | namespace Core.Extensions 6 | { 7 | public static class ClaimsPrincipalExtensions 8 | { 9 | public static List Claims(this ClaimsPrincipal claimsPrincipal, string claimType) 10 | { 11 | var result = claimsPrincipal?.FindAll(claimType)?.Select(x => x.Value).ToList(); 12 | return result; 13 | } 14 | 15 | public static List ClaimRoles(this ClaimsPrincipal claimsPrincipal) 16 | { 17 | return claimsPrincipal?.Claims(ClaimTypes.Role); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Logging/Log4Net/Layouts/JsonLayout.cs: -------------------------------------------------------------------------------- 1 | using log4net.Core; 2 | using log4net.Layout; 3 | using Newtonsoft.Json; 4 | using System.IO; 5 | 6 | 7 | namespace Core.CrossCuttingConcerns.Logging.Log4Net.Layouts 8 | { 9 | public class JsonLayout : LayoutSkeleton 10 | { 11 | public override void ActivateOptions() 12 | { 13 | 14 | } 15 | 16 | public override void Format(TextWriter writer, LoggingEvent loggingEvent) 17 | { 18 | var logEvent = new SerializableLogEvent(loggingEvent); 19 | var json = JsonConvert.SerializeObject(logEvent, Formatting.Indented); 20 | writer.WriteLine(json); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Business/Abstract/ICarImageService.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.FileOperation; 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 ICarImageService 11 | { 12 | IDataResult> GetAll(); 13 | IDataResult GetById(int carImageId); 14 | IDataResult> GetCarImagesByCarId(int carId); 15 | IResult Add(FileOperation file, string filePath, CarImage carImage); 16 | IResult Delete(string filePath, CarImage carImage); 17 | IResult Update(FileOperation file,string filePath, CarImage carImage); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /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.Diagnostics; 7 | 8 | namespace Core.DependencyResolvers 9 | { 10 | public class CoreModule : ICoreModule 11 | { 12 | public void Load(IServiceCollection services) 13 | { 14 | services.AddMemoryCache(); 15 | services.AddSingleton(); 16 | services.AddSingleton(); 17 | services.AddSingleton(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /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(p => p.Name).NotEmpty(); 14 | RuleFor(p => p.Name).MinimumLength(2); 15 | RuleFor(p => p.DailyPrice).NotEmpty(); 16 | RuleFor(p => p.DailyPrice).GreaterThan(0); 17 | RuleFor(p => p.BrandId).NotEmpty(); 18 | RuleFor(p => p.ColorId).NotEmpty(); 19 | RuleFor(p => p.ModelYear).NotEmpty(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /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 GetById(int carId); 14 | IDataResult> GetCarsByBrandId(int id); 15 | IDataResult> GetCarsByColorId(int id); 16 | IDataResult> GetCarDetails(); 17 | IResult Add(Car car); 18 | IResult Delete(Car car); 19 | IResult Update(Car car); 20 | IResult IsExist(int carId); 21 | IResult TransactionalOperation(Car car); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /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 | 7 | namespace Core.Aspects.Autofac.Caching 8 | { 9 | public class CacheRemoveAspect : MethodInterception 10 | { 11 | private string _pattern; 12 | private ICacheManager _cacheManager; 13 | 14 | public CacheRemoveAspect(string pattern) 15 | { 16 | _pattern = pattern; 17 | _cacheManager = ServiceTool.ServiceProvider.GetService(); 18 | } 19 | 20 | protected override void OnSuccess(IInvocation invocation) 21 | { 22 | _cacheManager.RemoveByPattern(_pattern); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Transaction/TransactionScopeAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.Utilities.Interceptors; 3 | using System.Transactions; 4 | 5 | namespace Core.Aspects.Autofac.Transaction 6 | { 7 | public class TransactionScopeAspect : MethodInterception 8 | { 9 | public override void Intercept(IInvocation invocation) 10 | { 11 | using (TransactionScope transactionScope = new TransactionScope()) 12 | { 13 | try 14 | { 15 | invocation.Proceed(); 16 | transactionScope.Complete(); 17 | } 18 | catch (System.Exception e) 19 | { 20 | transactionScope.Dispose(); 21 | throw; 22 | } 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /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(p => p.FirstName).NotEmpty(); 15 | RuleFor(p => p.FirstName).MinimumLength(2); 16 | RuleFor(p => p.LastName).NotEmpty(); 17 | RuleFor(p => p.LastName).MinimumLength(2); 18 | RuleFor(p => p.Email).NotEmpty(); 19 | RuleFor(p => p.Email).EmailAddress(); 20 | RuleFor(p => p.PasswordHash).NotEmpty(); 21 | RuleFor(p => p.PasswordSalt).NotEmpty(); 22 | RuleFor(p => p.Status).NotEmpty(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /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:58475", 8 | "sslPort": 44311 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 | -------------------------------------------------------------------------------- /WebAPI/WebAPI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Core/Utilities/Interceptors/AspectInterceptorSelector.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Reflection; 6 | using System.Linq; 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 | //Log eklendigi zaman classAttributes.Add(new ExceptionLogAspect(typeof(FileLogger))); 20 | 21 | return classAttributes.OrderBy(x => x.Priority).ToArray(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFrameWork/SouthwindContext.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Entities.Concrete; 3 | using Microsoft.EntityFrameworkCore; 4 | 5 | namespace DataAccess.Concrete.EntityFrameWork 6 | { 7 | public class SouthwindContext : DbContext 8 | { 9 | 10 | 11 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 12 | { 13 | optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=southwind;Trusted_Connection=true"); 14 | } 15 | 16 | public DbSet Cars { get; set; } 17 | public DbSet Colors { get; set; } 18 | public DbSet Brands { get; set; } 19 | public DbSet Users { get; set; } 20 | public DbSet Customers { get; set; } 21 | public DbSet Rentals { get; set; } 22 | public DbSet CarImages { get; set; } 23 | public DbSet OperationClaims { get; set; } 24 | public DbSet UserOperationClaims { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Core/Extensions/ClaimExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IdentityModel.Tokens.Jwt; 4 | using System.Linq; 5 | using System.Security.Claims; 6 | using System.Text; 7 | 8 | namespace Core.Extensions 9 | { 10 | public static class ClaimExtensions 11 | { 12 | public static void AddEmail(this ICollection claims, string email) 13 | { 14 | claims.Add(new Claim(JwtRegisteredClaimNames.Email, email)); 15 | } 16 | 17 | public static void AddName(this ICollection claims, string name) 18 | { 19 | claims.Add(new Claim(ClaimTypes.Name, name)); 20 | } 21 | 22 | public static void AddNameIdentifier(this ICollection claims, string nameIdentifier) 23 | { 24 | claims.Add(new Claim(ClaimTypes.NameIdentifier, nameIdentifier)); 25 | } 26 | 27 | public static void AddRoles(this ICollection claims, string[] roles) 28 | { 29 | roles.ToList().ForEach(role => claims.Add(new Claim(ClaimTypes.Role, role))); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /DataAccess/Concrete/EntityFrameWork/EfUserDal.cs: -------------------------------------------------------------------------------- 1 | using Core.DataAccess.EntityFramework; 2 | using Core.Entities.Concrete; 3 | using DataAccess.Abstract; 4 | using Entities.Concrete; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | 9 | namespace DataAccess.Concrete.EntityFrameWork 10 | { 11 | public class EfUserDal : EfEntityRepositoryBase, IUserDal 12 | { 13 | public List GetClaims(User user) 14 | { 15 | using (var context = new SouthwindContext()) 16 | { 17 | var result = from operationClaim in context.OperationClaims 18 | join userOperationClaim in context.UserOperationClaims 19 | on operationClaim.Id equals userOperationClaim.OperationClaimId 20 | where userOperationClaim.UserId == user.Id 21 | select new OperationClaim { Id = operationClaim.Id, Name = operationClaim.Name }; 22 | return result.ToList(); 23 | 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /WebAPI/Program.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Extensions.DependencyInjection; 3 | using Business.DependencyResolvers.Autofac; 4 | using Microsoft.AspNetCore.Hosting; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.Extensions.Hosting; 7 | using Microsoft.Extensions.Logging; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | using System.Threading.Tasks; 12 | 13 | namespace WebAPI 14 | { 15 | public class Program 16 | { 17 | public static void Main(string[] args) 18 | { 19 | CreateHostBuilder(args).Build().Run(); 20 | } 21 | 22 | public static IHostBuilder CreateHostBuilder(string[] args) => 23 | Host.CreateDefaultBuilder(args) 24 | .UseServiceProviderFactory(new AutofacServiceProviderFactory()) 25 | .ConfigureContainer(builder => 26 | { 27 | builder.RegisterModule(new AutofacBusinessModule()); 28 | }) 29 | .ConfigureWebHostDefaults(webBuilder => 30 | { 31 | webBuilder.UseStartup(); 32 | }); 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Performance/PerformanceAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.Utilities.Interceptors; 3 | using Core.Utilities.IoC; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using System.Diagnostics; 6 | 7 | namespace Core.Aspects.Autofac.Performance 8 | { 9 | public class PerformanceAspect : MethodInterception 10 | { 11 | private int _interval; 12 | private Stopwatch _stopwatch; 13 | 14 | public PerformanceAspect(int interval) 15 | { 16 | _interval = interval; 17 | _stopwatch = ServiceTool.ServiceProvider.GetService(); 18 | } 19 | 20 | 21 | protected override void OnBefore(IInvocation invocation) 22 | { 23 | _stopwatch.Start(); 24 | } 25 | 26 | protected override void OnAfter(IInvocation invocation) 27 | { 28 | if (_stopwatch.Elapsed.TotalSeconds > _interval) 29 | { 30 | Debug.WriteLine($"Performance : {invocation.Method.DeclaringType.FullName}.{invocation.Method.Name}-->{_stopwatch.Elapsed.TotalSeconds}"); 31 | } 32 | _stopwatch.Reset(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Core/Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /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/Utilities/Security/Hashing/HashingHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Core.Utilities.Security.Hashing 6 | { 7 | public class HashingHelper 8 | { 9 | public static void CreatePasswordHash(string password, out byte[] passwordHash, out byte[] passwordSalt) 10 | { 11 | using (var hmac = new System.Security.Cryptography.HMACSHA512()) 12 | { 13 | passwordSalt = hmac.Key; 14 | passwordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(password)); 15 | } 16 | } 17 | public static bool VerifyPasswordHash(string password, byte[] passwordHash, byte[] passwordSalt) 18 | { 19 | using (var hmac = new System.Security.Cryptography.HMACSHA512(passwordSalt)) 20 | { 21 | var computedHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(password)); 22 | for (int i = 0; i < computedHash.Length; i++) 23 | { 24 | if (computedHash[i] != passwordHash[i]) 25 | { 26 | return false; 27 | } 28 | } 29 | } 30 | return true; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Business/BusinessAspects/Autofac/SecuredOperation.cs: -------------------------------------------------------------------------------- 1 | using Business.Constants; 2 | using Castle.DynamicProxy; 3 | using Core.Extensions; 4 | using Core.Utilities.Interceptors; 5 | using Core.Utilities.IoC; 6 | using Microsoft.AspNetCore.Http; 7 | using System; 8 | using Microsoft.Extensions.DependencyInjection; 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; 34 | } 35 | } 36 | throw new Exception(Messages.AuthorizationDenied); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /WebAPI/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace WebAPI.Controllers 9 | { 10 | [ApiController] 11 | [Route("[controller]")] 12 | public class WeatherForecastController : ControllerBase 13 | { 14 | private static readonly string[] Summaries = new[] 15 | { 16 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 17 | }; 18 | 19 | private readonly ILogger _logger; 20 | 21 | public WeatherForecastController(ILogger logger) 22 | { 23 | _logger = logger; 24 | } 25 | 26 | [HttpGet] 27 | public IEnumerable Get() 28 | { 29 | var rng = new Random(); 30 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 31 | { 32 | Date = DateTime.Now.AddDays(index), 33 | TemperatureC = rng.Next(-20, 55), 34 | Summary = Summaries[rng.Next(Summaries.Length)] 35 | }) 36 | .ToArray(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Validation/ValidationAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.CrossCuttingConcerns.Validation; 3 | using Core.Utilities.Interceptors; 4 | using Core.Utilities.Messages; 5 | using FluentValidation; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Text; 10 | 11 | namespace Core.Aspects.Autofac.Validation 12 | { 13 | public class ValidationAspect : MethodInterception 14 | { 15 | private Type _validatorType; 16 | public ValidationAspect(Type validatorType) 17 | { 18 | if (!typeof(IValidator).IsAssignableFrom(validatorType)) 19 | { 20 | throw new System.Exception(AspectMessages.WrongValidationType); 21 | } 22 | 23 | _validatorType = validatorType; 24 | } 25 | protected override void OnBefore(IInvocation invocation) 26 | { 27 | var validator = (IValidator)Activator.CreateInstance(_validatorType); 28 | var entityType = _validatorType.BaseType.GetGenericArguments()[0]; 29 | var entities = invocation.Arguments.Where(t => t.GetType() == entityType); 30 | foreach (var entity in entities) 31 | { 32 | ValidationTool.Validate(validator, entity); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /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.Linq; 7 | 8 | namespace Core.Aspects.Autofac.Caching 9 | { 10 | public class CacheAspect : MethodInterception 11 | { 12 | private int _duration; 13 | private ICacheManager _cacheManager; 14 | 15 | public CacheAspect(int duration = 60) 16 | { 17 | _duration = duration; 18 | _cacheManager = ServiceTool.ServiceProvider.GetService(); 19 | } 20 | 21 | public override void Intercept(IInvocation invocation) 22 | { 23 | var methodName = string.Format($"{invocation.Method.ReflectedType.FullName}.{invocation.Method.Name}"); 24 | var arguments = invocation.Arguments.ToList(); 25 | var key = $"{methodName}({string.Join(",", arguments.Select(x => x?.ToString() ?? ""))})"; 26 | if (_cacheManager.IsAdd(key)) 27 | { 28 | invocation.ReturnValue = _cacheManager.Get(key); 29 | return; 30 | } 31 | invocation.Proceed(); 32 | _cacheManager.Add(key, invocation.ReturnValue, _duration); 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 (SouthwindContext context = new SouthwindContext()) 19 | { 20 | var result = from c in context.Cars 21 | join b in context.Brands 22 | on c.BrandId equals b.Id 23 | join co in context.Colors 24 | on c.ColorId equals co.Id 25 | select new CarDetailDto 26 | { 27 | CarId = c.Id, 28 | CarName = c.Name, 29 | BrandName = b.Name, 30 | ColorName = co.Name, 31 | DailyPrice = c.DailyPrice 32 | }; 33 | return result.ToList(); 34 | } 35 | 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Core/Aspects/Autofac/Logging/LogAspect.cs: -------------------------------------------------------------------------------- 1 | using Castle.DynamicProxy; 2 | using Core.CrossCuttingConcerns.Logging; 3 | using Core.CrossCuttingConcerns.Logging.Log4Net; 4 | using Core.Utilities.Interceptors; 5 | using Core.Utilities.Messages; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | 10 | namespace Core.Aspects.Autofac.Logging 11 | { 12 | public class LogAspect : MethodInterception 13 | { 14 | private LoggerServiceBase _loggerServiceBase; 15 | 16 | public LogAspect(Type loggerService) 17 | { 18 | if (loggerService.BaseType != typeof(LoggerServiceBase)) 19 | { 20 | throw new System.Exception(AspectMessages.WrongLoggerType); 21 | } 22 | 23 | _loggerServiceBase = (LoggerServiceBase)Activator.CreateInstance(loggerService); 24 | } 25 | 26 | protected override void OnBefore(IInvocation invocation) 27 | { 28 | _loggerServiceBase.Info(GetLogDetail(invocation)); 29 | } 30 | 31 | private LogDetail GetLogDetail(IInvocation invocation) 32 | { 33 | var logParameters = new List(); 34 | for (int i = 0; i < invocation.Arguments.Length; i++) 35 | { 36 | logParameters.Add(new LogParameter 37 | { 38 | Name = invocation.GetConcreteMethod().GetParameters()[i].Name, 39 | Value = invocation.Arguments[i], 40 | Type = invocation.Arguments[i].GetType().Name 41 | }); 42 | } 43 | 44 | var logDetail = new LogDetail 45 | { 46 | MethodName = invocation.Method.Name, 47 | LogParameters = logParameters 48 | }; 49 | 50 | return logDetail; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /WebAPI/log4net.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /WebAPI/Controllers/AuthController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.DTOs; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class AuthController : Controller 15 | { 16 | private IAuthService _authService; 17 | 18 | public AuthController(IAuthService authService) 19 | { 20 | _authService = authService; 21 | } 22 | 23 | [HttpPost("login")] 24 | public ActionResult Login(UserForLoginDto userForLoginDto) 25 | { 26 | var userToLogin = _authService.Login(userForLoginDto); 27 | if (!userToLogin.Success) 28 | { 29 | return BadRequest(userToLogin.Message); 30 | } 31 | 32 | var result = _authService.CreateAccessToken(userToLogin.Data); 33 | if (result.Success) 34 | { 35 | return Ok(result.Data); 36 | } 37 | 38 | return BadRequest(result.Message); 39 | } 40 | 41 | [HttpPost("register")] 42 | public ActionResult Register(UserForRegisterDto userForRegisterDto) 43 | { 44 | var userExists = _authService.UserExists(userForRegisterDto.Email); 45 | if (!userExists.Success) 46 | { 47 | return BadRequest(userExists.Message); 48 | } 49 | 50 | var registerResult = _authService.Register(userForRegisterDto, userForRegisterDto.Password); 51 | var result = _authService.CreateAccessToken(registerResult.Data); 52 | if (result.Success) 53 | { 54 | return Ok(result.Data); 55 | } 56 | 57 | return BadRequest(result.Message); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /WebAPI/Controllers/UsersController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Core.Entities.Concrete; 3 | using Microsoft.AspNetCore.Mvc; 4 | 5 | namespace WebAPI.Controllers 6 | { 7 | [Route("api/[controller]")] 8 | [ApiController] 9 | public class UsersController : ControllerBase 10 | { 11 | IUserService _userService; 12 | 13 | public UsersController(IUserService userService) 14 | { 15 | _userService = userService; 16 | } 17 | [HttpGet("getall")] 18 | public IActionResult GetAll() 19 | { 20 | var result = _userService.GetAll(); 21 | if (result.Success) 22 | { 23 | return Ok(result); 24 | } 25 | return BadRequest(result); 26 | } 27 | [HttpGet("getbyid")] 28 | public IActionResult GetById(int userId) 29 | { 30 | var result = _userService.GetById(userId); 31 | if (result.Success) 32 | { 33 | return Ok(result); 34 | } 35 | return BadRequest(result); 36 | } 37 | [HttpPost("add")] 38 | public IActionResult Add(User user) 39 | { 40 | var result = _userService.Add(user); 41 | if (result.Success) 42 | { 43 | return Ok(result); 44 | } 45 | return BadRequest(result); 46 | } 47 | [HttpPost("delete")] 48 | public IActionResult Delete(User user) 49 | { 50 | var result = _userService.Delete(user); 51 | if (result.Success) 52 | { 53 | return Ok(result); 54 | } 55 | return BadRequest(result); 56 | } 57 | [HttpPost("update")] 58 | public IActionResult Update(User user) 59 | { 60 | var result = _userService.Update(user); 61 | if (result.Success) 62 | { 63 | return Ok(result); 64 | } 65 | return BadRequest(result); 66 | } 67 | 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Logging/Log4Net/LoggerServiceBase.cs: -------------------------------------------------------------------------------- 1 | using log4net; 2 | using log4net.Repository; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Reflection; 7 | using System.Text; 8 | using System.Xml; 9 | 10 | namespace Core.CrossCuttingConcerns.Logging.Log4Net 11 | { 12 | public class LoggerServiceBase 13 | { 14 | private ILog _log; 15 | public LoggerServiceBase(string name) 16 | { 17 | XmlDocument xmlDocument = new XmlDocument(); 18 | xmlDocument.Load(File.OpenRead("log4net.config")); 19 | 20 | ILoggerRepository loggerRepository = LogManager.CreateRepository(Assembly.GetEntryAssembly(), 21 | typeof(log4net.Repository.Hierarchy.Hierarchy)); 22 | log4net.Config.XmlConfigurator.Configure(loggerRepository, xmlDocument["log4net"]); 23 | 24 | _log = LogManager.GetLogger(loggerRepository.Name, name); 25 | 26 | 27 | } 28 | 29 | public bool IsInfoEnabled => _log.IsInfoEnabled; 30 | public bool IsDebugEnabled => _log.IsDebugEnabled; 31 | public bool IsWarnEnabled => _log.IsWarnEnabled; 32 | public bool IsFatalEnabled => _log.IsFatalEnabled; 33 | public bool IsErrorEnabled => _log.IsErrorEnabled; 34 | 35 | public void Info(object logMessage) 36 | { 37 | if (IsInfoEnabled) 38 | _log.Info(logMessage); 39 | } 40 | 41 | public void Debug(object logMessage) 42 | { 43 | if (IsDebugEnabled) 44 | _log.Debug(logMessage); 45 | } 46 | 47 | public void Warn(object logMessage) 48 | { 49 | if (IsWarnEnabled) 50 | _log.Warn(logMessage); 51 | } 52 | 53 | public void Fatal(object logMessage) 54 | { 55 | if (IsFatalEnabled) 56 | _log.Fatal(logMessage); 57 | } 58 | 59 | public void Error(object logMessage) 60 | { 61 | if (IsErrorEnabled) 62 | _log.Error(logMessage); 63 | } 64 | 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Core/Utilities/FileOperation/FileOperation.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.Results; 2 | using Microsoft.AspNetCore.Http; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | 9 | namespace Core.Utilities.FileOperation 10 | { 11 | public class FileOperation 12 | { 13 | public IFormFile files { get; set; } 14 | public string carImages { get; set; } 15 | 16 | //public static IDataResult UploadFile(IFormFile file) 17 | //{ 18 | 19 | // var sourcePath = Path.GetTempFileName(); 20 | 21 | // if (!Directory.Exists(sourcePath)) 22 | // { 23 | // Directory.CreateDirectory(sourcePath); 24 | // } 25 | 26 | // if (file.Length > 0) 27 | // using (var stream = new FileStream(sourcePath, FileMode.Create)) 28 | // file.CopyTo(stream); 29 | 30 | // var result = CreateGuid(file).Data; 31 | 32 | // File.Move(sourcePath, result); 33 | 34 | // return new SuccessDataResult(result); 35 | //} 36 | 37 | //public static IDataResult UpdateFile(string sourcePath, IFormFile file) 38 | //{ 39 | // var result = CreateGuid(file).Data; 40 | 41 | // File.Copy(sourcePath, result); 42 | 43 | // File.Delete(sourcePath); 44 | 45 | // return new SuccessDataResult(result); 46 | 47 | //} 48 | 49 | //public static IDataResult CreateGuid(IFormFile file) 50 | //{ 51 | // string[] fileNameSplit = file.FileName.Split('.'); 52 | // var extensionOfFile = "." + fileNameSplit[fileNameSplit.Length - 1]; 53 | // var newImageFileName = DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Year + "_" 54 | // + Guid.NewGuid().ToString() + extensionOfFile; 55 | 56 | // string path = Path.Combine(Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).FullName + @"\uploads"); 57 | 58 | // string result = $@"{path}\{newImageFileName}"; 59 | 60 | // return new SuccessDataResult(result); 61 | 62 | //} 63 | 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /WebAPI/Controllers/BrandsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class BrandsController : ControllerBase 15 | { 16 | IBrandService _brandService; 17 | 18 | public BrandsController(IBrandService brandService) 19 | { 20 | _brandService = brandService; 21 | } 22 | [HttpGet("getall")] 23 | public IActionResult GetAll() 24 | { 25 | var result = _brandService.GetAll(); 26 | if (result.Success) 27 | { 28 | return Ok(result); 29 | } 30 | return BadRequest(result); 31 | } 32 | [HttpGet("getbyid")] 33 | public IActionResult GetById(int brandId) 34 | { 35 | var result = _brandService.GetById(brandId); 36 | if (result.Success) 37 | { 38 | return Ok(result); 39 | } 40 | return BadRequest(result); 41 | } 42 | [HttpPost("add")] 43 | public IActionResult Add(Brand brand) 44 | { 45 | var result = _brandService.Add(brand); 46 | if (result.Success) 47 | { 48 | return Ok(result); 49 | } 50 | return BadRequest(result); 51 | } 52 | [HttpPost("delete")] 53 | public IActionResult Delete(Brand brand) 54 | { 55 | var result = _brandService.Delete(brand); 56 | if (result.Success) 57 | { 58 | return Ok(result); 59 | } 60 | return BadRequest(result); 61 | } 62 | [HttpPost("update")] 63 | public IActionResult Update(Brand brand) 64 | { 65 | var result = _brandService.Update(brand); 66 | if (result.Success) 67 | { 68 | return Ok(result); 69 | } 70 | return BadRequest(result); 71 | } 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /WebAPI/Controllers/ColorsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class ColorsController : ControllerBase 15 | { 16 | IColorService _colorService; 17 | 18 | public ColorsController(IColorService colorService) 19 | { 20 | _colorService = colorService; 21 | } 22 | [HttpGet("getall")] 23 | public IActionResult GetAll() 24 | { 25 | var result = _colorService.GetAll(); 26 | if (result.Success) 27 | { 28 | return Ok(result); 29 | } 30 | return BadRequest(result); 31 | } 32 | [HttpGet("getbyid")] 33 | public IActionResult GetById(int colorId) 34 | { 35 | var result = _colorService.GetById(colorId); 36 | if (result.Success) 37 | { 38 | return Ok(result); 39 | } 40 | return BadRequest(result); 41 | } 42 | [HttpPost("add")] 43 | public IActionResult Add(Color color) 44 | { 45 | var result = _colorService.Add(color); 46 | if (result.Success) 47 | { 48 | return Ok(result); 49 | } 50 | return BadRequest(result); 51 | } 52 | [HttpPost("delete")] 53 | public IActionResult Delete(Color color) 54 | { 55 | var result = _colorService.Delete(color); 56 | if (result.Success) 57 | { 58 | return Ok(result); 59 | } 60 | return BadRequest(result); 61 | } 62 | [HttpPost("update")] 63 | public IActionResult Update(Color color) 64 | { 65 | var result = _colorService.Update(color); 66 | if (result.Success) 67 | { 68 | return Ok(result); 69 | } 70 | return BadRequest(result); 71 | } 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Core/DataAccess/EntityFramework/EfEntityRepositoryBase.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities; 2 | using Microsoft.EntityFrameworkCore; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Linq.Expressions; 7 | using System.Text; 8 | 9 | namespace Core.DataAccess.EntityFramework 10 | { 11 | public class EfEntityRepositoryBase : IEntityRepository 12 | where TEntity : class, IEntity, new() 13 | where TContext : DbContext, new() 14 | { 15 | public void Add(TEntity entity) 16 | { 17 | using (TContext context = new TContext()) 18 | { 19 | var addedEntity = context.Entry(entity); 20 | addedEntity.State = EntityState.Added; 21 | context.SaveChanges(); 22 | } 23 | } 24 | 25 | public void Delete(TEntity entity) 26 | { 27 | using (TContext context = new TContext()) 28 | { 29 | var deletedEntity = context.Entry(entity); 30 | deletedEntity.State = EntityState.Deleted; 31 | context.SaveChanges(); 32 | } 33 | } 34 | 35 | public TEntity Get(Expression> filter) 36 | { 37 | using (TContext context = new TContext()) 38 | { 39 | return context.Set().SingleOrDefault(filter); 40 | } 41 | } 42 | 43 | public List GetAll(Expression> filter = null) 44 | { 45 | using (TContext context = new TContext()) 46 | { 47 | return filter == null 48 | ? context.Set().ToList() //filter null ise burası calıstır 49 | : context.Set().Where(filter).ToList(); //filter var ise filtreyi where ile ekleyip calıstır 50 | } 51 | } 52 | 53 | public void Update(TEntity entity) 54 | { 55 | using (TContext context = new TContext()) 56 | { 57 | var updatedEntity = context.Entry(entity); 58 | updatedEntity.State = EntityState.Modified; 59 | context.SaveChanges(); 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CustomersController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class CustomersController : ControllerBase 15 | { 16 | ICustomerService _customerService; 17 | 18 | public CustomersController(ICustomerService customerService) 19 | { 20 | _customerService = customerService; 21 | } 22 | [HttpGet("getall")] 23 | public IActionResult GetAll() 24 | { 25 | var result = _customerService.GetAll(); 26 | if (result.Success) 27 | { 28 | return Ok(result); 29 | } 30 | return BadRequest(result); 31 | } 32 | [HttpGet("getbyid")] 33 | public IActionResult GetById(int customerId) 34 | { 35 | var result = _customerService.GetById(customerId); 36 | if (result.Success) 37 | { 38 | return Ok(result); 39 | } 40 | return BadRequest(result); 41 | } 42 | [HttpPost("add")] 43 | public IActionResult Add(Customer customer) 44 | { 45 | var result = _customerService.Add(customer); 46 | if (result.Success) 47 | { 48 | return Ok(result); 49 | } 50 | return BadRequest(result); 51 | } 52 | [HttpPost("delete")] 53 | public IActionResult Delete(Customer customer) 54 | { 55 | var result = _customerService.Delete(customer); 56 | if (result.Success) 57 | { 58 | return Ok(result); 59 | } 60 | return BadRequest(result); 61 | } 62 | [HttpPost("update")] 63 | public IActionResult Update(Customer customer) 64 | { 65 | var result = _customerService.Update(customer); 66 | if (result.Success) 67 | { 68 | return Ok(result); 69 | } 70 | return BadRequest(result); 71 | } 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Core/CrossCuttingConcerns/Caching/Microsoft/MemoryCacheManager.cs: -------------------------------------------------------------------------------- 1 | using Core.Utilities.IoC; 2 | using Microsoft.Extensions.Caching.Memory; 3 | using System; 4 | using System.Collections.Generic; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using System.Text.RegularExpressions; 7 | using System.Linq; 8 | 9 | namespace Core.CrossCuttingConcerns.Caching.Microsoft 10 | { 11 | public class MemoryCacheManager : ICacheManager 12 | { 13 | private IMemoryCache _cache; 14 | public MemoryCacheManager() 15 | { 16 | _cache = ServiceTool.ServiceProvider.GetService(); 17 | } 18 | public T Get(string key) 19 | { 20 | return _cache.Get(key); 21 | } 22 | 23 | public object Get(string key) 24 | { 25 | return _cache.Get(key); 26 | } 27 | 28 | public void Add(string key, object data, int duration) 29 | { 30 | _cache.Set(key, data, TimeSpan.FromMinutes(duration)); 31 | } 32 | 33 | public bool IsAdd(string key) 34 | { 35 | return _cache.TryGetValue(key, out _); 36 | } 37 | 38 | public void Remove(string key) 39 | { 40 | _cache.Remove(key); 41 | } 42 | 43 | public void RemoveByPattern(string pattern) 44 | { 45 | var cacheEntriesCollectionDefinition = typeof(MemoryCache).GetProperty("EntriesCollection", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); 46 | var cacheEntriesCollection = cacheEntriesCollectionDefinition.GetValue(_cache) as dynamic; 47 | List cacheCollectionValues = new List(); 48 | 49 | foreach (var cacheItem in cacheEntriesCollection) 50 | { 51 | ICacheEntry cacheItemValue = cacheItem.GetType().GetProperty("Value").GetValue(cacheItem, null); 52 | cacheCollectionValues.Add(cacheItemValue); 53 | } 54 | 55 | var regex = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase); 56 | var keysToRemove = cacheCollectionValues.Where(d => regex.IsMatch(d.Key.ToString())).Select(d => d.Key).ToList(); 57 | 58 | foreach (var key in keysToRemove) 59 | { 60 | _cache.Remove(key); 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Business/DependencyResolvers/Autofac/AutofacBusinessModule.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Extras.DynamicProxy; 3 | using Business.Abstract; 4 | using Business.Concrete; 5 | using Castle.DynamicProxy; 6 | using Core.Utilities.Interceptors; 7 | using Core.Utilities.Security.Jwt; 8 | using DataAccess.Abstract; 9 | using DataAccess.Concrete.EntityFrameWork; 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Text; 13 | 14 | namespace Business.DependencyResolvers.Autofac 15 | { 16 | public class AutofacBusinessModule : Module 17 | { 18 | protected override void Load(ContainerBuilder builder) 19 | { 20 | builder.RegisterType().As().SingleInstance(); 21 | builder.RegisterType().As().SingleInstance(); 22 | builder.RegisterType().As().SingleInstance(); 23 | builder.RegisterType().As().SingleInstance(); 24 | builder.RegisterType().As().SingleInstance(); 25 | builder.RegisterType().As().SingleInstance(); 26 | builder.RegisterType().As().SingleInstance(); 27 | builder.RegisterType().As().SingleInstance(); 28 | builder.RegisterType().As().SingleInstance(); 29 | builder.RegisterType().As().SingleInstance(); 30 | builder.RegisterType().As().SingleInstance(); 31 | builder.RegisterType().As().SingleInstance(); 32 | builder.RegisterType().As().SingleInstance(); 33 | builder.RegisterType().As().SingleInstance(); 34 | builder.RegisterType().As(); 35 | builder.RegisterType().As(); 36 | builder.RegisterType().As(); 37 | builder.RegisterType().As(); 38 | 39 | var assembly = System.Reflection.Assembly.GetExecutingAssembly(); 40 | 41 | builder.RegisterAssemblyTypes(assembly).AsImplementedInterfaces() 42 | .EnableInterfaceInterceptors(new ProxyGenerationOptions() 43 | { 44 | Selector = new AspectInterceptorSelector() 45 | }).SingleInstance(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Business/Concrete/BrandManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Business.ValidationRules.FluentValidation; 4 | using Core.Aspects.Autofac.Validation; 5 | using Core.Utilities.Results; 6 | using DataAccess.Abstract; 7 | using Entities.Concrete; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Text; 11 | 12 | namespace Business.Concrete 13 | { 14 | public class BrandManager : IBrandService 15 | { 16 | 17 | IBrandDal _brandDal; 18 | 19 | public BrandManager(IBrandDal brandDal) 20 | { 21 | _brandDal = brandDal; 22 | } 23 | [ValidationAspect(typeof(BrandValidator))] 24 | public IResult Add(Brand brand) 25 | { 26 | if (!IsExist(brand.Id).Success) 27 | { 28 | _brandDal.Add(brand); 29 | return new SuccessResult(Messages.BrandAdded); 30 | } 31 | return new ErrorResult(Messages.BrandExists); 32 | } 33 | 34 | public IResult Delete(Brand brand) 35 | { 36 | if (IsExist(brand.Id).Success) 37 | { 38 | _brandDal.Delete(brand); 39 | return new SuccessResult(Messages.BrandDeleted); 40 | } 41 | return new ErrorResult(Messages.BrandNotFound); 42 | } 43 | 44 | public IDataResult> GetAll() 45 | { 46 | 47 | return new SuccessDataResult>(_brandDal.GetAll(), Messages.BrandListed); 48 | } 49 | 50 | 51 | public IDataResult GetById(int Id) 52 | { 53 | return new SuccessDataResult(_brandDal.Get(p => p.Id == Id), Messages.BrandListed); 54 | } 55 | 56 | public IResult IsExist(int brandId) 57 | { 58 | var brandExist = GetById(brandId); 59 | if (brandExist.Data != null) 60 | { 61 | return new SuccessResult(Messages.BrandExists); 62 | } 63 | return new ErrorResult(Messages.BrandNotFound); 64 | } 65 | 66 | public IResult Update(Brand brand) 67 | { 68 | 69 | //var brandExist = GetById(brand.Id); //Check if the record exist 70 | if (IsExist(brand.Id).Success) 71 | { 72 | _brandDal.Update(brand); 73 | return new SuccessResult(Messages.BrandUpdated); 74 | } 75 | return new ErrorResult(Messages.BrandNotFound); 76 | 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Business/Concrete/ColorManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Business.ValidationRules.FluentValidation; 4 | using Core.Aspects.Autofac.Validation; 5 | using Core.Utilities.Results; 6 | using DataAccess.Abstract; 7 | using Entities.Concrete; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Text; 11 | 12 | namespace Business.Concrete 13 | { 14 | public class ColorManager : IColorService 15 | { 16 | 17 | IColorDal _colorDal; 18 | 19 | public ColorManager(IColorDal colorDal) 20 | { 21 | _colorDal = colorDal; 22 | } 23 | [ValidationAspect(typeof(ColorValidator))] 24 | public IResult Add(Color color) 25 | { 26 | if (!IsExist(color.Id).Success) 27 | { 28 | _colorDal.Add(color); 29 | return new SuccessResult(Messages.ColorAdded); 30 | } 31 | return new ErrorResult(Messages.ColorExists); 32 | } 33 | 34 | public IResult Delete(Color color) 35 | { 36 | if (IsExist(color.Id).Success) 37 | { 38 | _colorDal.Delete(color); 39 | return new SuccessResult(Messages.ColorDeleted); 40 | } 41 | return new ErrorResult(Messages.ColorNotFound); 42 | } 43 | 44 | public IDataResult> GetAll() 45 | { 46 | //Is Kodları 47 | //Yetki ve is kontrolleri yapıldıktan sonra aşağıdaki kodlar çalışacak 48 | 49 | return new SuccessDataResult>(_colorDal.GetAll(),Messages.ColorListed); 50 | } 51 | 52 | 53 | public IDataResult GetById(int Id) 54 | { 55 | return new SuccessDataResult(_colorDal.Get(p => p.Id == Id),Messages.ColorListed); 56 | } 57 | 58 | public IResult IsExist(int colorId) 59 | { 60 | var colorExist = GetById(colorId); 61 | if (colorExist.Data != null) 62 | { 63 | return new SuccessResult(Messages.ColorExists); 64 | } 65 | return new ErrorResult(Messages.ColorNotFound); 66 | } 67 | 68 | public IResult Update(Color color) 69 | { 70 | if (IsExist(color.Id).Success) 71 | { 72 | _colorDal.Update(color); 73 | return new SuccessResult(Messages.ColorUpdated); 74 | } 75 | return new ErrorResult(Messages.ColorNotFound); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /WebAPI/Controllers/RentalsController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Entities.Concrete; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace WebAPI.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class RentalsController : ControllerBase 15 | { 16 | IRentalService _rentalService; 17 | 18 | public RentalsController(IRentalService rentalService) 19 | { 20 | _rentalService = rentalService; 21 | } 22 | [HttpGet("getall")] 23 | public IActionResult GetAll() 24 | { 25 | var result = _rentalService.GetAll(); 26 | if (result.Success) 27 | { 28 | return Ok(result); 29 | } 30 | return BadRequest(result); 31 | } 32 | [HttpGet("getbyid")] 33 | public IActionResult GetById(int rentalId) 34 | { 35 | var result = _rentalService.GetById(rentalId); 36 | if (result.Success) 37 | { 38 | return Ok(result); 39 | } 40 | return BadRequest(result); 41 | } 42 | [HttpPost("add")] 43 | public IActionResult Add(Rental rental) 44 | { 45 | var result = _rentalService.Add(rental); 46 | if (result.Success) 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) 57 | { 58 | return Ok(result); 59 | } 60 | return BadRequest(result); 61 | } 62 | [HttpPost("endrental")] 63 | public IActionResult EndRental(Rental rental) 64 | { 65 | var result = _rentalService.EndRental(rental); 66 | if (result.Success) 67 | { 68 | return Ok(result); 69 | } 70 | return BadRequest(result); 71 | } 72 | [HttpPost("update")] 73 | public IActionResult Update(Rental rental) 74 | { 75 | var result = _rentalService.Update(rental); 76 | if (result.Success) 77 | { 78 | return Ok(result); 79 | } 80 | return BadRequest(result); 81 | } 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /Business/Concrete/CustomerManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Business.ValidationRules.FluentValidation; 4 | using Core.Aspects.Autofac.Validation; 5 | using Core.Utilities.Results; 6 | using DataAccess.Abstract; 7 | using Entities.Concrete; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Text; 11 | 12 | namespace Business.Concrete 13 | { 14 | public class CustomerManager : ICustomerService 15 | { 16 | 17 | ICustomerDal _customerDal; 18 | 19 | public CustomerManager(ICustomerDal customerDal) 20 | { 21 | _customerDal = customerDal; 22 | } 23 | [ValidationAspect(typeof(CustomerValidator))] 24 | public IResult Add(Customer customer) 25 | { 26 | if (!IsExist(customer.Id).Success) 27 | { 28 | //if (customer.CompanyName.Length >= 2) 29 | //{ 30 | _customerDal.Add(customer); 31 | return new SuccessResult(Messages.CustomerAdded); 32 | //} 33 | //return new ErrorResult(Messages.CustomerNameInvalid); 34 | } 35 | return new ErrorResult(Messages.CustomerExists); 36 | } 37 | 38 | public IResult Delete(Customer customer) 39 | { 40 | if (IsExist(customer.Id).Success) 41 | { 42 | _customerDal.Delete(customer); 43 | return new SuccessResult(Messages.CustomerDeleted); 44 | } 45 | return new ErrorResult(Messages.CustomerNotFound); 46 | } 47 | 48 | public IDataResult> GetAll() 49 | { 50 | 51 | return new SuccessDataResult>(_customerDal.GetAll(), Messages.CustomerListed); 52 | } 53 | 54 | 55 | public IDataResult GetById(int Id) 56 | { 57 | return new SuccessDataResult(_customerDal.Get(p => p.Id == Id), Messages.CustomerListed); 58 | } 59 | 60 | public IResult IsExist(int customerId) 61 | { 62 | var customerExist = GetById(customerId); 63 | if (customerExist.Data != null) 64 | { 65 | return new SuccessResult(Messages.CustomerExists); 66 | } 67 | return new ErrorResult(Messages.CustomerNotFound); 68 | } 69 | 70 | public IResult Update(Customer customer) 71 | { 72 | if (IsExist(customer.Id).Success) 73 | { 74 | _customerDal.Update(customer); 75 | return new SuccessResult(Messages.CustomerUpdated); 76 | } 77 | return new ErrorResult(Messages.CustomerNotFound); 78 | 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /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).Data; 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).Data; 70 | var accessToken = _tokenHelper.CreateToken(user, claims); 71 | return new SuccessDataResult(accessToken, Messages.AccessTokenCreated); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Core/Utilities/Security/Jwt/JwtHelper.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using Core.Extensions; 3 | using Core.Utilities.Security.Encryption; 4 | using Microsoft.Extensions.Configuration; 5 | using Microsoft.IdentityModel.Tokens; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.IdentityModel.Tokens.Jwt; 9 | using System.Linq; 10 | using System.Security.Claims; 11 | using System.Text; 12 | 13 | namespace Core.Utilities.Security.Jwt 14 | { 15 | public class JwtHelper : ITokenHelper 16 | { 17 | public IConfiguration Configuration { get; } 18 | private TokenOptions _tokenOptions; 19 | private DateTime _accessTokenExpiration; 20 | public JwtHelper(IConfiguration configuration) 21 | { 22 | Configuration = configuration; 23 | _tokenOptions = Configuration.GetSection("TokenOptions").Get(); 24 | 25 | } 26 | public AccessToken CreateToken(User user, List operationClaims) 27 | { 28 | _accessTokenExpiration = DateTime.Now.AddMinutes(_tokenOptions.AccessTokenExpiration); 29 | var securityKey = SecurityKeyHelper.CreateSecurityKey(_tokenOptions.SecurityKey); 30 | var signingCredentials = SigningCredentialsHelper.CreateSigningCredentials(securityKey); 31 | var jwt = CreateJwtSecurityToken(_tokenOptions, user, signingCredentials, operationClaims); 32 | var jwtSecurityTokenHandler = new JwtSecurityTokenHandler(); 33 | var token = jwtSecurityTokenHandler.WriteToken(jwt); 34 | 35 | return new AccessToken 36 | { 37 | Token = token, 38 | Expiration = _accessTokenExpiration 39 | }; 40 | 41 | } 42 | 43 | public JwtSecurityToken CreateJwtSecurityToken(TokenOptions tokenOptions, User user, 44 | SigningCredentials signingCredentials, List operationClaims) 45 | { 46 | var jwt = new JwtSecurityToken( 47 | issuer: tokenOptions.Issuer, 48 | audience: tokenOptions.Audience, 49 | expires: _accessTokenExpiration, 50 | notBefore: DateTime.Now, 51 | claims: SetClaims(user, operationClaims), 52 | signingCredentials: signingCredentials 53 | ); 54 | return jwt; 55 | } 56 | 57 | private IEnumerable SetClaims(User user, List operationClaims) 58 | { 59 | var claims = new List(); 60 | claims.AddNameIdentifier(user.Id.ToString()); 61 | claims.AddEmail(user.Email); 62 | claims.AddName($"{user.FirstName} {user.LastName}"); 63 | claims.AddRoles(operationClaims.Select(c => c.Name).ToArray()); 64 | 65 | return claims; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /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.Collections.Generic; 10 | 11 | namespace Business.Concrete 12 | { 13 | public class UserManager : IUserService 14 | { 15 | 16 | IUserDal _userDal; 17 | 18 | public UserManager(IUserDal userDal) 19 | { 20 | _userDal = userDal; 21 | } 22 | [ValidationAspect(typeof(UserValidator))] 23 | public IResult Add(User user) 24 | { 25 | var result = BusinessRules.Run(IsExist(user.Id)); 26 | if (result == null) 27 | { 28 | return result; 29 | } 30 | _userDal.Add(user); 31 | return new SuccessResult(Messages.UserAdded); 32 | } 33 | 34 | public IResult Delete(User user) 35 | { 36 | var result = BusinessRules.Run(IsExist(user.Id)); 37 | if (result != null) 38 | { 39 | return result; 40 | } 41 | _userDal.Delete(user); 42 | return new SuccessResult(Messages.UserDeleted); 43 | } 44 | 45 | public IDataResult> GetAll() 46 | { 47 | 48 | return new SuccessDataResult>(_userDal.GetAll(), Messages.UserListed); 49 | } 50 | 51 | public IDataResult GetById(int Id) 52 | { 53 | return new SuccessDataResult(_userDal.Get(p => p.Id == Id), Messages.UserListed); 54 | } 55 | 56 | public IResult Update(User user) 57 | { 58 | var result = BusinessRules.Run(IsExist(user.Id)); 59 | if (result != null) 60 | { 61 | return result; 62 | } 63 | _userDal.Update(user); 64 | return new SuccessResult(Messages.UserUpdated); 65 | } 66 | private IResult IsExist(int userId) 67 | { 68 | var userExist = GetById(userId); 69 | if (userExist.Data != null) 70 | { 71 | return new SuccessResult(Messages.UserExists); 72 | } 73 | return new ErrorResult(Messages.UserNotFound); 74 | } 75 | 76 | public IDataResult> GetClaims(User user) 77 | { 78 | return new SuccessDataResult>(_userDal.GetClaims(user)); 79 | } 80 | 81 | //Refactored 82 | public IDataResult GetByMail(string email) 83 | { 84 | return new SuccessDataResult(_userDal.Get(u => u.Email == email)); 85 | } 86 | //} 87 | 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /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 | 18 | public CarsController(ICarService carService) 19 | { 20 | _carService = carService; 21 | } 22 | [HttpGet("getall")] 23 | public IActionResult GetAll() 24 | { 25 | var result = _carService.GetAll(); 26 | if (result.Success) 27 | { 28 | return Ok(result); 29 | } 30 | return BadRequest(result); 31 | } 32 | [HttpGet("getbyid")] 33 | public IActionResult GetById(int carId) 34 | { 35 | var result = _carService.GetById(carId); 36 | if (result.Success) 37 | { 38 | return Ok(result); 39 | } 40 | return BadRequest(result); 41 | } 42 | [HttpGet("getcarsbybrandid")] 43 | public IActionResult GetCarsByBrandId(int id) 44 | { 45 | var result = _carService.GetCarsByBrandId(id); 46 | if (result.Success) 47 | { 48 | return Ok(result); 49 | } 50 | return BadRequest(result); 51 | } 52 | [HttpGet("getcarsbycolorid")] 53 | public IActionResult GetCarsByColorId(int id) 54 | { 55 | var result = _carService.GetCarsByColorId(id); 56 | if (result.Success) 57 | { 58 | return Ok(result); 59 | } 60 | return BadRequest(result); 61 | } 62 | [HttpGet("getcardetails")] 63 | public IActionResult GetCarDetails() 64 | { 65 | var result = _carService.GetCarDetails(); 66 | if (result.Success) 67 | { 68 | return Ok(result); 69 | } 70 | return BadRequest(result); 71 | } 72 | [HttpPost("add")] 73 | public IActionResult Add(Car car) 74 | { 75 | var result = _carService.Add(car); 76 | if (result.Success) 77 | { 78 | return Ok(result); 79 | } 80 | return BadRequest(result); 81 | } 82 | [HttpPost("delete")] 83 | public IActionResult Delete(Car car) 84 | { 85 | var result = _carService.Delete(car); 86 | if (result.Success) 87 | { 88 | return Ok(result); 89 | } 90 | return BadRequest(result); 91 | } 92 | [HttpPost("update")] 93 | public IActionResult Update(Car car) 94 | { 95 | var result = _carService.Update(car); 96 | if (result.Success) 97 | { 98 | return Ok(result); 99 | } 100 | return BadRequest(result); 101 | } 102 | 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /WebAPI/Startup.cs: -------------------------------------------------------------------------------- 1 | using Core.DependencyResolvers; 2 | using Core.Extensions; 3 | using Core.Utilities.IoC; 4 | using Core.Utilities.Security.Encryption; 5 | using Core.Utilities.Security.Jwt; 6 | using Microsoft.AspNetCore.Authentication.JwtBearer; 7 | using Microsoft.AspNetCore.Builder; 8 | using Microsoft.AspNetCore.Hosting; 9 | using Microsoft.Extensions.Configuration; 10 | using Microsoft.Extensions.DependencyInjection; 11 | using Microsoft.Extensions.Hosting; 12 | using Microsoft.IdentityModel.Tokens; 13 | 14 | 15 | 16 | namespace WebAPI 17 | { 18 | public class Startup 19 | { 20 | public Startup(IConfiguration configuration) 21 | { 22 | Configuration = configuration; 23 | } 24 | 25 | public IConfiguration Configuration { get; } 26 | 27 | // This method gets called by the runtime. Use this method to add services to the container. 28 | public void ConfigureServices(IServiceCollection services) 29 | { 30 | services.AddControllers(); 31 | //services.AddSingleton(); 32 | //services.AddSingleton(); 33 | //services.AddSingleton(); 34 | //services.AddSingleton(); 35 | //services.AddSingleton(); 36 | //services.AddSingleton(); 37 | //services.AddSingleton(); 38 | //services.AddSingleton(); 39 | //services.AddSingleton(); 40 | //services.AddSingleton(); 41 | //services.AddSingleton(); 42 | //services.AddSingleton(); 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 | 60 | //ServiceTool.Create(services); 61 | 62 | services.AddDependencyResolvers(new ICoreModule[] 63 | { 64 | new CoreModule(), 65 | }); 66 | } 67 | 68 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 69 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 70 | { 71 | if (env.IsDevelopment()) 72 | { 73 | app.UseDeveloperExceptionPage(); 74 | } 75 | 76 | app.UseHttpsRedirection(); 77 | 78 | app.UseRouting(); 79 | 80 | app.UseAuthentication(); 81 | 82 | app.UseAuthorization(); 83 | 84 | app.UseEndpoints(endpoints => 85 | { 86 | endpoints.MapControllers(); 87 | }); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /ReCapProject.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30907.101 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Business", "Business\Business.csproj", "{2B9E4ED2-B768-4715-BAA9-BE90A4F1AD05}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAccess", "DataAccess\DataAccess.csproj", "{C1C0F536-697B-4BBD-93AA-7BC9B7ADE76D}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "Entities\Entities.csproj", "{AF8C8376-489A-4E1E-BDCD-8A38AB4C1BCA}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleUI", "ConsoleUI\ConsoleUI.csproj", "{BF614ADB-8895-4DF2-B9D9-4740C8D97192}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{0A343892-DD68-4007-92DF-E614A18DF1A1}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPI", "WebAPI\WebAPI.csproj", "{31307D9A-72F7-4B43-AAAC-A7B5103AD402}" 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 | {2B9E4ED2-B768-4715-BAA9-BE90A4F1AD05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {2B9E4ED2-B768-4715-BAA9-BE90A4F1AD05}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {2B9E4ED2-B768-4715-BAA9-BE90A4F1AD05}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {2B9E4ED2-B768-4715-BAA9-BE90A4F1AD05}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {C1C0F536-697B-4BBD-93AA-7BC9B7ADE76D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {C1C0F536-697B-4BBD-93AA-7BC9B7ADE76D}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {C1C0F536-697B-4BBD-93AA-7BC9B7ADE76D}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {C1C0F536-697B-4BBD-93AA-7BC9B7ADE76D}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {AF8C8376-489A-4E1E-BDCD-8A38AB4C1BCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {AF8C8376-489A-4E1E-BDCD-8A38AB4C1BCA}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {AF8C8376-489A-4E1E-BDCD-8A38AB4C1BCA}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {AF8C8376-489A-4E1E-BDCD-8A38AB4C1BCA}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {BF614ADB-8895-4DF2-B9D9-4740C8D97192}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {BF614ADB-8895-4DF2-B9D9-4740C8D97192}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {BF614ADB-8895-4DF2-B9D9-4740C8D97192}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {BF614ADB-8895-4DF2-B9D9-4740C8D97192}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {0A343892-DD68-4007-92DF-E614A18DF1A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {0A343892-DD68-4007-92DF-E614A18DF1A1}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {0A343892-DD68-4007-92DF-E614A18DF1A1}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {0A343892-DD68-4007-92DF-E614A18DF1A1}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {31307D9A-72F7-4B43-AAAC-A7B5103AD402}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {31307D9A-72F7-4B43-AAAC-A7B5103AD402}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {31307D9A-72F7-4B43-AAAC-A7B5103AD402}.Release|Any CPU.ActiveCfg = Release|Any CPU 47 | {31307D9A-72F7-4B43-AAAC-A7B5103AD402}.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 = {A4855CD5-1199-441A-9E14-850D6D8C6FAB} 54 | EndGlobalSection 55 | EndGlobal 56 | -------------------------------------------------------------------------------- /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 | List _colors; 16 | List _brands; 17 | List _carDetailDtos; 18 | 19 | public InMemoryCarDal() 20 | { 21 | _cars = new List { 22 | new Car{Id=1,BrandId=1,ColorId=1,DailyPrice=300,ModelYear=2019,Name="Symbol"}, 23 | new Car{Id=2,BrandId=1,ColorId=1,DailyPrice=350,ModelYear=2019,Name="Megane"}, 24 | new Car{Id=3,BrandId=2,ColorId=2,DailyPrice=600,ModelYear=2019,Name="A3"}, 25 | new Car{Id=4,BrandId=2,ColorId=3,DailyPrice=800,ModelYear=2019,Name="A5"}, 26 | new Car{Id=5,BrandId=3,ColorId=1,DailyPrice=700,ModelYear=2020,Name="E200"}, 27 | new Car{Id=6,BrandId=3,ColorId=3,DailyPrice=1000,ModelYear=2020,Name="S500"}, 28 | 29 | }; 30 | _colors = new List { 31 | new Color{Id=1,Name="White"}, 32 | new Color{Id=2,Name="Gray"}, 33 | new Color{Id=3,Name="Navy blue"} 34 | }; 35 | _brands = new List { 36 | new Brand{Id=1,Name="Renault"}, 37 | new Brand{Id=2,Name="Audi"}, 38 | new Brand{Id=3,Name="Mercedes"} 39 | }; 40 | _carDetailDtos = (from c in _cars 41 | join b in _brands 42 | on c.BrandId equals b.Id 43 | join co in _colors 44 | on c.ColorId equals co.Id 45 | select new CarDetailDto 46 | { CarId=c.Id, 47 | DailyPrice= c.DailyPrice, 48 | CarName = c.Name, 49 | BrandName= b.Name, 50 | ColorName = co.Name 51 | } 52 | ).ToList(); 53 | } 54 | 55 | 56 | public void Add(Car car) 57 | { 58 | _cars.Add(car); 59 | } 60 | 61 | public void Delete(Car car) 62 | { 63 | Car carToDelete = _cars.SingleOrDefault(c => c.Id == car.Id); 64 | _cars.Remove(carToDelete); 65 | } 66 | public void Update(Car car) 67 | { 68 | Car carToUpdate = _cars.SingleOrDefault(c => c.Id == car.Id); 69 | carToUpdate.ColorId = car.ColorId; 70 | carToUpdate.BrandId = car.BrandId; 71 | carToUpdate.ModelYear = car.ModelYear; 72 | carToUpdate.DailyPrice = car.DailyPrice; 73 | carToUpdate.Name = car.Name; 74 | } 75 | public List GetById(int carId) 76 | { 77 | return _cars.Where(c=> c.Id==carId).ToList(); 78 | } 79 | public List GetAllByBrandId(int brandId) 80 | { 81 | return _cars.Where(p => p.BrandId == brandId).ToList(); 82 | } 83 | 84 | 85 | 86 | public List GetCarDetails() 87 | { 88 | return _carDetailDtos; 89 | } 90 | 91 | public List GetAll(Expression> filter = null) 92 | { 93 | return filter == null 94 | ? _cars.ToList() 95 | : _cars.Where(filter.Compile()).ToList(); 96 | } 97 | 98 | public Car Get(Expression> filter) 99 | { 100 | return _cars.SingleOrDefault(filter.Compile()); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /WebAPI/Controllers/CarImagesController.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Core.Utilities.FileOperation; 3 | using Entities.Concrete; 4 | using Microsoft.AspNetCore.Hosting; 5 | using Microsoft.AspNetCore.Http; 6 | using Microsoft.AspNetCore.Mvc; 7 | using Newtonsoft.Json; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.IO; 11 | using System.Linq; 12 | using System.Threading.Tasks; 13 | 14 | namespace WebAPI.Controllers 15 | { 16 | [Route("api/[controller]")] 17 | [ApiController] 18 | public class CarImagesController : ControllerBase 19 | { 20 | IWebHostEnvironment _webHostEnvironment; 21 | ICarImageService _carImageService; 22 | 23 | public CarImagesController(ICarImageService carImageService, IWebHostEnvironment webHostEnvironment) 24 | { 25 | _webHostEnvironment = webHostEnvironment; 26 | _carImageService = carImageService; 27 | } 28 | 29 | [HttpGet("getall")] 30 | public IActionResult GetAll() 31 | {string path = _webHostEnvironment.WebRootPath + "\\uploads\\"; 32 | var result = _carImageService.GetAll(); 33 | if (result.Success) 34 | { 35 | return Ok(result); 36 | } 37 | return BadRequest(result); 38 | } 39 | 40 | [HttpGet("getbyid")] 41 | public IActionResult GetById(int id) 42 | { 43 | var result = _carImageService.GetById(id); 44 | if (result.Success) 45 | { 46 | return Ok(result); 47 | } 48 | return BadRequest(result); 49 | } 50 | [HttpGet("getcarimagesbycarid")] 51 | public IActionResult GetCarImagesByCarId(int id) 52 | { 53 | var result = _carImageService.GetCarImagesByCarId(id); 54 | if (result.Success) 55 | { 56 | return Ok(result); 57 | } 58 | return BadRequest(result); 59 | } 60 | 61 | 62 | [HttpPost("add")] 63 | public IActionResult Add([FromForm] FileOperation objectFile) 64 | { 65 | CarImage _carImage = JsonConvert.DeserializeObject(objectFile.carImages); 66 | if (objectFile.files.Length > 0) 67 | { 68 | string path = _webHostEnvironment.WebRootPath + "\\uploads\\"; 69 | var result = _carImageService.Add(objectFile,path,_carImage); 70 | if (result.Success) 71 | { 72 | return Ok(result); 73 | } 74 | return BadRequest(result); 75 | } 76 | return BadRequest(); 77 | } 78 | [HttpPost("delete")] 79 | public IActionResult Delete(CarImage carImage) 80 | { 81 | string path = _webHostEnvironment.WebRootPath + "\\uploads\\"; 82 | var result = _carImageService.Delete(path, carImage); 83 | if (result.Success) 84 | { 85 | return Ok(result); 86 | } 87 | return BadRequest(result); 88 | } 89 | 90 | [HttpPost("update")] 91 | public IActionResult Update([FromForm] FileOperation objectFile) 92 | { 93 | CarImage _carImage = JsonConvert.DeserializeObject(objectFile.carImages); 94 | if (objectFile.files.Length > 0) 95 | { 96 | string path = _webHostEnvironment.WebRootPath + "\\uploads\\"; 97 | var result = _carImageService.Update(objectFile, path, _carImage); 98 | if (result.Success) 99 | { 100 | return Ok(result); 101 | } 102 | return BadRequest(result); 103 | } 104 | return BadRequest(); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /Business/Concrete/CarManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.BusinessAspects.Autofac; 3 | using Business.Constants; 4 | using Business.ValidationRules.FluentValidation; 5 | using Core.Aspects.Autofac.Caching; 6 | using Core.Aspects.Autofac.Logging; 7 | using Core.Aspects.Autofac.Performance; 8 | using Core.Aspects.Autofac.Transaction; 9 | using Core.Aspects.Autofac.Validation; 10 | using Core.CrossCuttingConcerns.Logging.Log4Net.Loggers; 11 | using Core.Utilities.Results; 12 | using DataAccess.Abstract; 13 | using Entities.Concrete; 14 | using Entities.DTOs; 15 | using System; 16 | using System.Collections.Generic; 17 | using System.Linq; 18 | using System.Linq.Expressions; 19 | using System.Text; 20 | using System.Threading; 21 | 22 | namespace Business.Concrete 23 | { 24 | public class CarManager : ICarService 25 | { 26 | 27 | ICarDal _carDal; 28 | 29 | public CarManager(ICarDal carDal) 30 | { 31 | _carDal = carDal; 32 | } 33 | [SecuredOperation("car.add,admin")] 34 | [ValidationAspect(typeof(CarValidator))] 35 | [CacheRemoveAspect("ICarService.Get")] 36 | public IResult Add(Car car) 37 | { 38 | if (!IsExist(car.Id).Success) 39 | { 40 | _carDal.Add(car); 41 | return new SuccessResult(Messages.CarAdded); 42 | } 43 | return new ErrorResult(Messages.CarExists); 44 | } 45 | 46 | [SecuredOperation("car.delete,admin")] 47 | public IResult Delete(Car car) 48 | { 49 | if (IsExist(car.Id).Success) 50 | { 51 | _carDal.Delete(car); 52 | return new SuccessResult(Messages.CarDeleted); 53 | } 54 | return new SuccessResult(Messages.CarNotFound); 55 | 56 | } 57 | [SecuredOperation("car.list,admin")] 58 | [PerformanceAspect(5)] 59 | [LogAspect(typeof(FileLogger))] 60 | [CacheAspect(duration: 10)] 61 | public IDataResult> GetAll() 62 | { 63 | Thread.Sleep(5000); 64 | return new SuccessDataResult>(_carDal.GetAll(), Messages.CarListed); 65 | } 66 | 67 | public IDataResult> GetCarsByBrandId(int id) 68 | { 69 | return new SuccessDataResult>(_carDal.GetAll(p => p.BrandId == id), Messages.CarListed); 70 | } 71 | 72 | public IDataResult> GetCarsByColorId(int id) 73 | { 74 | return new SuccessDataResult>(_carDal.GetAll(p => p.ColorId == id), Messages.CarListed); 75 | } 76 | 77 | public IDataResult GetById(int Id) 78 | { 79 | return new SuccessDataResult(_carDal.Get(p => p.Id == Id), Messages.CarListed); 80 | } 81 | 82 | public IResult Update(Car car) 83 | { 84 | if (IsExist(car.Id).Success) 85 | { 86 | _carDal.Update(car); 87 | return new SuccessResult(Messages.CarUpdated); 88 | } 89 | 90 | return new ErrorResult(Messages.CarNotFound); 91 | } 92 | 93 | public IDataResult> GetCarDetails() 94 | { 95 | return new SuccessDataResult>(_carDal.GetCarDetails(), Messages.CarListed); 96 | } 97 | 98 | public IResult IsExist(int carId) 99 | { 100 | var carExist = GetById(carId); 101 | if (carExist.Data != null) 102 | { 103 | return new SuccessResult(Messages.CarExists); 104 | } 105 | return new ErrorResult(Messages.CarNotFound); 106 | } 107 | [TransactionScopeAspect] 108 | public IResult TransactionalOperation(Car car) 109 | { 110 | _carDal.Update(car); 111 | _carDal.Add(car); 112 | return new SuccessResult(Messages.CarUpdated); 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /Business/Constants/Messages.cs: -------------------------------------------------------------------------------- 1 | using Core.Entities.Concrete; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Runtime.Serialization; 5 | using System.Text; 6 | 7 | namespace Business.Constants 8 | { 9 | public static class Messages 10 | { 11 | public static string CarAdded = "Araç eklendi"; 12 | public static string ColorAdded = "Renk eklendi"; 13 | public static string BrandAdded = "Marka eklendi"; 14 | public static string UserAdded = "Kullanıcı eklendi"; 15 | public static string CustomerAdded = "Müşteri eklendi"; 16 | public static string RentalAdded = "Kiralama eklendi"; 17 | public static string CarImageAdded = "Araç resmi eklendi"; 18 | public static string CarDeleted = "Araç silindi"; 19 | public static string ColorDeleted = "Renk silindi"; 20 | public static string BrandDeleted = "Marka silindi"; 21 | public static string UserDeleted = "Kullanıcı silindi"; 22 | public static string CustomerDeleted = "Müsteri silindi"; 23 | public static string RentalDeleted = "Kiralama silindi"; 24 | public static string CarUpdated = "Araç guncellendi"; 25 | public static string CarImageDeleted = "Araç resmi silindi"; 26 | public static string ColorUpdated = "Renk guncellendi"; 27 | public static string BrandUpdated = "Marka guncellendi"; 28 | public static string UserUpdated = "Kullanıcı guncellendi"; 29 | public static string CustomerUpdated = "Müşteri guncellendi"; 30 | public static string RentalUpdated = "Kiralama guncellendi"; 31 | public static string CarImageUpdated = "Araç resmi güncellendi"; 32 | public static string CarNotFound = "Araç bulunamadı"; 33 | public static string ColorNotFound = "Renk bulunamadı"; 34 | public static string BrandNotFound = "Marka bulunamadı"; 35 | public static string UserNotFound = "Kullanıcı bulunamadı"; 36 | public static string CustomerNotFound = "Müşteri bulunamadı"; 37 | public static string RentalNotFound = "Kiralama bulunamadı"; 38 | public static string CarImageNotFound = "Resim bulunamadı"; 39 | public static string BrandNameInvalid = "Marka ismi geçersiz"; 40 | public static string ColorNameInvalid = "Renk ismi geçersiz"; 41 | public static string CarNameInvalid = "Araç ismi geçersiz"; 42 | public static string UserNameInvalid = "Kullanıcı ismi geçersiz"; 43 | public static string CustomerNameInvalid = "Müşteri ismi geçersiz"; 44 | public static string CarExists = "Araç zaten veritabanında var."; 45 | public static string ColorExists = "Renk zaten veritabanında var."; 46 | public static string BrandExists = "Marka zaten veritabanında var."; 47 | public static string UserExists = "Kullanıcı zaten veritabanında var."; 48 | public static string CustomerExists = "Musteri zaten veritabanında var."; 49 | public static string RentalExists = "Kiralama kaydı veritabanında var."; 50 | public static string CarImageExists = "Resim kaydı veritabanında var"; 51 | public static string CarListed = "Araç(lar) listelendi"; 52 | public static string ColorListed = "Renk(ler) listelendi"; 53 | public static string BrandListed = "Marka(lar) listelendi"; 54 | public static string UserListed = "Kullanıcı(lar) listelendi"; 55 | public static string CustomerListed = "Müşteri(ler) listelendi"; 56 | public static string RentalListed = "Kiralama(lar) listelendi"; 57 | public static string RentalIsOnRent = "Araç şu anda kirada."; 58 | public static string RentalEnded = "Araç kiradan döndü."; 59 | public static string MaintenanceTime = "Sistem bakımı var"; 60 | public static string MaxCarImageCountLimit = "Bir aracın en fazla 5 resmi olabilir"; 61 | public static string CarImageListed = "Resim(ler) listelendi"; 62 | public static string CarImageFileNameChanged = "Resim ismi GUID ile değiştirildi"; 63 | public static string AuthorizationDenied = "Yetki Reddedildi"; 64 | public static string UserRegistered ="Kullanıcı kayıt edildi."; 65 | public static string PasswordError = "Şifre Hatalı."; 66 | public static string SuccessfulLogin = "Başarılı giriş."; 67 | public static string UserAlreadyExists = "Kullanıcı zaten var."; 68 | public static string AccessTokenCreated = "Access Token Oluşturuldu."; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /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 System; 9 | using System.Collections.Generic; 10 | using System.Text; 11 | 12 | namespace Business.Concrete 13 | { 14 | public class RentalManager : IRentalService 15 | { 16 | 17 | IRentalDal _rentalDal; 18 | 19 | public RentalManager(IRentalDal rentalDal) 20 | { 21 | _rentalDal = rentalDal; 22 | } 23 | [ValidationAspect(typeof(RentalValidator))] 24 | public IResult Add(Rental rental) 25 | { 26 | if (!IsExist(rental.Id).Success) 27 | { 28 | if (!IsOnRent(rental.CarId).Success) 29 | { 30 | _rentalDal.Add(rental); 31 | return new SuccessResult(Messages.RentalAdded); 32 | } 33 | return new ErrorResult(Messages.RentalIsOnRent); 34 | } 35 | return new ErrorResult(Messages.RentalExists); 36 | } 37 | 38 | public IResult Delete(Rental brand) 39 | { 40 | if (IsExist(brand.Id).Success) 41 | { 42 | _rentalDal.Delete(brand); 43 | return new SuccessResult(Messages.RentalDeleted); 44 | } 45 | return new ErrorResult(Messages.RentalNotFound); 46 | } 47 | 48 | public IResult EndRental(Rental rental) 49 | { 50 | if (IsExist(rental.Id).Success) 51 | { 52 | var rentalToUpdate = GetById(rental.Id); 53 | if (rentalToUpdate.Data.ReturnDate.Equals(null)||rentalToUpdate.Data.ReturnDate.Equals(DateTime.MinValue)) 54 | { 55 | rental.CarId = rentalToUpdate.Data.CarId; 56 | rental.CustomerId = rentalToUpdate.Data.CustomerId; 57 | rental.RentDate = rentalToUpdate.Data.RentDate; 58 | if ((rental.ReturnDate==null) || (rental.ReturnDate==DateTime.MinValue)) 59 | { 60 | rental.ReturnDate = DateTime.Now; 61 | } 62 | _rentalDal.Update(rental); 63 | return new SuccessResult(Messages.RentalEnded); 64 | } 65 | } 66 | return new ErrorResult(Messages.RentalNotFound); 67 | } 68 | 69 | public IDataResult> GetAll() 70 | { 71 | return new SuccessDataResult>(_rentalDal.GetAll(), Messages.RentalListed); 72 | } 73 | 74 | public IDataResult GetById(int Id) 75 | { 76 | return new SuccessDataResult(_rentalDal.Get(p => p.Id == Id), Messages.RentalListed); 77 | } 78 | 79 | public IResult Update(Rental rental) 80 | { 81 | if (IsExist(rental.Id).Success) 82 | { 83 | var rentalToUpdate=GetById(rental.Id); 84 | if (rental.CarId.Equals(null)||rental.CarId.Equals(0)) 85 | { 86 | rental.CarId = rentalToUpdate.Data.CarId; 87 | } 88 | if (rental.CustomerId.Equals(null)||rental.CustomerId.Equals(0)) 89 | { 90 | rental.CustomerId = rentalToUpdate.Data.CustomerId; 91 | } 92 | if (rental.RentDate.Equals(null)||rental.RentDate.Equals(DateTime.MinValue)) 93 | { 94 | rental.RentDate = rentalToUpdate.Data.RentDate; 95 | } 96 | rental.ReturnDate = DateTime.MinValue; 97 | _rentalDal.Update(rental); 98 | return new SuccessResult(Messages.RentalUpdated); 99 | } 100 | return new ErrorResult(Messages.RentalNotFound); 101 | 102 | } 103 | private IResult IsExist(int rentalId) 104 | { 105 | var rentalExist = GetById(rentalId); 106 | if (rentalExist.Data != null) 107 | { 108 | return new SuccessResult(Messages.RentalExists); 109 | } 110 | return new ErrorResult(Messages.RentalNotFound); 111 | } 112 | 113 | private IResult IsOnRent(int carId) 114 | { 115 | var isOnRent = false; 116 | var rentalByCarId = new List(_rentalDal.GetAll(p => p.CarId == carId)); 117 | if (rentalByCarId.Count > 0) 118 | { 119 | foreach (var rental in rentalByCarId) 120 | { 121 | if (rental.ReturnDate == DateTime.MinValue) 122 | { 123 | isOnRent = true; 124 | } 125 | } 126 | } 127 | if (isOnRent) 128 | { 129 | return new SuccessResult(Messages.RentalIsOnRent); 130 | } 131 | return new ErrorResult(); 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /Business/Concrete/CarImageManager.cs: -------------------------------------------------------------------------------- 1 | using Business.Abstract; 2 | using Business.Constants; 3 | using Business.ValidationRules.FluentValidation; 4 | using Core.Aspects.Autofac.Validation; 5 | using Core.Utilities.Business; 6 | using Core.Utilities.FileOperation; 7 | using Core.Utilities.Results; 8 | using DataAccess.Abstract; 9 | using Entities.Concrete; 10 | using System; 11 | using System.Collections.Generic; 12 | using System.IO; 13 | using System.Linq; 14 | 15 | namespace Business.Concrete 16 | { 17 | public class CarImageManager : ICarImageService 18 | { 19 | 20 | ICarImageDal _carImageDal; 21 | ICarService _carService; 22 | 23 | public CarImageManager(ICarImageDal carImageDal, ICarService carService) 24 | { 25 | _carImageDal = carImageDal; 26 | _carService = carService; 27 | } 28 | [ValidationAspect(typeof(CarImageValidator))] 29 | public IResult Add(FileOperation file, string path, CarImage carImage) 30 | { 31 | var result = BusinessRules.Run(IsExist(carImage.Id)); 32 | if (result == null) 33 | { 34 | return result; 35 | } 36 | result = BusinessRules.Run(CheckCarImageCountLimitReached(carImage.CarId)); 37 | if (result != null) 38 | { 39 | return result; 40 | } 41 | 42 | if (!Directory.Exists(path)) 43 | { 44 | Directory.CreateDirectory(path); 45 | } 46 | 47 | string newImageFileName = RenameFileToGuid(file).Data; 48 | 49 | carImage.ImagePath = newImageFileName; 50 | carImage.Date = DateTime.Now; 51 | 52 | UploadImage(file, path, newImageFileName); 53 | 54 | _carImageDal.Add(carImage); 55 | return new SuccessResult(Messages.CarImageAdded); 56 | 57 | } 58 | 59 | private static IDataResult RenameFileToGuid(FileOperation file) 60 | { 61 | string[] fileNameSplit = file.files.FileName.Split('.'); 62 | var extensionOfFile = "." + fileNameSplit[fileNameSplit.Length - 1]; 63 | var result = 64 | DateTime.Now.Day.ToString() + "_" + 65 | DateTime.Now.Month.ToString() + "_" + 66 | DateTime.Now.Year.ToString() + "_" + 67 | Guid.NewGuid().ToString() + extensionOfFile; 68 | return new SuccessDataResult(result,Messages.CarImageFileNameChanged); 69 | } 70 | 71 | public IResult Delete(string path, CarImage carImage) 72 | { 73 | var result = BusinessRules.Run(IsExist(carImage.Id)); 74 | if (result != null) 75 | { 76 | return result; 77 | } 78 | var carImageToDelete = _carImageDal.Get(p => p.Id == carImage.Id); 79 | DeleteImage(path + carImageToDelete.ImagePath); 80 | _carImageDal.Delete(carImage); 81 | return new SuccessResult(Messages.CarImageDeleted); 82 | 83 | } 84 | 85 | public IDataResult> GetAll() 86 | { 87 | var result = _carImageDal.GetAll().ToList(); 88 | return new SuccessDataResult>(_carImageDal.GetAll(), Messages.CarImageListed); 89 | } 90 | 91 | public IDataResult> GetCarImagesByCarId(int carId) 92 | { 93 | if (!_carImageDal.GetAll(p => p.CarId == carId).Any()) 94 | { 95 | if (_carService.IsExist(carId).Success) 96 | { 97 | return new SuccessDataResult>(new List {new CarImage {Id = 0, 98 | CarId = carId, 99 | ImagePath = "DefaultCar.jfif", 100 | Date = DateTime.MinValue 101 | } 102 | } 103 | , Messages.CarImageListed); 104 | } 105 | return new ErrorDataResult>(Messages.CarNotFound); 106 | } 107 | return new SuccessDataResult>(_carImageDal.GetAll(p => p.CarId == carId), Messages.CarImageListed); 108 | } 109 | 110 | public IDataResult GetById(int Id) 111 | { 112 | return new SuccessDataResult(_carImageDal.Get(p => p.Id == Id), Messages.CarImageListed); 113 | } 114 | [ValidationAspect(typeof(CarImageValidator))] 115 | public IResult Update(FileOperation file, string path, CarImage carImage) 116 | { 117 | var result = BusinessRules.Run(IsExist(carImage.Id)); 118 | if (result != null) 119 | { 120 | return result; 121 | } 122 | var carImageToUpdate = _carImageDal.Get(p => p.Id == carImage.Id); 123 | DeleteImage(path + carImageToUpdate.ImagePath); 124 | string newImageFileName = RenameFileToGuid(file).Data; 125 | carImage.ImagePath = newImageFileName; 126 | carImage.Date = DateTime.Now; 127 | UploadImage(file, path, newImageFileName); 128 | 129 | _carImageDal.Update(carImage); 130 | return new SuccessResult(Messages.CarImageUpdated); 131 | } 132 | 133 | private IResult IsExist(int carImageId) 134 | { 135 | var carImageExist = GetById(carImageId); 136 | if (carImageExist.Data != null) 137 | { 138 | return new SuccessResult(Messages.CarImageExists); 139 | } 140 | return new ErrorResult(Messages.CarImageNotFound); 141 | } 142 | private IResult CheckCarImageCountLimitReached(int carId) 143 | { 144 | var result = _carImageDal.GetAll(p => p.CarId == carId).Count; 145 | if (result >= 5) 146 | { 147 | return new ErrorResult(Messages.MaxCarImageCountLimit); 148 | } 149 | return new SuccessResult(); 150 | } 151 | 152 | 153 | private static void UploadImage(FileOperation file, string path, string newImageFileName) 154 | { 155 | using (FileStream fileStream = System.IO.File.Create(path + newImageFileName)) 156 | { 157 | file.files.CopyTo(fileStream); 158 | fileStream.Flush(); 159 | } 160 | } 161 | private static void DeleteImage(string path) 162 | { 163 | if (System.IO.File.Exists(path)) 164 | { 165 | System.IO.File.Delete(path); 166 | } 167 | } 168 | 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /.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 -------------------------------------------------------------------------------- /ConsoleUI/Program.cs: -------------------------------------------------------------------------------- 1 | using Business.Concrete; 2 | using Core.Entities.Concrete; 3 | using DataAccess.Concrete.EntityFrameWork; 4 | using DataAccess.Concrete.InMemory; 5 | using Entities.Concrete; 6 | using Entities.DTOs; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Data.SqlTypes; 10 | 11 | namespace ConsoleUI 12 | { 13 | class Program 14 | { 15 | static void Main(string[] args) 16 | { 17 | //InMemoryGetTest(); 18 | //InMemoryAddTest(); 19 | //InMemoryGetByIdTest(); 20 | //InMemoryUpdateTest(); 21 | //InMemoryDeleteTest(); 22 | //InMemoryGetDetailsTest(); 23 | 24 | 25 | //EfGetTest(); 26 | //EfAddTest(); 27 | //EfUpdateTest(); 28 | //EfGetByIdTest(); 29 | //EfDeleteTest(); 30 | //EfGetDetailsTest(); 31 | 32 | 33 | // ----------------------------------------Car Creation------------------------------------------------- 34 | //List cars = new List { 35 | //new Car { Id = 1, BrandId = 1, ColorId = 1, DailyPrice = 300, ModelYear = 2019, Name = "Symbol" }, 36 | //new Car { Id = 2, BrandId = 1, ColorId = 1, DailyPrice = 350, ModelYear = 2019, Name = "Megane" }, 37 | //new Car { Id = 3, BrandId = 2, ColorId = 2, DailyPrice = 600, ModelYear = 2019, Name = "A3" }, 38 | //new Car { Id = 4, BrandId = 2, ColorId = 3, DailyPrice = 800, ModelYear = 2019, Name = "A5" }, 39 | //new Car { Id = 5, BrandId = 3, ColorId = 1, DailyPrice = 700, ModelYear = 2020, Name = "E200" }, 40 | //new Car { Id = 6, BrandId = 3, ColorId = 3, DailyPrice = 1000, ModelYear = 2020, Name = "S500" }, 41 | //}; 42 | //CarManager carManager = new CarManager(new EfCarDal()); 43 | //foreach (var car in cars) 44 | //{ 45 | // carManager.Add(car); 46 | //} 47 | // ----------------------------------------Car Creation------------------------------------------------- 48 | 49 | // ----------------------------------------Color And Brand Creation----------------------------------------- 50 | //List colors = new List 51 | //{ 52 | // new Color {Id=1,Name="White"}, 53 | // new Color {Id=2,Name="Gray"}, 54 | // new Color {Id=3,Name="NavyBlue"} 55 | //}; 56 | //ColorManager colorManager = new ColorManager(new EfColorDal()); 57 | //foreach (var color in colors) 58 | // { 59 | // colorManager.Add(color); 60 | // } 61 | //List brands = new List { 62 | //new Brand{Id=1,Name="Renault"}, 63 | //new Brand{Id=2,Name="Audi"}, 64 | //new Brand{Id=3,Name="Mercedes"} 65 | //}; 66 | //BrandManager brandManager = new BrandManager(new EfBrandDal()); 67 | //foreach (var brand in brands) 68 | //{ 69 | // brandManager.Add(brand); 70 | //} 71 | // ----------------------------------------Color And Brand Creation----------------------------------------- 72 | //Change Add to Delete or Update to delete or update color and brands 73 | // ----------------------------------------User And Customer Creation----------------------------------------- 74 | //List users = new List { 75 | //new User{Id=1,FirstName="Zafer",LastName="Çıklaçekiç",Email="zafer@ciklacekic.info",Password="1234"}, 76 | //new User{Id=2,FirstName="Recep",LastName="Göksu",Email="recep@goksu.info",Password="1234"}, 77 | //new User{Id=3,FirstName="Hüseyin",LastName="Cimşir",Email="huseyin@cimsir.info",Password="1234"} 78 | //}; 79 | List customers = new List { 80 | new Customer{Id=1,UserId=1,CompanyName="Çıklaçekiç A.Ş."}, 81 | new Customer{Id=2,UserId=2,CompanyName="Göksu A.Ş."}, 82 | new Customer{Id=3,UserId=3,CompanyName="Cimşir A.Ş."} 83 | }; 84 | //CustomerAddTest(customers); 85 | //UserAddTest(users); 86 | //DateTime? nullDateTime=null; 87 | List rentals = new List { 88 | new Rental{Id=1,CustomerId=1,CarId=4,RentDate=DateTime.Now,ReturnDate =DateTime.MinValue}, 89 | new Rental{Id=2,CustomerId=2,CarId=3,RentDate=DateTime.Now.AddDays(-2),ReturnDate=DateTime.MinValue}, 90 | new Rental{Id=3,CustomerId=3,CarId=4,RentDate=DateTime.Now.AddDays(-10),ReturnDate=DateTime.MinValue}, 91 | new Rental{Id=4,CustomerId=3,CarId=4,RentDate=DateTime.Now.AddDays(-10),ReturnDate=DateTime.MinValue}, 92 | }; 93 | //RentalAddTest(rentals); 94 | //Rental rental = new Rental { Id = 1, CustomerId = 2 }; 95 | //RentalUpdateTest(rental); 96 | //Rental rental = new Rental { Id = 1 }; 97 | //RentalEndTest(rental); 98 | CarImage carImage = new CarImage 99 | { 100 | Id = 1, 101 | CarId = 1, 102 | ImagePath = @"c:\sources\images\birinci.ikinci.ucuncu.jpg", 103 | Date = DateTime.Now 104 | }; 105 | string[] fileSplit = carImage.ImagePath.Split('.'); 106 | var extensionOfFile = "."+ fileSplit[fileSplit.Length - 1]; 107 | var newPathName = Guid.NewGuid().ToString() + extensionOfFile; 108 | Console.WriteLine(newPathName); 109 | } 110 | 111 | private static void RentalEndTest(Rental rental) 112 | { 113 | RentalManager rentalManager = new RentalManager(new EfRentalDal()); 114 | var result = rentalManager.EndRental(rental); 115 | Console.WriteLine("{0,3} | {1,3} | {2,3} | {3,40} |", rental.Id, rental.CarId, rental.CustomerId, result.Message); 116 | } 117 | 118 | private static void RentalUpdateTest(Rental rental) 119 | { 120 | RentalManager rentalManager = new RentalManager(new EfRentalDal()); 121 | var result = rentalManager.Update(rental); 122 | Console.WriteLine("{0,3} | {1,3} | {2,3} | {3,40} |", rental.Id, rental.CarId, rental.CustomerId, result.Message); 123 | } 124 | 125 | private static void RentalAddTest(List rentals) 126 | { 127 | RentalManager rentalManager = new RentalManager(new EfRentalDal()); 128 | foreach (var rental in rentals) 129 | { 130 | var result = rentalManager.Add(rental); 131 | Console.WriteLine("{0,3} | {1,3} | {2,3} | {3,40} |", rental.Id, rental.CarId, rental.CustomerId, result.Message); 132 | } 133 | } 134 | 135 | private static void CustomerAddTest(List customers) 136 | { 137 | CustomerManager customerManager = new CustomerManager(new EfCustomerDal()); 138 | foreach (var customer in customers) 139 | { 140 | var result = customerManager.Add(customer); 141 | Console.WriteLine("{0,3} | {1,3} | {2,20} | {3,40} |", customer.Id, customer.UserId, customer.CompanyName, result.Message); 142 | } 143 | } 144 | 145 | private static void UserAddTest(List users) 146 | { 147 | UserManager userManager = new UserManager(new EfUserDal()); 148 | foreach (var user in users) 149 | { 150 | var result=userManager.Add(user); 151 | Console.WriteLine("{0,3} | {1,10} | {2,20} | {3,40} |",user.Id,user.FirstName,user.LastName, result.Message); 152 | } 153 | } 154 | 155 | private static void EfGetDetailsTest() 156 | { 157 | Console.WriteLine("-------------Entity Framework Get Details-----------------------"); 158 | CarManager carManager = new CarManager(new EfCarDal()); 159 | List carDetails = carManager.GetCarDetails().Data; 160 | PrintDetailsTest(carDetails); 161 | } 162 | 163 | private static void EfDeleteTest() 164 | { 165 | Console.WriteLine("-------------Entity Framework Car Delete-----------------------"); 166 | CarManager carManager = new CarManager(new EfCarDal()); 167 | Car car = new Car { Id = 7 }; 168 | carManager.Delete(car); //Only Id is needed 169 | List cars = carManager.GetAll().Data; 170 | PrintTest(cars); 171 | } 172 | 173 | private static void EfGetByIdTest() 174 | { 175 | Console.WriteLine("-------------Entity Framework Get By Id-----------------------"); 176 | CarManager carManager = new CarManager(new EfCarDal()); 177 | List cars = new List { carManager.GetById(3).Data }; 178 | 179 | 180 | PrintTest(cars); 181 | } 182 | 183 | private static void EfUpdateTest() 184 | { 185 | Console.WriteLine("-------------Entity FrameWork Car Update-----------------------"); 186 | CarManager carManager = new CarManager(new EfCarDal()); 187 | 188 | Car car = new Car { Id = 7, BrandId = 2, ColorId = 2, DailyPrice = 699, ModelYear = 2018, Name = "A4" }; 189 | carManager.Update(car); 190 | List cars = carManager.GetAll().Data; 191 | PrintTest(cars); 192 | } 193 | 194 | private static void EfAddTest() 195 | { 196 | Console.WriteLine("-------------Entity FrameWork Car Add-----------------------"); 197 | CarManager carManager = new CarManager(new EfCarDal()); 198 | 199 | Car car = new Car { Id = 7, BrandId = 2, ColorId = 2, DailyPrice = 500, ModelYear = 2018, Name = "A4" }; 200 | carManager.Add(car); 201 | List cars = carManager.GetAll().Data; 202 | PrintTest(cars); 203 | 204 | } 205 | 206 | private static void EfGetTest() 207 | { 208 | Console.WriteLine("-------------Entity FrameWork Car Get-----------------------"); 209 | CarManager carManager = new CarManager(new EfCarDal()); 210 | List cars = carManager.GetAll().Data; 211 | PrintTest(cars); 212 | } 213 | 214 | private static void InMemoryGetDetailsTest() 215 | { 216 | Console.WriteLine("-------------InMemory Get Details-----------------------"); 217 | CarManager carManager = new CarManager(new InMemoryCarDal()); 218 | List carDetails = carManager.GetCarDetails().Data; 219 | PrintDetailsTest(carDetails); 220 | } 221 | 222 | private static void PrintDetailsTest(List carDetails) 223 | { 224 | Console.WriteLine("| Id | Brand | Name | Color | DailyPrice |"); 225 | foreach (var item in carDetails) 226 | { 227 | 228 | Console.WriteLine("|{0,3} |{1,10} | {2,10} | {3,10} | {4,10} |", 229 | item.CarId, item.BrandName, item.CarName, item.ColorName, item.DailyPrice); 230 | } 231 | } 232 | 233 | private static void InMemoryDeleteTest() 234 | { 235 | Console.WriteLine("-------------InMemory Car Delete-----------------------"); 236 | CarManager carManager = new CarManager(new InMemoryCarDal()); 237 | Car car = new Car { Id = 6 }; 238 | carManager.Delete(car); //Only Id is needed 239 | List cars = carManager.GetAll().Data; 240 | PrintTest(cars); 241 | } 242 | 243 | private static void InMemoryUpdateTest() 244 | { 245 | Console.WriteLine("-------------InMemory Car Update-----------------------"); 246 | CarManager carManager = new CarManager(new InMemoryCarDal()); 247 | Car car = new Car { Id = 6, BrandId = 2, ColorId = 2, DailyPrice = 500, ModelYear = 2018, Name = "A4" }; 248 | car.DailyPrice = 699; 249 | carManager.Update(car); 250 | List cars = carManager.GetAll().Data; 251 | PrintTest(cars); 252 | } 253 | 254 | private static void InMemoryGetByIdTest() 255 | { 256 | Console.WriteLine("-------------InMemory Get By Id-----------------------"); 257 | CarManager carManager = new CarManager(new InMemoryCarDal()); 258 | List cars = new List { carManager.GetById(3).Data }; 259 | 260 | 261 | PrintTest(cars); 262 | } 263 | 264 | private static void InMemoryAddTest() 265 | { 266 | Console.WriteLine("-------------InMemory Car Add---------------------------"); 267 | CarManager carManager = new CarManager(new InMemoryCarDal()); 268 | 269 | Car car = new Car { Id = 7, BrandId = 2, ColorId = 2, DailyPrice = 500, ModelYear = 2018, Name = "A4" }; 270 | carManager.Add(car); 271 | List cars = carManager.GetAll().Data; 272 | PrintTest(cars); 273 | } 274 | 275 | private static void InMemoryGetTest() 276 | { 277 | Console.WriteLine("-------------InMemory Get All-----------------------"); 278 | CarManager carManager = new CarManager(new InMemoryCarDal()); 279 | List cars = carManager.GetAll().Data; 280 | PrintTest(cars); 281 | } 282 | 283 | private static void PrintTest(List cars) 284 | { 285 | 286 | Console.WriteLine("| Id | Name | BrandId | ColorId | DailyPrice | ModelYear |"); 287 | foreach (var item in cars) 288 | { 289 | Console.WriteLine("|{0,3} |{1,10} | {2,7} | {3,7} | {4,10} | {5,9} |", 290 | item.Id, item.Name, item.BrandId, item.ColorId, item.DailyPrice, item.ModelYear); 291 | 292 | } 293 | } 294 | } 295 | } 296 | --------------------------------------------------------------------------------