Пример #1
0
        [HttpPost]//Parameter name must be the same as the inputname in index.cshtml otherwise error
        public ActionResult SignUp(string firstName, string lastName, string emailAddress, DateTime dateOfBirth, int carYear, string carMake, string carModel, string dUI, int speedingTickets, int fullCoverageLiability)
        {
            decimal quoteTotal = 50;                                     // start with a base of $50

            using (CarInsuranceEntities db = new CarInsuranceEntities()) // instantiate the partial class, allow objects to access the database
            {
                var signup = new Quote();                                //new object from partial class === why?


                int userAge = Convert.ToDateTime(dateOfBirth).Year;
                int timeNow = Convert.ToDateTime(DateTime.Today).Year;
                int ageDiff = timeNow - userAge;

                //============== code intentions ============
                //> obtain exact age then compare it with system date using month day and year
                //e.g. DOB = 5/5/1995. Today = 5/4/2019. age = 24 but they are 23 years old not 24.

                //DateTime now = DateTime.Today
                //int age = now.Year - dateOfBirth.Year;

                //if (dateOfBirth < now.AddYears(-age)) age--;// subtract age
                //{

                //    quoteTotal += 100;
                //}
                //else if (dateOfBirth > 18 && dateOfBirth < 25)
                //{
                //    quoteTotal += 25;
                //}

                //user age
                //> will calculate only the year not month or day
                if (ageDiff < 18)
                {
                    quoteTotal += 100;
                }
                else if (ageDiff > 18 && ageDiff < 25)
                {
                    quoteTotal += 25;
                }
                else if (ageDiff > 100)
                {
                    quoteTotal += 25;
                }

                //car year
                if (carYear < 2000 || carYear > 2015)//add 25
                {
                    quoteTotal += 25;
                }

                //car make
                if (carMake.ToLower().Contains("porsche") && carModel.ToLower().Contains("911 carrera"))//multiple conditions must come first otherwise a single condition will only execute like the if else condition
                {
                    quoteTotal += 50;
                }
                else if (carMake.ToLower().Contains("porsche"))//checks and lowers user input
                {
                    quoteTotal += 25;
                }

                //Speeding Tickets
                if (speedingTickets == 0)
                {
                    speedingTickets *= 10; //for each tickets multiply by 10 and add to pending total
                }
                else
                {
                    speedingTickets *= 10;
                    quoteTotal      += speedingTickets;
                }

                //DUI add 10%
                if (dUI.ToLower().Contains("yes"))// if yes pending total is nulyiply by 0.25
                {
                    decimal DuiCharge = quoteTotal * 0.25m;
                    quoteTotal += DuiCharge;
                }
                else if (dUI.ToLower().Contains("no"))//does not return value
                {
                    quoteTotal += 0;
                }

                //Full coverage or liability
                if (fullCoverageLiability == 1)
                {
                    decimal fullCoverage = quoteTotal * 0.50m;
                    quoteTotal += fullCoverage;
                }
                else if (fullCoverageLiability == 0)//does not return value
                {
                    quoteTotal += 0;
                }


                signup.FirstName             = firstName;
                signup.LastName              = lastName;
                signup.EmailAddress          = emailAddress;
                signup.DateOfBirth           = dateOfBirth;
                signup.CarYear               = carYear;
                signup.CarMake               = carMake;
                signup.CarModel              = carModel;
                signup.DUI                   = dUI;
                signup.SpeedingTickets       = speedingTickets;
                signup.FullCoverageLiability = fullCoverageLiability;
                signup.Quotes                = Convert.ToInt32(quoteTotal);


                db.Quotes.Add(signup);//pass signup object
                db.SaveChanges();
            }

            CredentialsVm newQuote = new CredentialsVm();

            newQuote.FirstName    = firstName;
            newQuote.LastName     = lastName;
            newQuote.EmailAddress = emailAddress;
            newQuote.Quotes       = quoteTotal;
            return(View(newQuote));

            //return View("~/Views/Home/Quote.cshtml");
            //return RedirectToAction("Quote", "Home");//redirects to Quote to perform the logic after user enters information
        }
        public ActionResult Success(string firstName, string lastName, string email, DateTime dateOfBirth, string carMake, string carModel, string carYear, bool dui, string speedingTickets, bool fullCoverage)
        {
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(email) || dateOfBirth == null || string.IsNullOrEmpty(carMake) || string.IsNullOrEmpty(carModel) || string.IsNullOrEmpty(carYear) || string.IsNullOrEmpty(speedingTickets))
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }
            else
            {
                using (CarInsuranceEntities db = new CarInsuranceEntities())
                {
                    {
                        var client = new Client();
                        client.FirstName       = firstName;
                        client.LastName        = lastName;
                        client.DateOfBirth     = dateOfBirth;
                        client.Email           = email;
                        client.CarMake         = carMake.ToLower();
                        client.CarModel        = carModel.ToLower();
                        client.CarYear         = Convert.ToInt32(carYear);
                        client.DUI             = dui;
                        client.SpeedingTickets = Convert.ToInt32(speedingTickets);
                        client.FullCoverage    = fullCoverage;


                        int baseQuote = 50;
                        int age       = DateTime.Now.Year - dateOfBirth.Year;
                        if (DateTime.Now.DayOfYear < dateOfBirth.DayOfYear)
                        {
                            age -= 1;
                        }
                        if (age < 18)
                        {
                            baseQuote += 100;
                        }
                        else if (age < 25 || age > 100)
                        {
                            baseQuote += 25;
                        }

                        if (Convert.ToInt32(carYear) < 2000 || Convert.ToInt32(carYear) > 2015)
                        {
                            baseQuote += 25;
                        }

                        if (carMake == "porsche")
                        {
                            baseQuote = (carModel == "911 carrera") ? baseQuote + 50 : baseQuote + 25;
                        }

                        baseQuote += (Convert.ToInt32(speedingTickets) * 10);

                        if (dui)
                        {
                            baseQuote += (baseQuote / 4);
                        }

                        if (fullCoverage)
                        {
                            baseQuote += (baseQuote / 2);
                        }

                        client.Quote = baseQuote;

                        db.Clients.Add(client);
                        db.SaveChanges();

                        ViewBag.FirstName       = client.FirstName;
                        ViewBag.LastName        = client.LastName;
                        ViewBag.DateOfBirth     = client.DateOfBirth;
                        ViewBag.Email           = client.Email;
                        ViewBag.CarMake         = client.CarMake;
                        ViewBag.CarModel        = client.CarModel;
                        ViewBag.CarYear         = client.CarYear;
                        ViewBag.DUI             = client.DUI;
                        ViewBag.SpeedingTickets = client.SpeedingTickets;
                        ViewBag.FullCoverage    = client.FullCoverage;
                        ViewBag.Quote           = client.Quote;
                    }
                    return(View());
                }
            }
        }
