private static void AddQuoteToDb(Quote quote) { using (InsuranceQuotesEntities db = new InsuranceQuotesEntities()) { var addquote = new quote(); addquote.fname = quote.fname; addquote.lname = quote.lname; addquote.email = quote.email; addquote.dob = new DateTime(quote.doby, quote.dobm, quote.dobd); addquote.car_year = (short)quote.caryear; addquote.car_make = quote.carmake; addquote.car_model = quote.carmodel; addquote.had_dui = (quote.dui == 1) ? true : false; addquote.sp_ticket = (short)quote.tickets; addquote.coverage = quote.coverage; addquote.premium = quote.premium; db.quotes.Add(addquote); db.SaveChanges(); } }
public ActionResult Quote(string firstName, string lastName, string emailAddress, DateTime dateOfBirth, string carYear, string carMake, string carModel, string duiStatus, int speedingTicketNum, string typeOfCoverage) { if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress)) { return(View("~/Views/Shared/Error.cshtml")); } else { using (InsuranceQuotesEntities db = new InsuranceQuotesEntities()) { var quote = new Quote(); quote.FirstName = firstName; quote.LastName = lastName; quote.EmailAddress = emailAddress; quote.DateOfBirth = Convert.ToDateTime(dateOfBirth); quote.CarYear = carYear; quote.CarMake = carMake; quote.CarModel = carModel; quote.DUIStatus = duiStatus; quote.SpeedingTicketNum = speedingTicketNum.ToString(); quote.TypeOfCoverage = typeOfCoverage; Calculation result = new Calculation(); quote.CustomerQuote = result.CalculateQuote(firstName, lastName, emailAddress, dateOfBirth, carYear, carMake, carModel, duiStatus, speedingTicketNum, typeOfCoverage); db.Quotes.Add(quote); db.SaveChanges(); var displayQuoteVm = new DisplayQuoteVm(); displayQuoteVm.CustomerQuote = result.CalculateQuote(firstName, lastName, emailAddress, dateOfBirth, carYear, carMake, carModel, duiStatus, speedingTicketNum, typeOfCoverage); return(View("QuoteDisplay", displayQuoteVm)); } } }
public ActionResult GetQuote(string firstName, string lastName, string emailAddress, string dOB, string carYear, string carMake, string carModel, string tickets, string dUI, string insType) { if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress) || string.IsNullOrEmpty(dOB) || string.IsNullOrEmpty(carYear) || string.IsNullOrEmpty(carMake) || string.IsNullOrEmpty(carModel) || string.IsNullOrEmpty(tickets) || string.IsNullOrEmpty(dUI) || string.IsNullOrEmpty(insType)) { return(View("~/Views/Shared/Error.cshtml")); } else { using (InsuranceQuotesEntities db = new InsuranceQuotesEntities()) { var quote = new Quote(); quote.FirstName = firstName; quote.LastName = lastName; quote.EmailAddress = emailAddress; quote.DOB = Convert.ToDateTime(dOB); quote.CarYear = Convert.ToInt32(carYear); quote.CarMake = carMake; quote.CarModel = carModel; quote.Tickets = Convert.ToInt32(tickets); quote.DUI = dUI; quote.InsType = insType; var today = DateTime.Now; var age = today.Year - quote.DOB.Year; decimal x = 50 + (10 * quote.Tickets); if (age < 18) { x = x + 100; } else if (age < 18) { x = x + 25; } else if (age > 100) { x = x + 100; } if (quote.CarYear < 2000) { x = x + 25; } if (quote.CarYear > 2015) { x = x + 25; } if (quote.CarMake == "Porsche") { x = x + 25; } if (quote.CarMake == "Porsche" && quote.CarModel == "911 Carrera") { x = x + 25; } if (quote.DUI == "yes") { x = x + (x / 4); } if (quote.InsType == "full") { x = x + (x / 2); } quote.Quote1 = x; db.Quotes.Add(quote); db.SaveChanges(); int userid = quote.Id; return(RedirectToAction("Success", new { Id = userid })); } //var quoteVMs = new List<QuoteVm>(); //foreach (var quote in quoteVMs) //{ // var quoteVM = new QuoteVm(); // quoteVM.ID = quote.ID; // quoteVM.FirstName = quote.FirstName; // quoteVM.LastName = quote.LastName; // quoteVM.Quote = quote.Quote; // quoteVMs.Add(quoteVM); // lastQuote = Convert.ToString(quote.Quote); //} } }
public ActionResult Quote(string firstName, string lastName, string emailAddress, DateTime dob, string carYear, string carMake, string carModel, bool dui, string speeding, string covrage) { using (InsuranceQuotesEntities db = new InsuranceQuotesEntities()) { var app = new application(); app.FirstName = firstName; app.LastName = lastName; app.EmailAddress = emailAddress; app.DateOfBirth = dob; app.CarYear = Convert.ToInt32(carYear); app.CarMake = carMake; app.CarModel = carModel; app.DUI = dui; app.SpeedingTickets = Convert.ToInt32(speeding); app.Coverage = covrage; double quote = 50; int month = app.DateOfBirth.Value.Month - DateTime.Now.Month; int age = DateTime.Now.Year - app.DateOfBirth.Value.Year; if (month > 0) { age--; } if (age < 25 || age > 100) { if (age < 18) { quote += 100; } else { quote += 25; } } if (app.CarYear < 2000 || app.CarYear > 2015) { quote += 25; } if (app.CarMake.ToLower() == "porsche") { quote += 25; if (app.CarModel.ToLower() == "911 carrera" || app.CarModel.ToLower() == "911carrera") { quote += 25; } } quote += (app.SpeedingTickets.Value * 10); if (app.DUI.Value) { quote += (quote * 0.25); } if (app.Coverage.ToLower() == "full") { quote += (quote * 0.5); } app.Quote = Convert.ToInt32(quote); db.applications.Add(app); db.SaveChanges(); return(View(app)); } }