//This method createds ViewModel to restrict the information provided for the Model.
        public ActionResult Admin()
        {
            var insureeVms = new List <InsureeVM>();

            foreach (var insuree in db.Insurees)
            {
                var insureeVm = new InsureeVM();
                insureeVm.Id           = insuree.Id;
                insureeVm.FirstName    = insuree.FirstName;
                insureeVm.LastName     = insuree.LastName;
                insureeVm.EmailAddress = insuree.EmailAddress;
                // decimal quote = calculateQuote(insuree);
                insureeVm.quote = insuree.Quote;
                insureeVms.Add(insureeVm);
            }
            return(View(insureeVms));
        }
        public ActionResult Index()
        {
            List <Insuree> insureeList = db.Insurees.ToList();   //I used List but you can also use a "var" (variable)
                                                                 //to get info from the DB to prep
            List <InsureeVM> adminList = new List <InsureeVM>(); //made a empty list or "var" called it adminList & instanciate it as a new <list>object the data types are like a shadow ViewModel only specific info

            foreach (var insuree in insureeList)                 // this foreach loop I'm creating a temporary name so I can reference each item in the list of insureeList
            {
                InsureeVM adminItem = new InsureeVM();           //created a new shadow (new view modelItem) that we will add to the list admistList calling it adminItem
                adminItem.FirstName    = insuree.FirstName;
                adminItem.LastName     = insuree.LastName;
                adminItem.QUOTE        = insuree.QUOTE; // adminItem.Etcetc.. is the specific properties we want to pull from the actual View to add to the shadowview of it(viewmodel)
                adminItem.EmailAddress = insuree.EmailAddress;
                adminList.Add(adminItem);               // now that the adminItem has all the properties we want we use this to add it to the adminList
            }
            return(View(adminList));                    //all returns this view to the adminlist to actually be viewable on the webpage
        }
예제 #3
0
        // GET: Admin
        public ActionResult Index()
        {
            using (InsuranceEntities db = new InsuranceEntities())
            {
                var insurees   = db.Insurees.ToList();
                var insureeVms = new List <InsureeVM>();
                foreach (var insuree in insurees)
                {
                    var insureeVm = new InsureeVM();
                    insureeVm.Quote        = insuree.Quote;
                    insureeVm.FirstName    = insuree.FirstName;
                    insureeVm.LastName     = insuree.LastName;
                    insureeVm.EmailAddress = insuree.EmailAddress;
                    insureeVms.Add(insureeVm);
                }

                return(View(insureeVms));
            }
        }
예제 #4
0
        // GET: Admin
        public ActionResult Index()
        {
            List <InsureeVM> insureeVMs = new List <InsureeVM>();

            using (InsuranceEntities db = new InsuranceEntities())
            {
                var insurees = db.Insurees;
                foreach (var insuree in insurees)
                {
                    var insureeVM = new InsureeVM();
                    insureeVM.FirstName    = insuree.FirstName;
                    insureeVM.LastName     = insuree.LastName;
                    insureeVM.EmailAddress = insuree.EmailAddress;
                    insureeVM.Quote        = insuree.Quote;
                    insureeVMs.Add(insureeVM);
                }
            }
            return(View(insureeVMs));
        }
