public ActionResult Create([Bind(Include = "Id,FirstName,LastName,EmailAddress,DateOfBirth,CarYear,CarMake,CarModel,DUI,SpeedingTickets,CoverageType,Quote")] Insuree insuree) { if (ModelState.IsValid) { db.Insurees.Add(insuree); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(insuree)); }
public ActionResult Create([Bind(Include = "Id,FirstName,LastName,EmailAddress,DateOfBirth,CarYear,CarMake,CarModel,DUI,SpeedingTickets,CoverageType,Quote")] Insuree insuree) { if (ModelState.IsValid) { int total = 50; //int birthdate = Convert.ToInt32(insuree.DateOfBirth); //int currentAge = DateTime.Now.Year - birthdate; if ((DateTime.Now).Year - (Convert.ToDateTime(insuree.DateOfBirth)).Year < 18) { total += 25; } if ((DateTime.Now).Year - (Convert.ToDateTime(insuree.DateOfBirth)).Year < 25) { total += 100; } if ((DateTime.Now).Year - (Convert.ToDateTime(insuree.DateOfBirth)).Year > 100) { total += 25; } int vehicleYear = Convert.ToInt32(insuree.CarYear); if (vehicleYear < 2000) { total += 25; } else { total += 0; } if (vehicleYear > 2015) { total += 25; } if (insuree.CarMake == "Porsche") { total += 25; } if (insuree.CarMake == "Carrera") { total += 25; } int ticket = Convert.ToInt32(insuree.SpeedingTickets); if (ticket >= 1) { total += 25; } //bool drinker = Convert.ToBoolean(DUI); if (insuree.DUI == true) { total = total + Convert.ToInt32(.25m); } //bool type = Convert.ToBoolean(coverageType); if (insuree.CoverageType == true) { total = total + Convert.ToInt32(.50m); } else { total += 0; } //if (insuree.Quote > 0) //{ // Console.WriteLine("Your Quote is: {0} ", total); //Doesn't work for an MVC // Console.ReadLine(); //} insuree.Quote = total; db.Insurees.Add(insuree); db.SaveChanges(); ViewBag.Message = "Your total is: $" + total; return(View("Success")); //return RedirectToAction("Index"); } return(View(insuree)); }
public ActionResult Quote(string firstName, string lastName, string emailAddress, DateTime DateOfBirth, string CarYear, string CarMake, string CarModel, bool DUI, string Tickets, bool Full) { if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress)) { return(View("~/Views/Shared/Error.cshtml")); } else { using (QuoteEntities db = new QuoteEntities()) { var quote = new Quote(); quote.FirstName = firstName; quote.LastName = lastName; quote.EmailAddress = emailAddress; var today = DateTime.Today; var age = today.Year - DateOfBirth.Year; if (DateOfBirth > today.AddYears(-age)) { --age; } quote.StartingTotal = 50; if (age <= 18) { quote.StartingTotal = quote.StartingTotal + 100; } if (age <= 25 && age >= 19) { quote.StartingTotal = quote.StartingTotal + 25; } if (age >= 100) { quote.StartingTotal = quote.StartingTotal + 25; } int carYear = Convert.ToInt32(CarYear); if (carYear <= 1999) { quote.StartingTotal = quote.StartingTotal + 25; } if (carYear >= 2015) { quote.StartingTotal = quote.StartingTotal + 25; } if (CarMake == "Porsche") { quote.StartingTotal = quote.StartingTotal + 25; } if (CarMake == "Porsche" && CarModel == "911 Carrera") { quote.StartingTotal = quote.StartingTotal + 25; } int tickets = Convert.ToInt32(Tickets); tickets = tickets * 10; quote.FinalQuote = quote.StartingTotal + tickets; int dui = Convert.ToInt32(1.25); int coverage = Convert.ToInt32(1.5); if (DUI == true) { quote.FinalQuote = quote.FinalQuote * dui; } if (Full == true) { quote.FinalQuote = quote.FinalQuote * coverage; } ViewBag.finalQuote = quote.FinalQuote; int FinalQuote = quote.FinalQuote; db.Quotes.Add(quote); db.SaveChanges(); } return(View("Index")); } }
public ActionResult Submit(string firstName, string lastName, string emailAddress, string dateOfBirth, string carYear, string carMake, string carModel, string dui, string speedingTickets, string insType) { if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress) || string.IsNullOrEmpty(dateOfBirth) || string.IsNullOrEmpty(carYear) || string.IsNullOrEmpty(carMake) || string.IsNullOrEmpty(carModel) || string.IsNullOrEmpty(dui) || string.IsNullOrEmpty(speedingTickets) || string.IsNullOrEmpty(insType)) { return(View("~/Views/Shared/Error.cshtml")); } else //Recording into DB { using (QuoteEntities db = new QuoteEntities()) { var customer = new Customer(); customer.FirstName = firstName; customer.LastName = lastName; customer.EmailAddress = emailAddress; customer.DateOfBirth = dateOfBirth.AsDateTime(); customer.CarYear = carYear; customer.CarMake = carMake; customer.CarModel = carModel; customer.DUI = dui; customer.SpeedingTickets = Convert.ToInt32(speedingTickets); customer.InsType = insType; //Quote Calculation int monthlyBaseAmount = 50; int monthlyAgeAmount = 0; int monthlyCarYearAmount = 0; int monthlyCarMakeAmount = 0; int monthlyCarModelAmount = 0; int monthlySpeedTicketsAmount = 0; //Calculating age and extra amount depending on the age DateTime dob = DateTime.Parse(dateOfBirth); int age = DateTime.Now.Year - dob.Year; if (DateTime.Now.DayOfYear < dob.DayOfYear) { age = age - 1; } if (age < 18) { monthlyAgeAmount = 100; } else if (age < 25 && age >= 18) { monthlyAgeAmount = 25; } else if (age > 100) { monthlyAgeAmount = 25; } //Calculating extra amount depending on the year car made int year = Convert.ToInt32(carYear); if (year < 2000 || year > 2015) { monthlyCarYearAmount = 25; } //Calculating extra amount depending on the car manufacture and model string carName = carMake.ToLower(); string carMod = carModel.ToLower(); if (carName == "porsche") { monthlyCarMakeAmount = 25; } if (carName == "porsche" && carMod == "911 carrera") { monthlyCarModelAmount = 25; } //Calculating extra amount depending on number of speeding tickets monthlySpeedTicketsAmount = 10 * Convert.ToInt32(speedingTickets); //Calculation Total double totalAmount = monthlyBaseAmount + monthlyAgeAmount + monthlyCarYearAmount + monthlyCarMakeAmount + monthlyCarModelAmount + monthlySpeedTicketsAmount; //Calculating Total depending on if DUI ever happened string duiExist = dui.ToLower(); if (duiExist == "yes") { totalAmount = 1.25 * totalAmount; } //Calculating Total depending on insurance cover choice string insCover = insType.ToLower(); if (insCover == "full coverage") { totalAmount = Math.Round((1.5 * totalAmount), 2); } //Add quote amount into DB customer.QuoteAmount = Convert.ToString(totalAmount); db.Customers.Add(customer); db.SaveChanges(); } return(View("Index")); } }
public void Update(T entity) { Context.SaveChanges(); //Context.Entry(entity).State = EntityState.Modified; }