Ejemplo n.º 1
0
        public ActionResult GetQuote(string firstName, string lastName, string email,
                                     DateTime dateOfBirth, int carYear, string carMake, string carModel,
                                     bool dui, int ticketNumber, bool fullCoverage)
        {
            using (Car_Insurance_QuoteEntities db = new Car_Insurance_QuoteEntities())
            {
                // Maps user input to DB.
                var quote = new Quote();
                quote.FirstName    = firstName;
                quote.LastName     = lastName;
                quote.Email        = email;
                quote.DateOfBirth  = dateOfBirth;
                quote.CarYear      = carYear;
                quote.CarMake      = carMake;
                quote.CarModel     = carModel;
                quote.DUI          = dui;
                quote.TicketNumber = ticketNumber;
                quote.FullCoverage = fullCoverage;
                quote.Total        = CalcQuote(quote); //Quote total is calulated.

                db.Quotes.Add(quote);                  //Data added to DB.
                db.SaveChanges();                      // Data saved to DB

                return(View(quote));
            }
        }
Ejemplo n.º 2
0
        // GET: Admin
        public ActionResult Index()
        {
            using (Car_Insurance_QuoteEntities db = new Car_Insurance_QuoteEntities())
            {
                List <Quote> quotes = db.Quotes.ToList(); // Creates a List of all quotes from the DB.

                var quoteVMs = new List <QuoteVM>();      // Instantiates a View Model List, DB info is mapped into it.
                // Maps pertinent info from the DB to the View Model.
                foreach (var quote in quotes)
                {
                    QuoteVM quoteVM = new QuoteVM();
                    quoteVM.FirstName = quote.FirstName;
                    quoteVM.LastName  = quote.LastName;
                    quoteVM.Email     = quote.Email;
                    quoteVM.Total     = quote.Total;

                    quoteVMs.Add(quoteVM); // Add the quote into the View Model.
                }

                return(View(quoteVMs));
            }
        }