Пример #3
0
        public ActionResult Driver(string firstName, string lastName, string emailAddress,
                                   string dateOfBirth, string yearOfCar, string makeOfCar, string modelOfCar,
                                   string dui, string speedingTickets, string coverage)
        {
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) ||
                string.IsNullOrEmpty(emailAddress) || string.IsNullOrEmpty(dateOfBirth) ||
                string.IsNullOrEmpty(yearOfCar) || string.IsNullOrEmpty(makeOfCar) ||
                string.IsNullOrEmpty(modelOfCar) || string.IsNullOrEmpty(dui) ||
                string.IsNullOrEmpty(speedingTickets) || string.IsNullOrEmpty(coverage))
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }
            else
            {
                int rate = 50;

                int yearItIs = DateTime.Now.Year;
                int dob      = Convert.ToDateTime(dateOfBirth).Year;
                int age      = yearItIs - dob;

                bool isUnder18 = age < 18;
                int  rate18    = (isUnder18 ? 100 : 0);
                bool isUnder25 = age < 25 && age > 18;
                int  rate25    = (isUnder25 ? 25 : 0);
                bool isOver100 = age >= 100;
                int  rate100   = (isOver100 ? 25 : 0);

                bool carIsOld     = Convert.ToInt32(yearOfCar) < 2000;
                int  rateOldCar   = (carIsOld ? 25 : 0);
                bool carIsNew     = Convert.ToInt32(yearOfCar) > 2015;
                int  rateNewCar   = (carIsNew ? 25 : 0);
                bool carIsPorsche = makeOfCar.ToLower() == "porsche";
                int  porscheRate  = (carIsPorsche ? 25 : 0);
                bool carIsCarrera = modelOfCar.ToLower().Contains("carrera");
                int  carreraRate  = (carIsPorsche && carIsCarrera ? 25 : 0);
                int  tickets      = Convert.ToInt32(speedingTickets);
                int  tickRate     = tickets * 10;

                int addedRate = rate + rate18 + rate25 + rate100
                                + rateOldCar + rateNewCar + porscheRate
                                + carreraRate + tickRate;

                int  duiCalc = addedRate / 4;
                bool hasDui  = dui.ToLower() == "yes";
                int  duiRate = (hasDui ? duiCalc : 0);

                int adjustedDui = addedRate + duiRate;

                int  coverageCalc = adjustedDui / 2;
                bool fullCov      = coverage.ToLower() == "full";
                int  fullRate     = (fullCov ? coverageCalc : 0);

                int newRate = adjustedDui + fullRate;

                ViewBag.Message = newRate;

                using (CarInsuranceEntities db = new CarInsuranceEntities())
                {
                    var quote = new Driver();
                    quote.FirstName       = firstName;
                    quote.LastName        = lastName;
                    quote.EmailAddress    = emailAddress;
                    quote.DateOfBirth     = Convert.ToDateTime(dateOfBirth);
                    quote.YearOfCar       = yearOfCar;
                    quote.MakeOfCar       = makeOfCar;
                    quote.ModelOfCar      = modelOfCar;
                    quote.Dui             = dui;
                    quote.SpeedingTickets = speedingTickets;
                    quote.Coverage        = coverage;
                    quote.Quote           = newRate;

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

                return(View());
            }
        }
