public ActionResult EnterCarInfo(string firstname, string lastname, string email, string dob, string caryear, string carmake, string carmodel, string numberspeedingtickets, string fullorliability, string dui) { if (string.IsNullOrEmpty(firstname) || string.IsNullOrEmpty(lastname) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(carmake) || string.IsNullOrEmpty(carmodel) || string.IsNullOrEmpty(fullorliability) || string.IsNullOrEmpty(dob) || string.IsNullOrEmpty(caryear) || string.IsNullOrEmpty(numberspeedingtickets) || string.IsNullOrEmpty(dui)) { return(View("~/Views/Shared/Error.cshtml")); } else { using (CarQuoteDBEntities db = new CarQuoteDBEntities()) { var carquote = new CarQuote(); carquote.FirstName = firstname; carquote.LastName = lastname; carquote.Email = email; carquote.DOB = Convert.ToDateTime(dob); carquote.CarYear = Convert.ToInt32(caryear); carquote.CarMake = carmake; carquote.CarModel = carmodel; carquote.DUI = Convert.ToBoolean(dui); carquote.NumberSpeedingTickets = Convert.ToInt32(numberspeedingtickets); carquote.FullOrLiability = fullorliability; var quotecalculator = new QuoteCalculator(); carquote.Quote = quotecalculator.GetQuote(carquote); db.CarQuotes.Add(carquote); db.SaveChanges(); return(View("ShowQuote", carquote)); } } }
// GET: Admin public ActionResult Index() { using (CarQuoteDBEntities db = new CarQuoteDBEntities()) { var carquotes = db.CarQuotes; var carquotesVms = new List <CarQuoteVm>(); foreach (var carquote in carquotes) { var carquoteVm = new CarQuoteVm(); carquoteVm.FirstName = carquote.FirstName; carquoteVm.LastName = carquote.LastName; carquoteVm.Email = carquote.Email; carquoteVm.Quote = carquote.Quote; carquotesVms.Add(carquoteVm); } return(View(carquotesVms)); } }