Exemplo n.º 1
0
        public ActionResult FreeQuote(string firstName, string lastName, string emailAddress, DateTime dateOfBirth,
                                      DateTime carYear, string carMake, string carModel, bool dUI,
                                      Nullable <int> speedingTickets, string coverageType, Nullable <decimal> quotePrice)
        {
            quotePrice = 50.00m;
            int age    = DateTime.Today.Year - dateOfBirth.Year;
            int carAge = carYear.Year;

            if (age < 25 || age > 100)
            {
                quotePrice += 25;
            }
            if (age < 18)
            {
                quotePrice += 100;
            }
            if (carAge < 2000 || carAge > 2015)
            {
                quotePrice += 25;
            }
            if (carMake == "Porsche" || carMake == "porsche")
            {
                quotePrice += 25;
            }
            if (carMake == "Porsche" || carMake == "porsche" && carModel == "911 Carrera" || carModel == "911 carrera")
            {
                quotePrice += 25;
            }
            if (speedingTickets > 0)
            {
                quotePrice += (speedingTickets * 10);
            }
            if (dUI == true)
            {
                quotePrice += (quotePrice * 25 / 100);
            }
            if (coverageType == "Full")
            {
                quotePrice += (quotePrice * 50 / 100);
            }

            Quote quoteCopy = new Quote();

            using (CustomerQuotesEntities db = new CustomerQuotesEntities())
            {
                Quote newQuote = new Quote();
                newQuote.FirstName       = firstName;
                newQuote.LastName        = lastName;
                newQuote.EmailAddress    = emailAddress;
                newQuote.DateOfBirth     = dateOfBirth;
                newQuote.CarYear         = carYear;
                newQuote.CarMake         = carMake;
                newQuote.CarModel        = carModel;
                newQuote.DUI             = dUI;
                newQuote.SpeedingTickets = speedingTickets;
                newQuote.CoverageType    = coverageType;
                newQuote.QuotePrice      = quotePrice;

                db.Quotes.Add(newQuote);
                db.SaveChanges();
                quoteCopy = newQuote;
            }
            return(View(quoteCopy));
        }