public decimal TotalPriceCalculator(RentalEvent rentalEvent) { var daysRented = (rentalEvent.EndDate - rentalEvent.StartDate).TotalDays; if (daysRented == 0) { daysRented = 1; } var basePrice = GetBasePrice(daysRented, rentalEvent.Vehicle.PricePerDay); var discount = GetDiscountPercentage(daysRented, rentalEvent.Customer.IsVip); return(GetDiscountedPrice(basePrice, discount)); }
public void AddRentalEvent(RentalEvent rentalEvent) { var addedRentalEvent = new RentalEvent { BookInLibrary = rentalEvent.BookInLibrary, EventDate = rentalEvent.EventDate, RentalUser = rentalEvent.RentalUser }; _dbContext.RentalEvents.Add(addedRentalEvent); _dbContext.SaveChanges(); }
public async Task AddRentalEvent(Vehicle vehicle, ApplicationUser customer, BookVehicleDTO bookVehicleDTO) { var rentalEvent = new RentalEvent { Customer = customer, Vehicle = vehicle, StartDate = bookVehicleDTO.StartDate, EndDate = bookVehicleDTO.EndDate, IsActive = true }; rentalEvent.TotalRentalEventPrice = _helper.TotalPriceCalculator(rentalEvent); await _context.RentalEvents.AddAsync(rentalEvent); await _context.SaveChangesAsync(); }