Beispiel #1
0
        public ActionResult GetQuote(GetQuoteModel quote)
        {
            // return estimated quote based on user input
            DateTime Birthday = quote.Birthday;
            DateTime now      = DateTime.Today;
            int      age      = now.Year - Birthday.Year;

            if (now < Birthday.AddYears(age))
            {
                age--;
            }
            //age method  update EstimatedQuote
            var EstimatedQuote = quote.Age(age);

            //car method, make model year; update EstimatedQuote
            EstimatedQuote = quote.Car(EstimatedQuote, quote.CarYear, quote.CarMake.ToLower(), quote.CarModel.ToLower());
            // speeding tickets method; update EstimatedQuote
            EstimatedQuote = quote.Tickets(EstimatedQuote, quote.Ticket);
            //dui method update EstimatedQuote
            EstimatedQuote = quote.YesDui(EstimatedQuote, quote.Dui);
            //coverage method update EstimatedQuote
            EstimatedQuote = quote.YesCoverage(EstimatedQuote, quote.Coverage);

            //instantiate entitiy object and pass in connection string to access to db
            using (CarInsurance1Entities db = new CarInsurance1Entities())
            {
                var user = new User
                { //pass db values passed to model from UI
                    FirstName      = quote.FirstName,
                    LastName       = quote.LastName,
                    EmailAddress   = quote.EmailAddress,
                    Birthday       = quote.Birthday,
                    CarYear        = quote.CarYear,
                    CarMake        = quote.CarMake,
                    CarModel       = quote.CarModel,
                    Dui            = quote.Dui,
                    Ticket         = quote.Ticket,
                    Coverage       = quote.Coverage,
                    EstimatedQuote = Convert.ToDecimal(EstimatedQuote)
                };
                db.Users.Add(user); // add to db
                db.SaveChanges();   //save to db
            }
            var getquoteVms = new List <GetQuoteVm>
            {
                new GetQuoteVm {
                    EstimatedQuote = EstimatedQuote
                }
            };

            return(View(getquoteVms));
        }
 // GET: Admin
 public ActionResult Index()
 {
     //instantiate entities object and passed into connection string to access to db
     using (CarInsurance1Entities db = new CarInsurance1Entities())
     {
         var users       = db.Users;                // access db, contains all records in db
         var getquoteVms = new List <GetQuoteVm>(); // create new list of viewmodels
         //map the viewmodels from the model to viewmodel then pass list to view
         foreach (var user in users)
         {
             var getquoteVm = new GetQuoteVm
             { // map db object to view model
                 FirstName      = user.FirstName,
                 LastName       = user.LastName,
                 EmailAddress   = user.EmailAddress,
                 EstimatedQuote = Convert.ToDouble(user.EstimatedQuote)
             };
             getquoteVms.Add(getquoteVm);
         }
         return(View(getquoteVms));
     }
 }