Skip to content

Commit

Permalink
28/03/2021 ✓
Browse files Browse the repository at this point in the history
  • Loading branch information
semihshn committed Mar 28, 2021
1 parent d8488f8 commit f7a54d0
Show file tree
Hide file tree
Showing 25 changed files with 294 additions and 63 deletions.
2 changes: 2 additions & 0 deletions ReCapProject/Business/Abstract/ICarService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public interface ICarService
IResult Delete(Car car);
IDataResult<List<Car>> GetAll();
IDataResult<Car> GetById(int id);

IDataResult<List<CarDetailDto>> GetCarDetails(Expression<Func<Car, bool>> filter = null);
IDataResult<CarDetailDto> GetCarDetail(Expression<Func<Car, bool>> filter);

IDataResult<List<CarDetailDto>> GetCarsBySelect(int brandId, int colorId);
}
Expand Down
3 changes: 3 additions & 0 deletions ReCapProject/Business/Abstract/ICreditCardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ namespace Business.Abstract
public interface ICreditCardService
{
IDataResult<List<CreditCard>> GetCreditCards(Expression<Func<CreditCard, bool>> filter = null);
IDataResult<CreditCard> GetCreditCard(Expression<Func<CreditCard, bool>> filter = null);
IResult Pay(CreditCard creditCard);


}
}
3 changes: 3 additions & 0 deletions ReCapProject/Business/Abstract/ICustomerService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Core.Utilities.Results.Abstract;
using DataAccess.Abstract;
using Entities.Concrete;
using Entities.DTOs;
using System;
using System.Collections.Generic;
using System.Text;
Expand All @@ -16,5 +17,7 @@ public interface ICustomerService
IResult Add(Customer customer);
IResult Update(Customer customer);
IResult Delete(Customer customer);
IResult UpdateCustomerAndUser(CustomerAndUserUpdateDto customerUpdateDto);
IDataResult<CustomerAndUserUpdateDto>GetCustomerAndUserDetails(int userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Extensions.DependencyInjection;
using Core.Extensions;
using Business.Constants;
using System.Security;

namespace Business.BusinessAspect.Autofac
{
Expand All @@ -32,8 +33,7 @@ protected override void OnBefore(IInvocation invocation)//Authorization işlemi
return;
}
}
return;
throw new Exception(Messages.AuthorizationDenied);
throw new SecurityException(Messages.AuthorizationDenied);
}
}
}
3 changes: 2 additions & 1 deletion ReCapProject/Business/Concrete/AuthManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public IDataResult<User> Register(UserForRegisterDto userForRegisterDto, string
LastName = userForRegisterDto.LastName,
PasswordHash = passwordHash,
PasswordSalt = passwordSalt,
Status = true
Status = true,
Age=userForRegisterDto.Age
};
_userService.Add(user);//Kullanıcı veri tabanına kaydediliyor
return new SuccessDataResult<User>(user, Messages.UserRegistered);
Expand Down
7 changes: 6 additions & 1 deletion ReCapProject/Business/Concrete/CarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,10 @@ public IDataResult<List<CarDetailDto>> GetCarsBySelect(int brandId, int colorId)
{
return new SuccessDataResult<List<CarDetailDto>>(_carDal.GetCarDetails(c => c.ColorId == colorId & c.BrandId == brandId));
}
}

public IDataResult<CarDetailDto> GetCarDetail(Expression<Func<Car, bool>> filter)
{
return new SuccessDataResult<CarDetailDto>(_carDal.GetCarDetails(filter).FirstOrDefault());
}
}
}
5 changes: 5 additions & 0 deletions ReCapProject/Business/Concrete/CreditCardManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public CreditCardManager(ICreditCardDal creditCardDal)
_creditCardDal = creditCardDal;
}

public IDataResult<CreditCard> GetCreditCard(Expression<Func<CreditCard, bool>> filter = null)
{
return new SuccessDataResult<CreditCard>(_creditCardDal.Get(filter));
}

