public IActionResult Calculate() { CalculateCostVM calc = new CalculateCostVM() { FinalPrice = 0, }; return(View(calc)); }
public IActionResult Calculate(CalculateCostVM calc) { if (ModelState.IsValid) { var x = service.CalculateCost(calc); return(View(service.CalculateCost(calc))); } else { return(View()); } }
internal CalculateCostVM CalculateCost(CalculateCostVM calcVM) { calcVM.RentedCar = carRentalContext.Car.SingleOrDefault(c => c.CarRegistrationNumber.ToUpper() == calcVM.CarRegistration); //Customer customer = Booking booking = carRentalContext.Booking .SingleOrDefault(c => c.RentedCar == calcVM.RentedCar.Id && c.CustomerId == carRentalContext.Booking .SingleOrDefault(b => b.Customer.CustomerSsn == calcVM.CustomerSSN).Customer.Id); double price = -1; double kmPrice = 1; int numberOfKm = calcVM.DistanceEnd - calcVM.RentedCar.DistanceStart; int baseDayRental = 200; double numberOfDays = calcVM.DateReturned.Subtract((DateTime)calcVM.RentedCar.RentalStart).TotalDays + 1; //Just nu räknas både start- och slutdag som dagar man betalar för. if (calcVM.RentedCar.CarType == "Liten bil") { price = baseDayRental * numberOfDays; } else if (calcVM.RentedCar.CarType == "Van") { price = baseDayRental * numberOfDays * 1.2 + (kmPrice * numberOfKm); } else if (calcVM.RentedCar.CarType == "Minibuss") { price = baseDayRental * numberOfDays * 1.7 + (kmPrice * numberOfKm * 1.5); } else { throw new Exception("Type of car not supported"); } calcVM.FinalPrice = price; return(calcVM); }