Пример #4
0
        //passing in user input values
        public ActionResult Estimate(string firstName, string lastName, string email, DateTime birthdate, int carYear,
                                     string carMake, string carModel, string dui, int tickets, string coverage)
        {
            //accessing database
            using (CarInsuranceEntities db = new CarInsuranceEntities())
            {
                //instantiating a class object and assigning it properties based on user input
                var customer = new Customer
                {
                    FirstName = firstName,
                    LastName  = lastName,
                    Email     = email,
                    BirthDate = birthdate,
                    CarYear   = carYear,
                    CarMake   = carMake,
                    CarModel  = carModel,
                    DUI       = dui,
                    Tickets   = tickets,
                    Coverage  = coverage
                };

                customer.Estimate = 50m;
                //Gets customerAge
                int customerAge = DateTime.Now.Year - Convert.ToDateTime(customer.BirthDate).Year;
                //If the user is under 25, add $25 to the monthly total.
                if (customerAge < 25 && customerAge > 17)
                {
                    customer.Estimate += 25m;
                }
                //If the user is under 18, add $100 to the monthly total.
                else if (customerAge < 18)
                {
                    customer.Estimate += 100m;
                }
                //If the user is over 100, add $25 to the monthly total.
                else if (customerAge > 100)
                {
                    customer.Estimate += 25m;
                }
                //If the car's year is before 2000, add $25 to the monthly total.
                if (customer.CarYear < 2000)
                {
                    customer.Estimate += 25m;
                }
                //If the car's year is after 2015, add $25 to the monthly total.
                else if (customer.CarYear > 2015)
                {
                    customer.Estimate += 25;
                }
                //If the car's Make is a Porsche, add $25 to the price.
                if (customer.CarMake.ToLower() == "porsche")
                {
                    customer.Estimate += 25m;
                }
                //If the car's Make is a Porsche and its model is a 911 Carrera, add an additional $25 to the price.
                if (customer.CarMake.ToLower() == "porsche" && customer.CarModel.ToLower() == "911")
                {
                    customer.Estimate += 25m;
                }
                //Add $10 to the monthly total for every speeding ticket the user has.
                for (int i = 0; i < customer.Tickets; i++)
                {
                    customer.Estimate += 10m;
                }
                //If the user has ever had a DUI, add 25 % to the total.
                if (customer.DUI == "true")
                {
                    customer.Estimate *= 1.25m;
                }
                //If it's full coverage, add 50% to the total.
                if (customer.Coverage == "full")
                {
                    customer.Estimate *= 1.5m;
                }



                //adding and saving new class object to database
                db.Customers.Add(customer);
                db.SaveChanges();
                ViewBag.Message = customer;

                //had to try and catch a validation error from the database
                //had accidentally set DUI data type to varchar(3) ("yes" or "no")
                //and then later routed it to "true" and "false" lol!
                //try
                //{
                //    db.SaveChanges();
                //}
                //catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                //{
                //    Exception raise = dbEx;
                //    foreach (var validationErrors in dbEx.EntityValidationErrors)
                //    {
                //        foreach (var validationError in validationErrors.ValidationErrors)
                //        {
                //            string message = string.Format("{0}:{1}",
                //                validationErrors.Entry.Entity.ToString(),
                //                validationError.ErrorMessage);
                //            // raise a new exception nesting
                //            // the current instance as InnerException
                //            raise = new InvalidOperationException(message, raise);
                //        }
                //    }
                //    throw raise;
                //}
            }

            return(View("Success"));
        }