public IDataResult<List<CreditCard>> GetCreditCards(Expression<Func<CreditCard, bool>> filter = null)
{
return new SuccessDataResult<List<CreditCard>>(_creditCardDal.GetAll(filter));
Expand Down
57 changes: 56 additions & 1 deletion ReCapProject/Business/Concrete/CustomerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
using Business.Constants;
using Business.ValidationRules.FluentValidation;
using Core.Aspects.Autofac.Validation;
using Core.Utilities.Hashing;
using Core.Utilities.Results.Abstract;
using Core.Utilities.Results.Concrete;
using DataAccess.Abstract;
using Entities.Concrete;
using Entities.DTOs;
using System;
using System.Collections.Generic;
using System.Text;
Expand All @@ -15,10 +17,12 @@ namespace Business.Concrete
public class CustomerManager : ICustomerService
{
ICustomerDal _customerDal;
IUserService _userService;

public CustomerManager(ICustomerDal customerDal)
public CustomerManager(ICustomerDal customerDal,IUserService userService)
{
_customerDal = customerDal;
_userService = userService;
}

[ValidationAspect(typeof(CustomerValidator))]
Expand Down Expand Up @@ -54,5 +58,56 @@ public IResult Update(Customer customer)
_customerDal.Update(customer);
return new SuccessResult(Messages.CustomerUpdated);
}

public IDataResult<CustomerAndUserUpdateDto> GetCustomerAndUserDetails(int userId)
{
return new SuccessDataResult<CustomerAndUserUpdateDto>(_customerDal.GetCustomerAndUserDetails(userId));
}

public IResult UpdateCustomerAndUser(CustomerAndUserUpdateDto customerUpdateDto)
{
var userResult = _userService.GetById(customerUpdateDto.Id);
if (!userResult.Success)
return new ErrorResult(userResult.Message);

if (!HashingHelper.VerifyPasswordHash(customerUpdateDto.ActivePassword, userResult.Data.PasswordHash, userResult.Data.PasswordSalt))
return new ErrorResult(Messages.PasswordError);

var customerResult = _customerDal.Get(p => p.UserId == customerUpdateDto.Id);
if (customerResult == null)
return new ErrorResult(Messages.CustomerNotFound);

customerResult.CompanyName = customerUpdateDto.CompanyName;

userResult.Data.FirstName = customerUpdateDto.FirstName;
userResult.Data.LastName = customerUpdateDto.LastName;
userResult.Data.Email = customerUpdateDto.Email;

if (customerUpdateDto.NewPassword.Length > 5)
{
HashingHelper.CreatePasswordHash(customerUpdateDto.NewPassword, out byte[] passwordHash, out byte[] passwordSalt);
userResult.Data.PasswordHash = passwordHash;
userResult.Data.PasswordSalt = passwordSalt;
}

try
{
_customerDal.Update(customerResult);
}
catch (Exception)
{
return new ErrorResult(Messages.CustomerNotUpdated);
}
try
{
_userService.Update(userResult.Data);
}
catch (Exception)
{
return new ErrorResult(Messages.UserNotUpdated);
}

return new SuccessResult(Messages.CustomerUpdated);
}
}
}
45 changes: 42 additions & 3 deletions ReCapProject/Business/Concrete/RentalManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ namespace Business.Concrete
public class RentalManager : IRentalService
{
IRentalDal _rentalDal;
ICarService _carService;
ICustomerService _customerService;

public RentalManager(IRentalDal rentalDal)

public RentalManager(IRentalDal rentalDal,ICarService carService,ICustomerService customerService)
{
_rentalDal = rentalDal;
_carService = carService;
_customerService = customerService;
}

[ValidationAspect(typeof(RentalValidator))]
//[ValidationAspect(typeof(RentalValidator))]
public IResult Add(Rental rental)
{
IResult result = BusinessRules.Run(CheckCarExistInRentalList(rental), ChecCarExistRentalHistory(rental));
IResult result = BusinessRules.Run(CheckCarExistInRentalList(rental), ChecCarExistRentalHistory(rental), ChecIfCarOfFindeksPoint(rental), ChecIfCustomerOfFindeksPoint(rental), ChecIfFindeksPoint(rental));

if (result != null)
{
Expand Down Expand Up @@ -94,5 +99,39 @@ private IResult ChecCarExistRentalHistory(Rental rental)
return new SuccessResult();

}

private IResult ChecIfCarOfFindeksPoint(Rental rental)
{

var car = _carService.GetById(rental.CarId);
if (car.Data.FindeksPoint==null)
{
return new ErrorResult(Messages.ErrorCarFindeksPoint);
}
return new SuccessResult();
}

private IResult ChecIfCustomerOfFindeksPoint(Rental rental)
{

var customer = _customerService.GetById(rental.CustomerId);
if (customer.Data.FindeksPoint == null)
{
return new ErrorResult(Messages.ErrorCustomerFindeksPoint);
}
return new SuccessResult();
}

private IResult ChecIfFindeksPoint(Rental rental)
{

var customer = _customerService.GetById(rental.CustomerId);
var car = _carService.GetById(rental.CarId);
if (customer.Data.FindeksPoint<car.Data.FindeksPoint)
{
return new ErrorResult(Messages.InsufficientFindeksScore);
}
return new SuccessResult();
}
}
}
2 changes: 1 addition & 1 deletion ReCapProject/Business/Concrete/UserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ public IDataResult<List<OperationClaim>> GetClaims(User user)
{
return new SuccessDataResult<List<OperationClaim>>(_userDal.GetClaims(user));
}
}
}
}
6 changes: 6 additions & 0 deletions ReCapProject/Business/Constants/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,11 @@ public static class Messages
public static string ReturnedRental="Kiralama bilgisi döndürüldü";
public static string FailedRentalAddOrUpdate="Bu kiralık araç daha önce eklenmiş";
public static string AlreadyRented="Bu araç belirlediğiniz tarihlerde dolu , ileriki bir tarih seçiniz";
public static string ErrorCarFindeksPoint= "Kiralanmak istenen aracın findeks puanı yok , başka bir araç seçin";
public static string ErrorCustomerFindeksPoint = "Findeks puanınız olmadığından bu aracı size kiralayamayız";
public static string InsufficientFindeksScore="Findeks puanınız bu aracı kiralamak için yetersiz";
public static string CustomerNotFound = "Böyle bir müşteri bulunamadı";
public static string CustomerNotUpdated = "Müşteri bilgilerini güncellerken bir hatayla karşılaştık";
public static string UserNotUpdated = "Kullanıcı bilgilerini güncellerken bir hatayla karşılaştık";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public CarValidator()
RuleFor(c => c.BrandId).NotEmpty();
RuleFor(c => c.ColorId).NotEmpty();
RuleFor(c => c.DailyPrice).GreaterThan(0);

