public RentalResult Calculate(List <Rent> rents) { var result = new RentalResult(); foreach (var rent in rents) { result.RentResults.Add(CalculateRental(rent)); } return(result); }
public static string Build(ApplicationUserDto user, RentalResult rental) { var inBuilder = new StringBuilder(); inBuilder.AppendLine($"Invoice for: {user.Email}"); inBuilder.AppendLine("================================================"); inBuilder.AppendLine("Name - Type - Days - Price"); foreach (var item in rental.Equipment) { inBuilder.AppendLine($"{item.Name} | {item.Type} | {item.Days} | {item.Price:F2} €"); } inBuilder.AppendLine("================================================"); inBuilder.AppendLine($"Total: {rental.TotalPrice:F2}"); inBuilder.AppendLine($"Points earned: {rental.PointsEarned}"); return(inBuilder.ToString()); }
public IEnumerable <RentalResult> ProcessRentalEvents(IEnumerable <Rental> rentalEvents) { List <RentalResult> results = new List <RentalResult>(); foreach (var rentalEvent in rentalEvents) { try { var result = rentalCalculator.PerformRentalOperation(rentalEvent); rentalEvent.Customer.FrequentRenterPoints += result.FrequentRenterPointsAwarded; results.Add(result); } catch (Exception e) { var errorResult = new RentalResult(); errorResult.Errors.Add(e); results.Add(errorResult); } } return(results); }