Пример #5
0
        public ActionResult CalculateQuote(string firstName, string lastName, int dobMonth, int dobDay, int dobYear,
                                           string emailAddress, string dui, string fullCoverage, string carMake, string carModel, int numberOfTickets = 0, int carYear = 2020)
        {
            bool     hasDUI            = !(dui is null); // if string dui is null, not checked ==> No DUI, false
            bool     wantsFullCoverage = !(fullCoverage is null);
            DateTime userAge           = new DateTime(dobYear, dobMonth, dobDay);

            decimal quote = 50;

            // If the user is under 25, add $25 to the monthly total.
            if ((DateTime.Now - userAge).TotalDays / 365 < 25)
            {
                quote += 25;
            }

            // If the user is under 18, add $100 to the monthly total.
            if ((DateTime.Now - userAge).TotalDays / 365 < 18)
            {
                quote += 100;
            }

            // If the user is over 100, add $25 to the monthly total.
            if ((DateTime.Now - userAge).TotalDays / 365 > 100)
            {
                quote += 25;
            }

            // If the car's year is before 2000, add $25 to the monthly total.
            if (carYear < 2000)
            {
                quote += 25;
            }

            // If the car's year is after 2015, add $25 to the monthly total.
            if (carYear > 2015)
            {
                quote += 25;
            }

            // If the car's Make is a Porsche, add $25 to the price.
            if (carMake == "Porsche")
            {
                quote += 25;
            }

            // If the car's Make is a Porsche and its model is a 911 Carrera, add an additional $25 to the price.
            if (carMake == "Porsche" && carModel == "911 Carrera")
            {
                quote += 25;
            }

            // Add $10 to the monthly total for every speeding ticket the user has.
            if (numberOfTickets > 0)
            {
                quote += numberOfTickets * 10;
            }

            // If the user has ever had a DUI, add 25% to the total.
            if (hasDUI)
            {
                quote *= 1.25M;
            }

            // If it's full coverage, add 50% to the total.
            if (wantsFullCoverage)
            {
                quote *= 1.50M;
            }

            using (CarInsuranceEntities db = new CarInsuranceEntities())
            {
                var user = new User();
                user.FirstName       = firstName;
                user.LastName        = lastName;
                user.EmailAddress    = emailAddress;
                user.DateOfBirth     = userAge;
                user.CarYear         = carYear;
                user.CarModel        = carModel;
                user.CarMake         = carMake;
                user.DUI             = hasDUI;
                user.SpeedingTickets = numberOfTickets;
                user.FullCoverage    = wantsFullCoverage;
                user.Quote           = quote;

                db.Users.Add(user);
                db.SaveChanges();
            }

            ViewBag.CarYear  = carYear;
            ViewBag.CarModel = carModel;
            ViewBag.CarMake  = carMake;
            ViewBag.Quote    = quote;
            return(View());
        }
        public ActionResult GetQuote(string firstName, string lastName, string emailAddress, DateTime dob, string carYear, string carMake, string carModel, bool dui, int speedingTickets, bool fullCoverage)
        {
            //Testing to ensure the user has input name and email address, routing to error page otherwise
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress))
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }
            else
            {
                //The business logic for the user's quote. I create the variable integer at a baseline of 50 dollars.
                int quote = 50;
                //Here I am figuring out their age by subtracting their DOB input from todays date.
                TimeSpan howOld  = DateTime.Now.Date - dob.Date;
                int      userAge = Convert.ToInt32(howOld.TotalDays) / 365;
                //If the user is older than 100 or less than 25, we tack on 25 dollars.Under 18, we add 100.
                if (userAge > 100 || userAge < 25)
                {
                    quote += 25;
                }
                else if (userAge < 18)
                {
                    quote += 100;
                }
                //if the car is newer or much older, again we tack on 25 dollars.
                if (Convert.ToInt32(carYear) > 2015 || Convert.ToInt32(carYear) < 2000)
                {
                    quote += 25;
                }
                //For clients with the very expensive Porsche, we also collect more monthly.
                if (carMake == "Porsche")
                {
                    quote += 25;
                }

                if (carMake == "Porsche" && carModel == "911 Carrera")
                {
                    quote += 50;
                }
                //If the user has any speeding tickets, we add 10 dollars for each one
                for (int i = 0; i < speedingTickets; i++)
                {
                    quote += 10;
                }
                //If the user has had a DUI, we add 25% to their total
                if (dui)
                {
                    int percent = quote / 4;
                    quote += quote + percent;
                }
                //We add 50% to the total if they would like full coverage.
                if (fullCoverage)
                {
                    int percentage = quote / 2;
                    quote += quote + percentage;
                }
                //Here we instantiate the database
                using (CarInsuranceEntities db = new CarInsuranceEntities())
                {
                    //Now we instatiate the model class "ClientRecord" and fill in the record using the data provided by the user.
                    ClientRecord client = new ClientRecord();
                    client.FirstName       = firstName;
                    client.LastName        = lastName;
                    client.EmailAddress    = emailAddress;
                    client.DOB             = dob;
                    client.CarYear         = carYear;
                    client.CarMake         = carMake;
                    client.CarModel        = carModel;
                    client.DUI             = dui;
                    client.SpeedingTickets = speedingTickets;
                    client.FullCoverage    = fullCoverage;
                    client.Quote           = quote;
                    //We then add it to the database and save the database.
                    db.ClientRecords.Add(client);
                    db.SaveChanges();
                }



                return(View("Quote"));
            }
        }