RuleFor(c => c.FindeksPoint).ExclusiveBetween(0, 1900);
}
}
}
84 changes: 42 additions & 42 deletions ReCapProject/ConsoleUI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static void Main(string[] args)

private static void TestGetRentalDetailsDto()
{
RentalManager rentalManager = new RentalManager(new EfRentalDal());
//RentalManager rentalManager = new RentalManager(new EfRentalDal());

//var result = rentalManager.GetRentalDetailsDto();

Expand All @@ -83,36 +83,36 @@ private static void TestGetRentalDetailsDto()

private static void TestDeleteRental(int id)
{
RentalManager rentalManager = new RentalManager(new EfRentalDal());
//RentalManager rentalManager = new RentalManager(new EfRentalDal());

rentalManager.Delete(new Rental() { Id = id });
//rentalManager.Delete(new Rental() { Id = id });
}

private static RentalManager TestGetAllRentals()
{
RentalManager rentalManager = new RentalManager(new EfRentalDal());
// private static RentalManager TestGetAllRentals()
// {
// RentalManager rentalManager = new RentalManager(new EfRentalDal());

var result = rentalManager.GetAll();
// var result = rentalManager.GetAll();

foreach (var rentals in result.Data)
{
Console.WriteLine("{0}/{1}/{2}//{3}//{4}", rentals.Id, rentals.CarId, rentals.CustomerId, rentals.RentDate, rentals.ReturnDate);
}
// foreach (var rentals in result.Data)
// {
// Console.WriteLine("{0}/{1}/{2}//{3}//{4}", rentals.Id, rentals.CarId, rentals.CustomerId, rentals.RentDate, rentals.ReturnDate);
// }

return rentalManager;
}
// return rentalManager;
//}

private static RentalManager TestAddNewRentalCar(int carId, int customerId)
{
RentalManager rentalManager = new RentalManager(new EfRentalDal());
// private static RentalManager TestAddNewRentalCar(int carId, int customerId)
// {
// RentalManager rentalManager = new RentalManager(new EfRentalDal());

rentalManager.Add(new Rental()
{
CarId = carId,
CustomerId = customerId
});
return rentalManager;
}
//rentalManager.Add(new Rental()
//{
// CarId = carId,
// CustomerId = customerId
//});
// return rentalManager;
// }

private static CreditCardManager TestAddNewCreditCard(string cardNumber,string cvc,string expiration, int customerId)
{
Expand All @@ -128,30 +128,30 @@ private static CreditCardManager TestAddNewCreditCard(string cardNumber,string c
return creditCardManager;
}

private static void TestGetAllCustomer()
{
CustomerManager customerManager = new CustomerManager(new EfCustomerDal());
//private static void TestGetAllCustomer()
// {
// CustomerManager customerManager = new CustomerManager(new EfCustomerDal());

var result = customerManager.GetAll();
// var result = customerManager.GetAll();

foreach (var customer in result.Data)
{
Console.WriteLine("{0}/{1}/{2}", customer.Id, customer.UserId, customer.CompanyName);
// foreach (var customer in result.Data)
// {
// Console.WriteLine("{0}/{1}/{2}", customer.Id, customer.UserId, customer.CompanyName);

}
}
// }
// }

private static CustomerManager TestAddNewCustomer(int id, string companyName)
{
CustomerManager customerManager = new CustomerManager(new EfCustomerDal());
//private static CustomerManager TestAddNewCustomer(int id, string companyName)
//{
// CustomerManager customerManager = new CustomerManager(new EfCustomerDal());

customerManager.Add(new Customer()
{
UserId = id,
CompanyName = companyName,
});
return customerManager;
}
// customerManager.Add(new Customer()
// {
// UserId = id,
// CompanyName = companyName,
// });
// return customerManager;
//}

private static void TestUserGetAll()
{
Expand Down
2 changes: 1 addition & 1 deletion ReCapProject/Core/Entities/Concrete/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public class User : IEntity
public byte[] PasswordHash { get; set; }
public bool Status { get; set; }
public DateTime? Age { get; set; }
}
}
}
5 changes: 5 additions & 0 deletions ReCapProject/Core/Extensions/ErrorDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ public class ValidationErrorDetails : ErrorDetails
{
public IEnumerable<ValidationFailure> ValidationErrors { get; set; }
}

public class SecurityErrorDetail : ErrorDetails
{

}
}
Loading

0 comments on commit f7a54d0

Please sign in to comment.