public async Task <ActionResult <Rental> > EndRental(int id) { var rental = await _context.Rentals.FindAsync(id); if (rental == null) { return(NotFound()); } if (rental.Ended) { return(BadRequest("Rental is already ended")); } rental.RentalEnd = System.DateTime.Now; rental.Ended = true; rental.Bike.IsRented = false; rental.Customer.HasActiveRental = false; rental.TotalCost = _calculator.CalculateCosts(rental.RentalBegin, rental.RentalEnd, rental.Bike.RentalPriceFirstHour, rental.Bike.RentalPricePerAdditionalHour); _context.Entry(rental).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); }