public static void CalculateQuote(CarSeeker carSeeker, out int totalPrice) { int currentPrice = 50; if (DateTime.Now.Year - carSeeker.DateOfBirth.Value.Year < 25 && DateTime.Now.Year - carSeeker.DateOfBirth.Value.Year > 18 && DateTime.Now.Year - carSeeker.DateOfBirth.Value.Year < 100) { currentPrice += 25; } if (DateTime.Now.Year - carSeeker.DateOfBirth.Value.Year < 18) { currentPrice += 100; } if (DateTime.Now.Year - carSeeker.DateOfBirth.Value.Year > 100) { currentPrice += 25; } if (carSeeker.CarYear.Value.Year < 2000) { currentPrice += 25; } if (carSeeker.CarYear.Value.Year > 2015) { currentPrice += 25; } string lowerCarMake = carSeeker.CarMake.ToLower(); string lowerCarModel = carSeeker.CarModel.ToLower(); if (lowerCarMake == "porsche" && lowerCarModel != "911 carrera") { currentPrice += 25; } if (lowerCarMake == "porsche" && lowerCarModel == "911 carrera") { currentPrice += 50; } for (int i = 0; i < carSeeker.SpeedingTickets; i++) { if (i != carSeeker.SpeedingTickets) { currentPrice += 10; } } if (carSeeker.HasHadDUI == true) { currentPrice += (currentPrice / 4); } if (carSeeker.CoverageVsLiability == true) { currentPrice += (currentPrice / 2); } totalPrice = currentPrice; }
public ActionResult ProcessCarSeeker(string firstName, string lastName, string emailAddress, DateTime dateOfBirth, DateTime carYear, string carMake, string carModel, bool?hasHadDUI, int?speedingTickets, bool?coverageVsLiability) { using (CarQuotesDBEntities db = new CarQuotesDBEntities()) { var carSeeker = new CarSeeker(); carSeeker.FirstName = firstName; carSeeker.LastName = lastName; carSeeker.EmailAddress = emailAddress; carSeeker.DateOfBirth = dateOfBirth; carSeeker.CarYear = carYear; carSeeker.CarMake = carMake; carSeeker.CarModel = carModel; if (Request.Form["HasHadDUI"] == "Yes") { carSeeker.HasHadDUI = true; } else { carSeeker.HasHadDUI = false; } carSeeker.SpeedingTickets = speedingTickets; if (Request.Form["CoverageVsLiability"] == "Full Coverage") { carSeeker.CoverageVsLiability = true; } else { carSeeker.CoverageVsLiability = false; } db.CarSeekers.Add(carSeeker); db.SaveChanges(); var carSeekerProcessed = new CarSeekerProcessed(); var carSeekersProcessed = new List <CarSeekerProcessed>(); int finalQuote = 50; CarQuote.CalculateQuote(carSeeker, out finalQuote); carSeekerProcessed.FirstName = carSeeker.FirstName; carSeekerProcessed.LastName = carSeeker.LastName; carSeekerProcessed.EmailAddress = carSeeker.EmailAddress; carSeekerProcessed.DateOfBirth = carSeeker.DateOfBirth; carSeekerProcessed.CarYear = carSeeker.CarYear; carSeekerProcessed.CarMake = carSeeker.CarMake; carSeekerProcessed.CarModel = carSeeker.CarModel; carSeekerProcessed.HasHadDUI = carSeeker.HasHadDUI; carSeekerProcessed.SpeedingTickets = carSeeker.SpeedingTickets; carSeekerProcessed.CoverageVsLiability = carSeeker.CoverageVsLiability; carSeekerProcessed.FinalQuote = finalQuote; carSeekersProcessed.Add(carSeekerProcessed); return(View("YourQuote", carSeekersProcessed)); } }