// GET: Admin public ActionResult Index() { using (QuoteEntities db = new QuoteEntities()) { var customers = (from c in db.Customers select c).ToList(); var customersVM = new List <AdminViewModel>(); foreach (var customer in customers) { var customerVM = new AdminViewModel(); customerVM.Id = customer.Id; customerVM.FirstName = customer.FirstName; customerVM.LastName = customer.LastName; customerVM.EmailAddress = customer.EmailAddress; customerVM.QuoteAmount = "$" + customer.QuoteAmount; customersVM.Add(customerVM); } return(View(customersVM)); } }
public ActionResult VmQuote() { using (QuoteEntities db = new QuoteEntities()) { var quotes = db.Quotes; var VmQuotes = new List <VmQuote> (); foreach (var quote in quotes) { var VmQuote = new VmQuote(); VmQuote.FirstName = quote.FirstName; VmQuote.LastName = quote.LastName; VmQuote.EmailAddress = quote.EmailAddress; VmQuote.FinalQuote = quote.FinalQuote; VmQuotes.Add(VmQuote); } return(View(VmQuotes)); } }
// GET: Admin public ActionResult Index() { using (QuoteEntities db = new QuoteEntities()) { var quotes = (from c in db.Quotes select c).ToList(); var VmQuotes = new List <VmQuote>(); foreach (var quote in quotes) { var VmQuote = new VmQuote(); VmQuote.Id = quote.Id; VmQuote.FirstName = quote.FirstName; VmQuote.LastName = quote.LastName; VmQuote.EmailAddress = quote.EmailAddress; VmQuote.FinalQuote = quote.FinalQuote; VmQuotes.Add(VmQuote); } return(View(VmQuotes)); } }
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 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")); } }