Пример #1
0
        public ActionResult CustomerInfo(string firstName, string lastName, string emailAddress, DateTime dateOfBirth, DateTime carYear,
                                         string carMake, string carModel, string speedingTickets, string fullCoverage, string dui, double quote = 0)
        {
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress) ||
                string.IsNullOrEmpty(carMake) || string.IsNullOrEmpty(carModel) ||
                string.IsNullOrEmpty(speedingTickets))
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }
            else
            {
                using (QuoteDbEntities db = new QuoteDbEntities())
                {
                    var customer = new CustomerInfo();
                    customer.FirstName       = firstName;
                    customer.LastName        = lastName;
                    customer.EmailAddress    = emailAddress;
                    customer.DateOfBirth     = dateOfBirth;
                    customer.CarYear         = carYear;
                    customer.CarMake         = carMake;
                    customer.CarModel        = carModel;
                    customer.Dui             = CheckBool(dui);
                    customer.SpeedingTickets = Convert.ToInt32(speedingTickets);
                    customer.FullCoverage    = CheckBool(fullCoverage);
                    quote          = CalculateQuote(firstName, lastName, emailAddress, dateOfBirth, carYear, carMake, carModel, CheckBool(dui), speedingTickets, CheckBool(fullCoverage), quote);
                    customer.Quote = quote;

                    db.CustomerInfoes.Add(customer);
                    db.SaveChanges();
                    ViewBag.Message = quote;
                }
                return(View("QuotePage"));
            }
        }
        public ActionResult Quote(string firstName, string lastName, string emailAddress, DateTime dateOfBirth, int carYear, string carMake, string carModel, string hadDUI, int numberOfTickets, string coverage)
        {
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress) || string.IsNullOrEmpty(carMake) || string.IsNullOrEmpty(carModel) || string.IsNullOrEmpty(hadDUI) || string.IsNullOrEmpty(coverage))
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }
            else
            {
                var     today = DateTime.Today;
                var     age   = today.Year - dateOfBirth.Year;
                decimal total = 50;
                if (age < 25 && age >= 18)
                {
                    total += 25;
                }
                if (age < 18)
                {
                    total += 25;
                }
                if (age > 100)
                {
                    total += 25;
                }
                if (carYear < 2000)
                {
                    total += 25;
                }
                if (carYear > 2015)
                {
                    total += 25;
                }
                if (carMake == "Porsche")
                {
                    total += 25;
                }
                if (carMake == "Porsche" && carModel == "911 Carrera")
                {
                    total += 25;
                }
                total = total + (10 * numberOfTickets);
                if (hadDUI == "Yes")
                {
                    total = (total * 1.25m);
                }
                if (coverage == "Full Coverage")
                {
                    total = (total * 1.5m);
                }
                using (QuoteDbEntities db = new QuoteDbEntities())
                {
                    var quote = new QuoteTable();
                    quote.FirstName       = firstName;
                    quote.LastName        = lastName;
                    quote.EmailAddress    = emailAddress;
                    quote.DateOfBirth     = dateOfBirth;
                    quote.CarYear         = carYear;
                    quote.CarMake         = carMake;
                    quote.CarModel        = carModel;
                    quote.HadDUI          = hadDUI;
                    quote.NumberOfTickets = numberOfTickets;
                    quote.Coverage        = coverage;
                    quote.Quote1          = total;

                    db.QuoteTables.Add(quote);
                    db.SaveChanges();
                }
                return(View("Success"));
            }
        }