public async Task <IDataResult <Rental> > AddAsync(RentalAddDto rentalCreateDto) { var ruleResult = BusinessRules.Run( (await CheckRentDateAsync(rentalCreateDto.CarId, rentalCreateDto.RentDate)), CheckIfReturnDateSmallOfRentDate(rentalCreateDto.RentDate, rentalCreateDto.ReturnDate.Value), (await CheckCreditScoreByCustomerIdAsync(rentalCreateDto.CustomerId, rentalCreateDto.CarId))); if (!ruleResult.Success) { return(new ErrorDataResult <Rental>(null, ruleResult.Message)); } var rentalToAdd = new Rental() { CarId = rentalCreateDto.CarId, CustomerId = rentalCreateDto.CustomerId, RentDate = rentalCreateDto.RentDate, ReturnDate = rentalCreateDto.ReturnDate }; bool addResult = await _rentalDal.AddAsync(rentalToAdd); if (addResult == true) { return(new SuccessDataResult <Rental>(rentalToAdd, Messages.RentalAdded)); } else { return(new ErrorDataResult <Rental>(null, Messages.RentalNotAdded)); } }
public async Task <IResult> Add(Rental rental) { var result = BusinessRules.Run(await IsRentable(rental), await DriveExperienceSufficiency(rental), await CheckFindeksScoreSufficiency(rental)); if (result != null) { return(result); } var car = await _carDal.GetAsync(c => c.Id == rental.CarId); car.Available = false; await _carDal.UpdateAsync(car); await _rentalDal.AddAsync(rental); return(new SuccessResult(Messages.RentalCreated)); }
public async Task <IResult> AddAsync(Rental entity) { await _rentalDal.AddAsync(entity); return(new SuccessResult()); }