Пример #7
0
        public ActionResult SignUp(string firstName, string lastName, string emailAddress,
                                   DateTime dob, int?carYear, string carMake, string carModel,
                                   int?tickets, bool?dui, bool?fullCoverage)
        {
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress) ||
                string.IsNullOrEmpty(carMake) || string.IsNullOrEmpty(carModel) || tickets.HasValue == false || carYear.HasValue == false ||
                dui.HasValue == false || fullCoverage.HasValue == false)
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }

            else
            {
                //code for calculating a quote
                decimal quote = 50;
                int     age   = CalculateAge(dob);

                if (age <= 25 || age >= 100)
                {
                    quote += 25;
                }
                if (age <= 18)
                {
                    quote += 100;
                }

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

                if (carMake == "Porsche")
                {
                    quote += 25;
                }
                if (carMake == "Porsche" && carModel == "911 Carrera")
                {
                    quote += 25;
                }

                if (tickets >= 1)
                {
                    quote += (decimal)tickets * 10;
                }

                if (dui == true)
                {
                    Decimal duiMarkup = 1.25m;
                    quote *= duiMarkup;
                }

                if (fullCoverage == true)
                {
                    Decimal fullCovMarkup = 1.5m;
                    quote *= fullCovMarkup;
                }



                using (CarInsuranceEntities db = new CarInsuranceEntities())
                {
                    var signup = new SignUp();
                    signup.FirstName    = firstName;
                    signup.LastName     = lastName;
                    signup.EmailAddress = emailAddress;
                    signup.DOB          = dob;
                    signup.CarYear      = carYear;
                    signup.CarMake      = carMake;
                    signup.CarModel     = carModel;
                    signup.DUI          = dui;
                    signup.Tickets      = tickets;
                    signup.FullCoverage = fullCoverage;
                    signup.Quote        = quote;


                    db.SignUps.Add(signup);
                    db.SaveChanges();
                }


                quote         = Math.Round(quote, 2);
                ViewBag.Quote = quote;
                return(View("DisplayQuote"));
            }
        }
