public ActionResult Client(string firstName, string lastName, string emailAddress, int birthYear, int birthMonth, int birthDay, int carYear, string make, string model, int speedingTickets)//, bool dui, 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 client = new Client(); client.FirstName = firstName; client.LastName = lastName; client.EmailAddress = emailAddress; string birthday = birthYear + "-" + birthMonth + "-" + birthDay; client.Birthday = Convert.ToDateTime(birthday); //client.Dui = dui; //client.FullCoverage = fullCoverage; db.Clients.Add(client); db.SaveChanges(); } return(View("Success")); } }
// GET: Admin public ActionResult Index() { using (CarInsuranceEntities db = new CarInsuranceEntities()) { var clients = db.Clients; var clientsVm = new List <ClientVM>(); foreach (var client in clients) { var clientVm = new ClientVM(); clientVm.Id = client.Id; clientVm.FirstName = client.FirstName; clientVm.LastName = client.LastName; //clientVm.DateOfBirth = client.DateOfBirth; clientVm.Email = client.Email; //clientVm.CarMake = client.CarMake; //clientVm.CarModel = client.CarModel; //clientVm.CarYear = client.CarYear; //clientVm.DUI = client.DUI; //clientVm.SpeedingTickets = client.SpeedingTickets; //clientVm.FullCoverage = client.FullCoverage; clientVm.Quote = client.Quote; clientsVm.Add(clientVm); } return(View(clientsVm)); } }
public ActionResult Quote(string firstName, string lastName, string emailAddress, DateTime DOB, string hadDUI, int?tickets, string coverage, int carYear, string carMake, string carModel) { using (CarInsuranceEntities db = new CarInsuranceEntities()) { var customer = new Customer() { FirstName = firstName, LastName = lastName, EmailAddress = emailAddress, DOB = DOB, HadDUI = hadDUI, Tickets = tickets, Coverage = coverage }; var car = new Car() { CarYear = carYear, CarMake = carMake.ToLower(), CarModel = carModel.ToLower() }; customer.Quote = getQuote(customer, car); db.Customers.Add(customer); db.Cars.Add(car); db.SaveChanges(); var customerVm = new CustomerVM() { FirstName = customer.FirstName, LastName = customer.LastName, Quote = customer.Quote, Coverage = customer.Coverage }; return(View(customerVm)); } }
// GET: Admin public ActionResult Index() { using (CarInsuranceEntities db = new CarInsuranceEntities()) { List <Quote> quotes = db.Quotes.ToList(); ViewBag.adminActive = "active"; return(View(quotes)); } }
public ActionResult Admin() { using (CarInsuranceEntities db = new CarInsuranceEntities()) { var quoteList = new List <Customer>(); foreach (var customer in db.Customers) { quoteList.Add(customer); } return(View(quoteList)); } }
// GET: Admin public ActionResult Index() { using (CarInsuranceEntities db = new CarInsuranceEntities()) { List <CustomerVM> Customers = new List <CustomerVM>(); var persons = (from c in db.Customers //create Table object joined with CustomerCars and CustomerRecords join d in db.CustomerCars on c.Id equals d.CustomerId join e in db.CustomerRecords on c.Id equals e.CustomerId select new { c.FirstName, c.LastName, c.EmailAddress, c.DateofBirth, d.CarYear, d.CarMake, d.CarModel, e.DUI, e.FullCoverage, e.NumofTicket, person = c.Id }).ToList(); foreach (var person in persons) //Iterate through the table mapping it to View Model Object { CustomerVM Customer = new CustomerVM { Birthday = (DateTime)person.DateofBirth, FirstName = person.FirstName, LastName = person.LastName, EmailAddress = person.EmailAddress, CarMake = person.CarMake, CarModel = person.CarModel, CarYear = person.CarYear, DUI = person.DUI, FullCoverage = person.FullCoverage, NumofTicket = person.NumofTicket }; Customers.Add(Customer); } return(View(Customers)); } }
public ActionResult Admin() { using (CarInsuranceEntities db = new CarInsuranceEntities()) { var quotes = db.Quotes; var quoteVms = new List <QuoteVm>(); foreach (var quote in quotes) { var quoteVm = new QuoteVm(); quoteVm.FirstName = quote.FirstName; quoteVm.LastName = quote.LastName; quoteVm.EmailAddress = quote.EmailAddress; quoteVm.InsuranceQuote = quote.InsuranceQuote; quoteVms.Add(quoteVm); } return(View(quoteVms)); } }
// GET: Admin public ActionResult Index() { using (CarInsuranceEntities db = new CarInsuranceEntities()) { var drivers = db.Drivers.ToList(); var driverVms = new List <DriverVm>(); foreach (var driver in drivers) { var driverVm = new DriverVm(); driverVm.Id = driver.Id; driverVm.FirstName = driver.FirstName; driverVm.LastName = driver.LastName; driverVm.EmailAddress = driver.EmailAddress; driverVm.Quote = driver.Quote; driverVms.Add(driverVm); } return(View(driverVms)); } }
// GET: Admin public ActionResult Index() { using (CarInsuranceEntities db = new CarInsuranceEntities()) { var signups = db.SignUps.ToList(); var signupVms = new List <SignUpVm>(); foreach (var signup in signups) { var signupVm = new SignUpVm(); signupVm.Id = signup.Id; signupVm.FirstName = signup.FirstName; signupVm.LastName = signup.LastName; signupVm.EmailAddress = signup.EmailAddress; signupVm.Quote = signup.Quote; signupVms.Add(signupVm); } return(View(signupVms)); } }
// GET: Admin public ActionResult Index() { using (CarInsuranceEntities db = new CarInsuranceEntities()) { var applying = db.Applicants; var applyVms = new List <ApplyVM>(); foreach (var apply in applying) { var applyVm = new ApplyVM(); applyVm.FirstName = apply.FirstName; applyVm.LastName = apply.LastName; applyVm.EmailAddress = apply.EmailAddress; applyVm.Quote = apply.Quote; applyVms.Add(applyVm); } return(View(applyVms)); } }
public ActionResult SignUp(string fname, string lname, string email, DateTime dob, int year, string make, string carmodel, bool coverage, bool dui, int?ticket) { if (fname != "" || lname != "" || email != null || year <= DateTime.Today.Year || year > DateTime.Today.AddYears(-130).Year || carmodel != "" || make != "") //check for null values { if (ticket == null) { ticket = 0; } using (CarInsuranceEntities db = new CarInsuranceEntities()) { string NewId = Guid.NewGuid().ToString(); var signUpCustomer = new Customer(); //Mapping objects instantiated for all three tables var signupCar = new CustomerCar(); var signupRecord = new CustomerRecord(); signUpCustomer.DateofBirth = dob; signUpCustomer.EmailAddress = email; signUpCustomer.FirstName = fname; signUpCustomer.LastName = lname; signupCar.CarMake = make; signupCar.CarModel = carmodel; signupCar.CarYear = year; signupRecord.DUI = dui; signupRecord.FullCoverage = coverage; signupRecord.NumofTicket = (int)ticket; signUpCustomer.Id = NewId; signupCar.CustomerId = NewId; signupRecord.CustomerId = NewId; db.Customers.Add(signUpCustomer); db.CustomerCars.Add(signupCar); db.CustomerRecords.Add(signupRecord); db.SaveChanges(); } } else { return(RedirectToAction(@"~/views/Shared/Error.cshtml")); } return(View("Success")); }
// GET: Admin public ActionResult Index() { using (CarInsuranceEntities db = new CarInsuranceEntities()) { var quoteinfo = db.QuoteInfoes; var quotes = new List <QuoteInfo>(); foreach (var quote in quoteinfo) { var quoteInfo = new QuoteInfo(); quoteInfo.Id = quote.Id; quoteInfo.FirstName = quote.FirstName; quoteInfo.LastName = quote.LastName; quoteInfo.EmailAddress = quote.EmailAddress; quoteInfo.Quote = quote.Quote; quotes.Add(quoteInfo); } return(View(quotes)); } }
// GET: Admin public ActionResult Index() { using (CarInsuranceEntities db = new CarInsuranceEntities()) { var allClients = (from c in db.Clients select c).ToList(); var viewClients = new List <ClientVm>(); foreach (var client in allClients) { var viewClient = new ClientVm(); viewClient.Id = client.Id; viewClient.FirstName = client.FirstName; viewClient.LastName = client.LastName; viewClient.EmailAddress = client.EmailAddress; viewClient.Quote = client.Quote; viewClients.Add(viewClient); } return(View(viewClients)); } }
// GET: Admin public ActionResult Index() { using (CarInsuranceEntities db = new CarInsuranceEntities()) { var customers = db.CustomerInfoes; var customerVMs = new List <customerVM>(); foreach (var customer in customers) { var CustomerVM = new customerVM(); CustomerVM.Id = customer.Id; CustomerVM.FirstName = customer.FirstName; CustomerVM.LastName = customer.LastName; CustomerVM.EmailAddress = customer.EmailAddress; CustomerVM.Quote = customer.Quote; customerVMs.Add(CustomerVM); } return(View(customerVMs)); } }
// GET: Admin public ActionResult Index() { using (CarInsuranceEntities db = new CarInsuranceEntities()) { var QuoteForms = db.QuoteForms; // 243:2:32 var quoteFormVms = new List <QuoteFormVm>(); foreach (var quote in QuoteForms) { var quoteVm = new QuoteFormVm(); quoteVm.Id = quote.Id; quoteVm.FirstName = quote.FirstName; quoteVm.LastName = quote.LastName; quoteVm.EmailAddress = quote.EmailAddress; quoteVm.FinalQuote = Convert.ToDecimal(quote.FinalQuote); quoteFormVms.Add(quoteVm); } return(View(quoteFormVms)); } }
// GET: Admin public ActionResult Index() { using (CarInsuranceEntities db = new CarInsuranceEntities()) { var quotes = db.Quotes; // this var represents all rows in the Quotes table var quoteVms = new List <QuoteVm>(); foreach (var quote in quotes) { var quoteVm = new QuoteVm { // map the applicable columns from the Model to our ViewModel FirstName = quote.FirstName, LastName = quote.LastName, EmailAddress = quote.EmailAddress, MonthlyPremium = (float)quote.MonthlyPremium }; quoteVms.Add(quoteVm); // add the row to our list of quotes } return(View(quoteVms)); // and display to our view } }
// GET: Admin public ActionResult Index() { using (CarInsuranceEntities db = new CarInsuranceEntities()) { var users = db.Users; var userVMList = new List <UserVM>(); foreach (var user in users) { var userVM = new UserVM(); userVM.FirstName = user.FirstName; userVM.LastName = user.LastName; userVM.EmailAddress = user.EmailAddress; userVM.Quote = user.Quote; userVMList.Add(userVM); } return(View(userVMList)); } }
// GET: Admin public ActionResult Index() { using (CarInsuranceEntities db = new CarInsuranceEntities()) { //var signups = db.SignUps.Where(x => x.Removed == null).ToList(); //var signups = (from c in db.SignUps // where c.Removed == null // select c).ToList(); var driverVms = new List <CardriverVm>(); var drivers = db.CarDrivers; foreach (var driver in drivers) { var driverVm = new CardriverVm(); driverVm.Id = driver.Id; driverVm.FirstName = driver.FirstName; driverVm.LastName = driver.LastName; driverVm.EmailAddress = driver.EmailAddress; driverVm.FinalQuote = Convert.ToDouble(driver.FinalQuote); driverVms.Add(driverVm); } return(View(driverVms)); } }
public ActionResult CustomerInfo(string firstName, string lastName, string emailAddress, DateTime dateOfBirth, int carYear, string carMake, string carModel, bool dui, int speedingTickets, int insuranceType) { using (CarInsuranceEntities db = new CarInsuranceEntities()) { var customerInfo = new CustomerInfo(); customerInfo.FirstName = firstName; customerInfo.LastName = lastName; customerInfo.EmailAddress = emailAddress; customerInfo.DateOfBirth = dateOfBirth; customerInfo.CarYear = carYear; customerInfo.CarMake = carMake; customerInfo.CarModel = carModel; customerInfo.DUI = dui; customerInfo.SpeedingTickets = speedingTickets; customerInfo.InsuranceType = insuranceType; db.CustomerInfoes.Add(customerInfo); db.SaveChanges(); } return View("Success") }
// GET: Admin public ActionResult Index() { //Calling database created using Entity Framework database first using (CarInsuranceEntities db = new CarInsuranceEntities()) { //Creating a list<> of client records, and instanting an empty list for the view model var clients = db.ClientRecords.ToList(); List <ClientRecordVm> clientRecordVm = new List <ClientRecordVm>(); //Passing relevant data from the database record to the view model "clientVm" which will be displayed in the view foreach (var client in clients) { var clientVm = new ClientRecordVm(); clientVm.Id = client.Id; clientVm.FirstName = client.FirstName; clientVm.LastName = client.LastName; clientVm.Quote = Convert.ToInt32(client.Quote); clientVm.EmailAddress = client.EmailAddress; clientRecordVm.Add(clientVm); } return(View(clientRecordVm)); } }
public ActionResult Quote(string firstName, string lastName, string emailAddress, DateTime dateOfBirth, int modelYear, string makeOfCar, string modelOfCar, string dui, int numSpeedingTickets, string coverageType) { // Start with base of $50/month double insQuote = 50.0; // calculate age of customer DateTime now = DateTime.Now; int customerAge = now.Year - dateOfBirth.Year; if (dateOfBirth.DayOfYear > now.DayOfYear) { customerAge -= 1; } // Increase quote per age risk categories if (customerAge < 18) { insQuote += 100; } else if (customerAge < 25) { insQuote += 50; } else if (customerAge > 100) { insQuote += 25; } // Increase quote per age of car if (modelYear < 2000) { insQuote += 25; } else if (modelYear > 2015) { insQuote += 25; } // if it's a Porche increase quote, and if it's a Porche 911 Carrera, increase some more if (new List <string> { "porche", "porsh", "porshe", "porch", "porsha" }.Contains(makeOfCar.ToLower())) { insQuote += 25; if (new List <string> { "911 carrera", "911 carerra", "911 carera", "911 carrerra" }.Contains(modelOfCar.ToLower())) { insQuote += 25; } } // Add 10 for every speeding ticket insQuote += (numSpeedingTickets * 10); // If DUI, add 25% to total if (dui == "Yes") { insQuote *= 1.25; } // If full coverage.... if (coverageType == "Full") { insQuote *= 1.5; } //round the quote to 2 decimal places before it gets used insQuote = Math.Round(insQuote, 2); // Save the data to the database using (CarInsuranceEntities db = new CarInsuranceEntities()) { var quote = new Quote { FirstName = firstName, LastName = lastName, EmailAddress = emailAddress, DateOfBirth = dateOfBirth, ModelOfCar = modelOfCar, MakeOfCar = makeOfCar, ModelYear = modelYear, DUI = (dui == "Yes"), // The form strictly controls what is passed in dui NumSpeedingTickets = numSpeedingTickets, CoverageType = coverageType, MonthlyPremium = insQuote }; db.Quotes.Add(quote); db.SaveChanges(); } // Using a ViewModel, prepare the final quote for display to customer. Capture only relavant info var finalQuote = new QuoteVm() { FirstName = firstName, MonthlyPremium = (float)insQuote }; // pass the quote for display to the customer return(View(finalQuote)); // goes to the Quote.cshtml view }
public ActionResult Apply(string firstName, string lastName, string emailAddress, string birthDate, string carYear, string carMake, string carModel, string DUI, string tickets, string coverageType) { if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress) || string.IsNullOrEmpty(birthDate) || string.IsNullOrEmpty(carYear) || string.IsNullOrEmpty(carMake) || string.IsNullOrEmpty(carModel) || string.IsNullOrEmpty(DUI) || string.IsNullOrEmpty(tickets) || string.IsNullOrEmpty(coverageType)) { return(View("~/Views/Shared/Error.cshtml")); } else { var insurance = 50; var insuranceAge = 0; int bday = Int32.Parse(birthDate); if (bday < 25 && bday > 17) { insuranceAge = 25; } else if (bday < 18) { insuranceAge = 100; } else if (bday > 100) { insuranceAge = 25; } else { insuranceAge = 0; } var insuranceTotal = insurance + insuranceAge; int cyear = Int32.Parse(carYear); var insuranceCYear = 0; if (cyear < 2000) { insuranceCYear = 25; } else if (cyear > 2015) { insuranceCYear = 25; } else { insuranceCYear = 0; } insuranceTotal = (insuranceTotal + insuranceCYear); string CarMake = carMake.ToLower(); string CarModel = carModel.ToLower(); var insuranceCarType = 0; if (CarMake == "porsche" && CarModel != "911 carrera") { insuranceCarType = 25; } else if (CarMake == "porsche" && CarModel == "911 carrera") { insuranceCarType = 50; } else { insuranceCarType = 0; } insuranceTotal = (insuranceTotal + insuranceCarType); var theTicket = Convert.ToInt32(tickets); var insuranceTicket = theTicket * 10; insuranceTotal = (insuranceTotal + insuranceTicket); string dui = DUI.ToLower(); double insuranceDui = 0; if (dui == "yes") { insuranceDui = .25; } else { insuranceDui = 0; } double insuranceTotalD = Convert.ToDouble(insuranceTotal); insuranceTotalD = (insuranceTotal + (insuranceTotal * insuranceDui)); string CoverageType = coverageType.ToLower(); double insuranceType = 0; if (CoverageType == "full" || CoverageType == "full coverage") { insuranceType = .50; } else if (CoverageType == "liability" || CoverageType == "liability coverage") { insuranceType = 0; } insuranceTotalD = (insuranceTotalD + (insuranceTotalD * insuranceType)); string finalInsurance = Convert.ToString(insuranceTotalD); using (CarInsuranceEntities db = new CarInsuranceEntities()) { var apply = new Applicant(); apply.FirstName = firstName; apply.LastName = lastName; apply.EmailAddress = emailAddress; apply.BirthDate = birthDate; apply.CarYear = carYear; apply.CarMake = carMake; apply.CarModel = carModel; apply.DUI = DUI; apply.Tickets = tickets; apply.CoverageType = coverageType; apply.Quote = finalInsurance; db.Applicants.Add(apply); db.SaveChanges(); } return(View("Success", insuranceTotalD)); } }
//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")); }
public ActionResult QuoteForm(string firstName, string lastName, string emailAddress, DateTime dateofBirth, int carYear, string carMake, string carModel, int ticketNumber, bool dui = false, bool coverage = false) // QuoteForm (public partial class QuoteForm in QuoteForm.cs) { if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress) || string.IsNullOrEmpty(dateofBirth.ToString()) || string.IsNullOrEmpty(carYear.ToString()) || string.IsNullOrEmpty(carMake) || string.IsNullOrEmpty(carModel) || string.IsNullOrEmpty(ticketNumber.ToString()) || string.IsNullOrEmpty(dui.ToString()) || string.IsNullOrEmpty(coverage.ToString())) { return(View("~/Views/Shared/Error.cshtml")); } else { using (CarInsuranceEntities db = new CarInsuranceEntities()) // using CarInsurance.Models for database connection { var quote = new QuoteForm(); // Models - QuoteForm.cs (insert data input to database table using Model) / use var because the datatype is obvious quote.FirstName = firstName; quote.LastName = lastName; quote.EmailAddress = emailAddress; quote.DateofBirth = dateofBirth; quote.CarYear = carYear; quote.CarMake = carMake; quote.CarModel = carModel; quote.TicketNumber = ticketNumber; quote.DUI = dui; quote.FullCoverage = coverage; var today = DateTime.Today; var age = today.Year - dateofBirth.Year; var finalQuote = 50m; if (age < 25 && age >= 18) { finalQuote += 25; } else if (age < 18) { finalQuote += 100; } else if (age >= 100) { finalQuote += 25; } if (carYear < 2000) { finalQuote += 25; } else if (carYear >= 2015) { finalQuote += 25; } if (carMake == "Porsche") { finalQuote += 25; } else if (carMake == "Porsche" && carModel == "911 Carrera") { finalQuote += 50; } if (ticketNumber >= 1) { finalQuote = finalQuote + (finalQuote * 10); } else { finalQuote += 0; } if (dui == true) { finalQuote = finalQuote + (finalQuote * .25m); } else { finalQuote += 0; } if (coverage == true) { finalQuote = finalQuote + (finalQuote * .5m); } else { finalQuote += 0; } quote.FinalQuote = finalQuote; db.QuoteForms.Add(quote); // 242:6:42, Models -> CarInsurance.Context.tt -> CarInsurance.Context.cs (database table name) db.SaveChanges(); } return(View("Success")); } }
// GET: Admin public ActionResult Index() { //accessing database using (CarInsuranceEntities db = new CarInsuranceEntities()) { //creating a list of db records and storing as 'customers' var customers = db.Customers; //creating a list of ViewModel objects var customerVms = new List <CustomerVm>(); foreach (var customer in customers) { //creating a ViewModel object and assigning chosen properties to be passed to the view var customerVm = new CustomerVm(); customerVm.FirstName = customer.FirstName; customerVm.LastName = customer.LastName; customerVm.Email = customer.Email; customerVm.Estimate = Convert.ToDecimal(customer.Estimate); //moved this logic to home controller ////Start with a base of $50 / month. //customerVm.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) //{ // customerVm.Estimate += 25m; //} ////If the user is under 18, add $100 to the monthly total. //else if (customerAge < 18) //{ // customerVm.Estimate += 100m; //} ////If the user is over 100, add $25 to the monthly total. //else if (customerAge > 100) //{ // customerVm.Estimate += 25m; //} ////If the car's year is before 2000, add $25 to the monthly total. //if (customer.CarYear < 2000) //{ // customerVm.Estimate += 25m; //} ////If the car's year is after 2015, add $25 to the monthly total. //else if (customer.CarYear > 2015) //{ // customerVm.Estimate += 25; //} ////If the car's Make is a Porsche, add $25 to the price. //if (customer.CarMake.ToLower() == "porsche") //{ // customerVm.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") //{ // customerVm.Estimate += 25m; //} ////Add $10 to the monthly total for every speeding ticket the user has. //for (int i = 0; i < customer.Tickets; i++) //{ // customerVm.Estimate += 10m; //} ////If the user has ever had a DUI, add 25 % to the total. //if (customer.DUI == "true") //{ // customerVm.Estimate *= 1.25m; //} ////If it's full coverage, add 50% to the total. //if (customer.Coverage == "full") //{ // customerVm.Estimate *= 1.5m; //} //adding new ViewModel object to list customerVms.Add(customerVm); } //passing ViewModel list to view return(View(customerVms)); } }
[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 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 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")); } }
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()); } }
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()); } } }