public ActionResult Car_Info(string firstName, string lastName, string emailAddress, DateTime dateofbirth, int caryear, string carmake, string carmodel, int speedingtickets, string dui, string coverage, int?total) { if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress) || string.IsNullOrEmpty(carmake) || string.IsNullOrEmpty(carmodel)) { return(View("~/Views/Shared/Error.cshtml")); } else { using (Car_InsuranceEntities db = new Car_InsuranceEntities()) { var signup = new Car_Insurance(); signup.FirstName = firstName; signup.Lastname = lastName; signup.EmailAddress = emailAddress; signup.DateOfBirth = dateofbirth; signup.CarYear = caryear; signup.SpeedingTickets = speedingtickets; signup.Dui = dui; signup.Coverage = coverage; signup.Total = total; total = 50; var today = DateTime.Today; var age = today.Year - dateofbirth.Year; if (dateofbirth > today.AddYears(-25)) { total = total + 25; } else if (dateofbirth > today.AddYears(-18)) { total = total + 100; } else if (dateofbirth > today.AddYears(-100)) { total = total + 25; } if (caryear < 2000) { total = total + 25; } else if (caryear > 2015) { total = total + 25; } if (carmake == "Porsche") { total = total + 25; } if (carmake == "Porsche" && carmodel == "911 Carrera") { total = total + 25; } // foreach (var ticket in speedingtickets) //{ //} if (speedingtickets > 0) { total = total + (speedingtickets * 10); } if (dui == "Yes" || dui == "yes" || dui == "yeah") { total = total + (total * 25 / 100); } else { total = total + 0; } if (coverage == "Yes" || coverage == "yes" || coverage == "yeah") { total = total + (total * 50 / 100); } else { total = total + 0; } signup.Total = total; db.Car_Insurance.Add(signup); db.SaveChanges(); @ViewBag.Total = total; return(View("Total")); } } }
public ActionResult Customer(string firstName, string lastName, string emailAddress, string dateOfBirth, int carYear, string carMake, string carModel, string dui, int numberOfTickets, string fullOrLiability, int?quote) { if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress) || string.IsNullOrEmpty(dateOfBirth) || string.IsNullOrEmpty(Convert.ToString(carYear)) || string.IsNullOrEmpty(carMake) || string.IsNullOrEmpty(carModel) || string.IsNullOrEmpty(dui) || string.IsNullOrEmpty(Convert.ToString(numberOfTickets)) || string.IsNullOrEmpty(fullOrLiability)) { return(View("~/Views/Shared/Error.cshtml")); } else { using (Car_InsuranceEntities db = new Car_InsuranceEntities()) { var customer = new Customer(); customer.FirstName = firstName; customer.LastName = lastName; customer.EmailAddress = emailAddress; customer.DateOfBirth = dateOfBirth; customer.CarYear = carYear; customer.CarMake = carMake; customer.CarModel = carModel; customer.DUI = dui; customer.NumberOfTickets = numberOfTickets; customer.FullOrLiability = fullOrLiability; customer.Quote = quote; var today = DateTime.Today; int total = 0; quote = 50; var dob = Convert.ToDateTime(customer.DateOfBirth); // getting age and price additional cost for quote if (dob.Year > today.Year - 25) { total = total + 25; } else if (dob.Year > today.Year - 18) { total = total + 100; } else if (dob.Year < today.Year - 100) { total = total + 25; } if (customer.CarYear < 2000) //getting year of car and additional cost for quote { total = total + 25; } else if (customer.CarYear > 2015) { total = total + 25; } if (customer.CarMake == "Porsche") //getting make of car and additional cost for quote { total = total + 25; } if (customer.CarModel == "911 Carrera") //getting model and additional cost for quote { total = total + 25; } if (customer.NumberOfTickets > 0) //getting number of speeding tickets and additional cost for quote { total = total + (numberOfTickets * 10); } if (customer.DUI == "yes") //getting DUI and additinal cost for quote { total = Convert.ToInt32(total * .25 + total); } if (customer.FullOrLiability == "Full") // getting full coverage additional cost for quote { total = Convert.ToInt32(total * .50 + total); } customer.Quote = quote + total; db.Customers.Add(customer); db.SaveChanges(); @ViewBag.Total = customer.Quote + total; } return(View("Success")); } }