Пример #8
0
        public ActionResult TotalQuote(string firstName, string lastName, string emailAddress, DateTime dateOfBirth, int carYear, string carMake, string carModel, bool hadDUI, int speedingTickets, bool fullCoverage)
        {
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress))
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }
            else
            {
                using (CarInsuranceEntities db = new CarInsuranceEntities())
                {
                    var driver = new CarDriver();
                    driver.FirstName       = firstName;
                    driver.LastName        = lastName;
                    driver.EmailAddress    = emailAddress;
                    driver.DateOfBirth     = dateOfBirth;
                    driver.CarYear         = carYear;
                    driver.CarMake         = carMake;
                    driver.CarModel        = carModel;
                    driver.HadDUI          = hadDUI;
                    driver.SpeedingTickets = speedingTickets;
                    driver.FullCoverage    = fullCoverage;

                    double totalQuote = 50;
                    if ((DateTime.Now).Year - (Convert.ToDateTime(driver.DateOfBirth)).Year < 18)
                    {
                        totalQuote += 100;
                    }
                    else if ((DateTime.Now).Year - (Convert.ToDateTime(driver.DateOfBirth)).Year < 25)
                    {
                        totalQuote += 25;
                    }

                    if ((DateTime.Now).Year - (Convert.ToDateTime(driver.DateOfBirth)).Year > 100)
                    {
                        totalQuote += 25;
                    }
                    if (driver.CarYear < 2000)
                    {
                        totalQuote += 25;
                    }
                    if (driver.CarYear > 2015)
                    {
                        totalQuote += 25;
                    }
                    if (driver.CarMake.ToLower() == "porsche")
                    {
                        totalQuote += 25;
                    }
                    if (driver.CarMake.ToLower() == "porsche" && driver.CarModel.ToLower() == "911 carrera")
                    {
                        totalQuote += 25;
                    }
                    if (driver.SpeedingTickets != 0)
                    {
                        totalQuote += Convert.ToDouble(driver.SpeedingTickets) * 10;
                    }
                    if (Convert.ToBoolean(driver.HadDUI))
                    {
                        totalQuote *= 1.25;
                    }
                    if (Convert.ToBoolean(driver.FullCoverage))
                    {
                        totalQuote *= 1.5;
                    }

                    driver.FinalQuote = totalQuote;
                    db.CarDrivers.Add(driver);
                    db.SaveChanges();

                    ViewBag.totalQuote = totalQuote;
                }

                return(View("Success"));
            }
        }
 public ActionResult CustomerInfo(string FirstName, string LastName, string EmailAddress, DateTime DateOfBirth,
                                  int?CarYear, string CarMake, string CarModel, bool HaveDui, int?SpeedingTickets,
                                  bool FullCoverage)
 {
     if (string.IsNullOrEmpty(FirstName) || string.IsNullOrEmpty(LastName) || string.IsNullOrEmpty(EmailAddress) ||
         CarYear == null || string.IsNullOrEmpty(CarMake) || string.IsNullOrEmpty(CarModel) || SpeedingTickets == null)
     {
         return(View("~/Views/Shared/Error.cshtml"));
     }
     else
     {
         using (CarInsuranceEntities db = new CarInsuranceEntities())
         {
             int     age    = DateTime.Now.Year - DateOfBirth.Year;
             string  strDOB = DateOfBirth.ToString("MM-dd-yyyy");
             decimal Quote  = 50.0m;
             //age
             if (age >= 18 && age < 25)
             {
                 Quote += 25m;
             }
             else if (age < 18)
             {
                 Quote += 100m;
             }
             else if (age > 100)
             {
                 Quote += 25;
             }
             //car
             if (CarYear < 2000 || CarYear > 2015)
             {
                 Quote += 25;
             }
             if (CarMake == "Porsche")
             {
                 if (CarModel == "911 Carrera")
                 {
                     Quote += 25;
                 }
                 Quote += 25;
             }
             if (SpeedingTickets > 0)
             {
                 Quote += (Convert.ToDecimal(SpeedingTickets) * 10);
             }
             if (HaveDui)
             {
                 Quote += (Quote * .25m);
             }
             if (FullCoverage)
             {
                 Quote += (Quote * .5m);
             }
             Quote = System.Math.Round(Quote, 2);
             var customerInfo = new CustomerInfo();
             customerInfo.FirstName       = FirstName;
             customerInfo.LastName        = LastName;
             customerInfo.EmailAddress    = EmailAddress;
             customerInfo.DateOfBirth     = strDOB;
             customerInfo.CarYear         = CarYear;
             customerInfo.CarMake         = CarMake;
             customerInfo.CarModel        = CarModel;
             customerInfo.HaveDui         = HaveDui;
             customerInfo.SpeedingTickets = SpeedingTickets;
             customerInfo.FullCoverage    = FullCoverage;
             customerInfo.Quote           = Quote;
             db.CustomerInfoes.Add(customerInfo);
             db.SaveChanges();
             ViewBag.Message = customerInfo;
         }
         return(View("Success"));
     }
 }
Пример #10
0
        public ActionResult GenerateQuote(string firstName, string lastName, string emailAddress, DateTime dateOfBirth, int carYear, string carMake, string carModel, bool dui, int speedingTickets, string coverageType)
        {
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress) || string.IsNullOrEmpty(carMake) || string.IsNullOrEmpty(carModel))
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }
            var client = new Client()
            {
                FirstName       = firstName,
                LastName        = lastName,
                EmailAddress    = emailAddress,
                DateOfBirth     = dateOfBirth,
                CarYear         = carYear,
                CarMake         = carMake,
                CarModel        = carModel,
                Dui             = dui,
                SpeedingTickets = speedingTickets,
                Coverage        = coverageType
            };

            var     today         = DateTime.Today;
            int     age           = today.Year - dateOfBirth.Year;
            decimal quoteEstimate = 50;

            if (age <= 25)
            {
                quoteEstimate += 25;
            }
            if (age < 18)
            {
                quoteEstimate += 100;
            }
            if (age > 100)
            {
                quoteEstimate += 25;
            }
            if (carYear < 2000)
            {
                quoteEstimate += 25;
            }
            if (carYear > 2015)
            {
                quoteEstimate += 25;
            }
            if (carMake.ToLower().Equals("porsche"))
            {
                quoteEstimate += 25;
            }
            if (carMake.ToLower().Equals("porsche") && carModel.ToLower().Equals("carrera"))
            {
                quoteEstimate += 25;
            }
            if (speedingTickets > 0)
            {
                quoteEstimate += (speedingTickets * 10);
            }
            if (dui == true)
            {
                quoteEstimate *= 1.25m;
            }
            if (coverageType.ToLower() == "full coverage")
            {
                quoteEstimate *= 1.50m;
            }

            using (CarInsuranceEntities db = new CarInsuranceEntities())
            {
                var newClient = new Client();
                newClient       = client;
                newClient.Quote = quoteEstimate;

                db.Clients.Add(newClient);
                db.SaveChanges();
            }
            return(View("Success"));
        }
