public ActionResult SendForm(string firstName, string lastName, string emailAddress, DateTime dateOfBirth, int carYear, string carMake, string carModel, bool dui, int speedTickets, string coverage)
        {
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress) || dateOfBirth == null || carYear == 0 || string.IsNullOrEmpty(carMake) || string.IsNullOrEmpty(carModel) || string.IsNullOrEmpty(coverage))
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }

            decimal quoteAmount = 50;

            using (var db = new CarInsuranceEntities1())
            {
                var quote = new InsuranceQuote();


                if (DateTime.Now - dateOfBirth < TimeSpan.FromDays(365 * 25))// if user is under 25
                {
                    quoteAmount += 25;
                }
                if (DateTime.Now - dateOfBirth < TimeSpan.FromDays(365 * 18))// if user is under 18
                {
                    quoteAmount += 100;
                }
                else if (DateTime.Now - dateOfBirth > TimeSpan.FromDays(365 * 100))// if user is over 100
                {
                    quoteAmount += 25;
                }

                if (carYear < 2000)
                {
                    quoteAmount += 25;
                }
                else if (carYear > 2015)
                {
                    quoteAmount += 25;
                }

                if (carMake.ToLower().Contains("porsche"))
                {
                    quoteAmount += 25;

                    if (carModel.ToLower().Contains("911 carrera"))
                    {
                        quoteAmount += 25;
                    }
                }

                quoteAmount += speedTickets * 10;

                if (dui)
                {
                    quoteAmount *= (decimal)1.25;
                }

                bool fullCoverage = (coverage == "Full");

                if (fullCoverage)
                {
                    quoteAmount *= (decimal)1.5;
                }

                quote.FirstName    = firstName;
                quote.LastName     = lastName;
                quote.EmailAddress = emailAddress;
                quote.DateOfBirth  = dateOfBirth;
                string CarDate = string.Format("01-01-" + carYear);
                quote.CarYear      = DateTime.Parse(CarDate);
                quote.CarMake      = carMake;
                quote.CarModel     = carModel;
                quote.Dui          = dui;
                quote.SpeedTickets = speedTickets;
                quote.FullCoverage = fullCoverage;
                quote.Quote        = quoteAmount;

                db.InsuranceQuotes.Add(quote);
                db.SaveChanges();
            }

            return(View("Quote", quoteAmount));
        }
Ejemplo n.º 2
0
        public ActionResult GetQuote(string firstName, string lastName, string emailAddress, int age, string dui, int carYear, string carMake, string carModel, int tickets, string coverage)
        {
            int runningQuote = 50;


            if (age < 18)
            {
                runningQuote = (runningQuote + 100);
            }

            else if (age < 25 || age > 100)
            {
                runningQuote = (runningQuote + 25);
            }


            if (carYear < 2000 || carYear > 2015)
            {
                runningQuote = runningQuote + 25;
            }


            if (carMake == "Porche" || carMake == "porche")
            {
                runningQuote = runningQuote + 25;
            }

            if (carMake == "Porche" || carMake == "porche" && carModel == "911 Carrera" || carModel == "911 carrera")
            {
                runningQuote = runningQuote + 25;
            }
            if (tickets > 0)
            {
                runningQuote = runningQuote + (tickets * 10);
            }


            if (dui == "yes" || dui == "ya" || dui == "yeah")

            {
                runningQuote = runningQuote + (runningQuote * (1 / 4));
            }

            if (coverage == "full")
            {
                runningQuote = runningQuote + (runningQuote * (1 / 2));
            }
            ViewBag.text = coverage;

            using (CarInsuranceEntities1 db = new CarInsuranceEntities1())
            {
                var customer = new CustomerQuote();
                customer.FirstName     = firstName;
                customer.LastName      = lastName;
                customer.EmailAddress  = emailAddress;
                customer.QuoteEstimate = runningQuote;

                db.CustomerQuotes.Add(customer);
                db.SaveChanges();
            }

            return(View("Quoted", runningQuote));
        }
Ejemplo n.º 3
0
        public ActionResult Index(string firstName, string lastName, string emailAddress, DateTime DOB, int CarYear, string CarMake, string CarModel, string DUI, string Tickets, string coverage)
        {
            flag = true;
            ViewBag.flagvalue = flag;
            double quote    = 50;
            int    year     = DateTime.Now.Year;
            int    useryear = DOB.Year;
            int    age      = year - useryear;

            if (age < 25 && age >= 18 || age > 100)
            {
                quote += 25;
            }
            else if (age < 18)
            {
                quote += 100;
            }
            if (CarYear < 2000)
            {
                quote += 25;
            }
            else if (CarYear > 2015)
            {
                quote += 25;
            }

            string carmodel = CarModel.ToLower();
            string carmake  = CarMake.ToLower();

            if (carmake == "porsche")
            {
                quote += 25;
                if (carmodel == "911 carrera")
                {
                    quote += 25;
                }
            }
            quote += Convert.ToInt32(Tickets) * 10;

            string dui = DUI.ToLower();

            if (dui == "yes")
            {
                quote = quote * 1.25;
            }

            double fullquote      = quote * 1.5;
            double liabilityquote = quote;
            string Coverage       = Request.Form["coverage"];

            if (Coverage == "full")
            {
                quote = fullquote;
            }
            else
            {
                quote = liabilityquote;
            }

            ViewBag.quote = quote;

            using (CarInsuranceEntities1 db = new CarInsuranceEntities1())
            {
                var carinsurance = new CarInsurance();

                carinsurance.FirstName      = firstName;
                carinsurance.LastName       = lastName;
                carinsurance.EmailAddress   = emailAddress;
                carinsurance.DOB            = DOB.ToString();
                carinsurance.CarYear        = CarYear.ToString();
                carinsurance.CarMake        = CarMake;
                carinsurance.CarModel       = CarModel;
                carinsurance.DUI            = DUI;
                carinsurance.Ticket         = Tickets;
                carinsurance.Coverage       = Coverage;
                carinsurance.FullQuote      = fullquote.ToString();
                carinsurance.LiabilityQuote = liabilityquote.ToString();

                db.CarInsurances.Add(carinsurance);
                db.SaveChanges();
            }

            return(View());
        }