예제 #5
0
        public ActionResult QuoteCalculator()
        {
            using (InsuranceEntities db = new InsuranceEntities())
            {
                var insurees   = db.Insurees;
                var autoQuotes = db.AutoQuotes;

                var autoQuoteVMs = new List <AutoQuoteVM>();
                var insureeVMs   = new List <InsureeVM>();

                {
                    foreach (Insuree insuree in insurees)
                    {
                        var autoQuote   = new AutoQuote();
                        var autoQuoteVM = new AutoQuoteVM();
                        var insureeVM   = new InsureeVM();


                        var baseRate = 50.00;


                        var age = DateTime.Now.Year - insuree.DateOfBirth.Year;



                        if (insuree.DateOfBirth.Month > DateTime.Now.Month ||
                            insuree.DateOfBirth.Month == DateTime.Now.Month &&
                            insuree.DateOfBirth.Day > DateTime.Now.Day)
                        {
                            age--;
                        }

                        var insureeAge = Convert.ToInt32(age);


                        double under18    = (insureeAge < 18) ? 100.00 : 0.00;
                        double btw19and25 = ((insureeAge > 18) && (age <= 25)) ? 50.00 : 0.00;
                        double over25     = (insureeAge > 25) ? 25.00 : 0.00;


                        double autoYearPrior2000 = (insuree.CarYear < 2000) ? 25.00 : 0.00;
                        double autoYearAfter2015 = (insuree.CarYear > 2015) ? 25.00 : 0.00;


                        double yesIsPorsche = (insuree.CarMake == "Porsche") ? 25.00 : 0.00;
                        double yesIsCarrera = (insuree.CarModel == "Carrera") ? 25.00 : 0.00;

                        double subtotalBeforeDUI = baseRate + under18 + btw19and25 + over25 +
                                                   autoYearPrior2000 + autoYearAfter2015 + yesIsPorsche +
                                                   yesIsCarrera;

                        int    isTrueDUI        = (insuree.DUI == true) ? 1 : 0;
                        double yesDUI           = subtotalBeforeDUI * 0.25;         //Calculating the rate of increase if DUI is true
                        double duiRate          = (isTrueDUI == 1) ? yesDUI : 0.00; // value that will be placed in Quote DUIRateUP25Percent
                        double subtotalAfterDUI = duiRate + subtotalBeforeDUI;      // value that will be placed in Quote SubTotalAfterDUICalc

                        int    speedingTickets     = insuree.SpeedingTickets;
                        double speedingTicketsRate = speedingTickets * 10.00;

                        double subtotalBeforeCoverageCalc = subtotalAfterDUI + speedingTicketsRate;
                        int    coverageTypeFull           = (insuree.CoverageType == true) ? 1 : 0;
                        double fullCoverageRate           = subtotalBeforeCoverageCalc * 0.50;                 // calculating the rate of increase if FullCoverage is true
                        double yesFullCoverage            = (coverageTypeFull == 1) ? fullCoverageRate : 0.00; //value that will be placed in FullCovRateUP50Percent
                        double subtotalAfterCoverageCalc  = subtotalBeforeCoverageCalc + yesFullCoverage;



                        double monthlyQuote = subtotalAfterCoverageCalc;
                        double yearlyQuote  = subtotalAfterCoverageCalc * 12;

                        insuree.QuoteMonthly                  = Convert.ToDecimal(monthlyQuote);
                        insuree.QuoteYearly                   = Convert.ToDecimal(yearlyQuote);
                        autoQuote.InsureeId                   = Convert.ToInt32(insuree.Id);
                        autoQuote.BaseRate                    = Convert.ToDecimal(baseRate);
                        autoQuote.AgeUnder18                  = Convert.ToDecimal(under18);
                        autoQuote.AgeBtw19and25               = Convert.ToDecimal(btw19and25);
                        autoQuote.Age26andUp                  = Convert.ToDecimal(over25);
                        autoQuote.AutoYearBefore2000          = Convert.ToDecimal(autoYearPrior2000);
                        autoQuote.AutoYearAfter2015           = Convert.ToDecimal(autoYearAfter2015);
                        autoQuote.IsPorsche                   = Convert.ToDecimal(yesIsPorsche);
                        autoQuote.IsCarrera                   = Convert.ToDecimal(yesIsCarrera);
                        autoQuote.SubTotalBeforeDuiCalc       = Convert.ToDecimal(subtotalBeforeDUI);
                        autoQuote.DuiRateUp25Percent          = Convert.ToDecimal(duiRate);
                        autoQuote.SubTotalAfterDuiCalc        = Convert.ToDecimal(subtotalAfterDUI);
                        autoQuote.SpeedingTickets             = Convert.ToDecimal(speedingTicketsRate);
                        autoQuote.SubTotalBeforeCoverageCalc  = Convert.ToDecimal(subtotalBeforeCoverageCalc);
                        autoQuote.FullCoverageRateUp50Percent = Convert.ToDecimal(fullCoverageRate);
                        autoQuote.SubTotalAfterCoverageCalc   = Convert.ToDecimal(subtotalAfterCoverageCalc);


                        insureeVM.QuoteMonthly                  = insuree.QuoteMonthly;
                        insureeVM.QuoteYearly                   = insuree.QuoteYearly;
                        autoQuoteVM.InsureeId                   = autoQuote.InsureeId;
                        autoQuoteVM.BaseRate                    = autoQuote.BaseRate;
                        autoQuoteVM.AgeUnder18                  = autoQuote.AgeUnder18;
                        autoQuoteVM.AgeBtw19and25               = autoQuote.AgeBtw19and25;
                        autoQuoteVM.Age26andUp                  = autoQuote.Age26andUp;
                        autoQuoteVM.AutoYearBefore2000          = autoQuote.AutoYearBefore2000;
                        autoQuoteVM.AutoYearAfter2015           = autoQuote.AutoYearAfter2015;
                        autoQuoteVM.IsPorsche                   = autoQuote.IsPorsche;
                        autoQuoteVM.IsCarrera                   = autoQuote.IsCarrera;
                        autoQuoteVM.SubTotalBeforeDuiCalc       = autoQuote.SubTotalBeforeDuiCalc;
                        autoQuoteVM.DuiRateUp25Percent          = autoQuote.DuiRateUp25Percent;
                        autoQuoteVM.SubTotalAfterDuiCalc        = autoQuote.SubTotalAfterDuiCalc;
                        autoQuoteVM.SpeedingTickets             = autoQuote.SpeedingTickets;
                        autoQuoteVM.SubTotalBeforeCoverageCalc  = autoQuote.SubTotalBeforeCoverageCalc;
                        autoQuoteVM.FullCoverageRateUp50Percent = autoQuote.FullCoverageRateUp50Percent;
                        autoQuoteVM.SubTotalAfterCoverageCalc   = autoQuote.SubTotalAfterCoverageCalc;
                        autoQuoteVM.QuoteMonthly                = autoQuote.QuoteMonthly;
                        autoQuoteVM.QuoteYearly                 = autoQuote.QuoteYearly;



                        db.AutoQuotes.Add(autoQuote);
                        db.Insurees.Add(insuree);
                        db.SaveChanges();
                    }
                    return(View(autoQuoteVMs));
                }
            }
        }