Пример #11
0
        public ActionResult QuoteInfo(string firstName, string lastName, string emailAddress, DateTime dateOfBirth, int carYear, string carMake, string carModel, bool coverageLiability, int speedingTickets = 0, bool dui = false)
        {
            // Calculating car inurance cost
            // Calc age
            int quote = 50;
            var today = DateTime.Today;
            var age   = today.Year - dateOfBirth.Year;

            // Age cost
            if (age < 25 && age >= 18)
            {
                quote = quote + 25;
            }
            else if (age < 18)
            {
                quote = quote + 100;
            }
            else if (age > 100)
            {
                quote = quote + 25;
            }
            // Cars Year cost
            if (carYear < 2000)
            {
                quote = quote + 25;
            }
            else if (carYear > 2015)
            {
                quote = quote + 25;
            }
            // Cars Make cost
            if (carMake == "Porsche")
            {
                quote = quote + 25;
            }
            else if (carMake == "Porsche" && carModel == "911 Carrera")
            {
                quote = quote + 25;
            }
            // Speeding tickets cost
            for (int i = 0; i < speedingTickets; i++)
            {
                quote = quote + 10;
            }
            // DUI cost
            if (dui == true)
            {
                double duiCost    = quote * .25;
                int    intDuiCost = Convert.ToInt32(duiCost);
                quote = quote + intDuiCost;
            }
            // Full coverage cost
            if (coverageLiability == true)
            {
                double coverageCost    = quote * .50;
                int    intCoverageCost = Convert.ToInt32(coverageCost);
                quote = quote + intCoverageCost;
            }

            using (CarInsuranceEntities db = new CarInsuranceEntities())
            {
                var quoteinfo = new QuoteInfo();
                quoteinfo.FirstName         = firstName;
                quoteinfo.LastName          = lastName;
                quoteinfo.EmailAddress      = emailAddress;
                quoteinfo.DateOfBirth       = dateOfBirth;
                quoteinfo.CarYear           = carYear;
                quoteinfo.CarMake           = carMake;
                quoteinfo.CarModel          = carModel;
                quoteinfo.DUI               = dui;
                quoteinfo.SpeedingTickets   = speedingTickets;
                quoteinfo.CoverageLiability = coverageLiability;
                quoteinfo.Quote             = quote;

                db.QuoteInfoes.Add(quoteinfo);
                db.SaveChanges();

                return(View("Quote", quoteinfo));
            }
        }
        public ActionResult GetQuote(Quote quote)
        {
            //Set the quote total at $50
            quote.QuoteTotal = 50.00m;

            //If the user is under 25, add $25 to the monthly total.
            //If the user is under 18, add $100 to the monthly total.
            //If the user is over 100, add $25 to the monthly total.

            int age = DateTime.Now.Year - quote.DateOfBirth.Year;

            if (age < 18)
            {
                quote.QuoteTotal += 100.00m;
            }
            else if (age < 25 || age > 100)
            {
                quote.QuoteTotal += 25.00m;
            }

            //If the car's year is before 2000, add $25 to the monthly total.
            //If the car's year is after 2015, add $25 to the monthly total.

            if (quote.CarYear < 2000 || quote.CarYear > 2015)
            {
                quote.QuoteTotal += 25m;
            }

            //If the car's Make is a Porsche, add $25 to the price.
            //If the car's Make is a Porsche and its model is a 911 Carrera, add an additional $25 to the price.
            if (quote.CarMake == "Porsche")
            {
                quote.QuoteTotal += 25.00m;
                if (quote.CarModel == "911 Carrera")
                {
                    quote.QuoteTotal += 25.00m;
                }
            }

            //Add $10 to the monthly total for every speeding ticket the user has.
            quote.QuoteTotal += quote.Tickets * 10.00m;


            //If the user has ever had a DUI, add 25 % to the total.
            if (quote.DUI)
            {
                quote.QuoteTotal += 25.00m;
            }

            //If it's full coverage, add 50% to the total.
            if (quote.FullCoverage)
            {
                quote.QuoteTotal *= 1.5m;
            }



            using (CarInsuranceEntities db = new CarInsuranceEntities())
            {
                db.Quotes.Add(quote);
                db.SaveChanges();
            }
            ViewBag.homeActive = "active";
            return(View(quote));
        }
Пример #13
0
        public ActionResult Quote(string firstName, string lastName, string emailAddress, DateTime dateOfBirth,
                                  short carYear, string carMake, string carModel, bool dui, short speedingTickets, string insuranceType)
        {
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress) ||
                string.IsNullOrEmpty(carMake) || string.IsNullOrEmpty(carModel) || string.IsNullOrEmpty(insuranceType))
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }
            else
            {
                decimal monthly = 50;

                // calculating the monthly quote
                var today = DateTime.Today;
                int age   = today.Year - dateOfBirth.Year;
                if (today.Month < dateOfBirth.Month || (today.Month == dateOfBirth.Month && today.Day < dateOfBirth.Day))
                {
                    age--;
                }
                if (age < 18)
                {
                    monthly += 100;
                }
                else if (age < 25 || age >= 100)
                {
                    monthly += 25;
                }

                if (carYear < 2000 || carYear > 2015)
                {
                    monthly += 25;
                }
                if (carMake.ToLower() == "porsche")
                {
                    monthly += 25;
                }
                if (carMake.ToLower() == "porsche" && carModel.ToLower() == "911 carrera")
                {
                    monthly += 25;
                }

                monthly += (speedingTickets * 10);
                if (dui == true)
                {
                    monthly *= (decimal)1.25;
                }
                if (insuranceType == "full")
                {
                    monthly *= (decimal)1.5;
                }

                decimal monthlyFinal = Math.Round(monthly, 2);

                // entering information into database
                using (CarInsuranceEntities db = new CarInsuranceEntities())
                {
                    var quote = new Quote();
                    quote.FirstName       = firstName;
                    quote.LastName        = lastName;
                    quote.EmailAddress    = emailAddress;
                    quote.DateOfBirth     = dateOfBirth;
                    quote.CarYear         = carYear;
                    quote.CarMake         = carMake;
                    quote.CarModel        = carModel;
                    quote.Dui             = dui;
                    quote.SpeedingTickets = speedingTickets;
                    quote.InsuranceType   = insuranceType;
                    quote.InsuranceQuote  = monthlyFinal;

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

                // displaying the quote
                ViewBag.MonthlyQuote = "Your monthly car insurance quote is: " + monthlyFinal.ToString();

                return(View());
            }
        }
Пример #14
0
        public ActionResult GetQuote(string firstName, string lastName, string emailAddress, DateTime dateOfBirth, int carYear, string carMake, string carModel, bool hasDUI, int speedingTickets, bool wantsCoverage)
        {
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress))
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }
            else
            {
                using (CarInsuranceEntities db = new CarInsuranceEntities())
                {
                    var quote = new Quote();
                    quote.FirstName       = firstName;
                    quote.LastName        = lastName;
                    quote.EmailAddress    = emailAddress;
                    quote.DateOfBirth     = dateOfBirth;
                    quote.CarYear         = carYear;
                    quote.CarMake         = carMake;
                    quote.CarModel        = carModel;
                    quote.HasDUI          = hasDUI;
                    quote.SpeedingTickets = speedingTickets;
                    quote.WantsCoverage   = wantsCoverage;


                    int insuranceQuote = 50;
                    if (Convert.ToInt32(DateTime.Now.Year - (dateOfBirth.Year)) < 18)
                    {
                        insuranceQuote += 100;
                    }
                    else if (Convert.ToInt32(DateTime.Now.Year - (dateOfBirth.Year)) < 25)
                    {
                        insuranceQuote += 25;
                    }
                    else if (Convert.ToInt32(DateTime.Now.Year - (dateOfBirth.Year)) > 100)
                    {
                        insuranceQuote += 25;
                    }

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

                    if (carMake.ToLower() == "porsche")
                    {
                        insuranceQuote += 25;
                    }

                    if (carMake.ToLower() == "porsche" && carModel.ToLower() == "911 carrera")
                    {
                        insuranceQuote += 25;
                    }

                    if (speedingTickets > 0)
                    {
                        insuranceQuote += speedingTickets * 10;
                    }

                    if (hasDUI)
                    {
                        insuranceQuote += Convert.ToInt32(insuranceQuote * .25);
                    }

                    if (wantsCoverage)
                    {
                        insuranceQuote += Convert.ToInt32(insuranceQuote * .50);
                    }

                    quote.InsuranceQuote = insuranceQuote;
                    db.Quotes.Add(quote);
                    db.SaveChanges();
                }

                return(View("Success"));
            }
        }