Exemplo n.º 1
0
        public ActionResult Add(SettingsViewModel addForm)
        {
            //Grab users email to add to correct collection document
            string usersEmail = addForm.Email;

            //Get the type of car selected by the CarID
            string CarSelected = GetSelectedCarType(addForm.CarType);



            //Create new UsersCar object to add into database -> Gets information from the Form
            UsersCars newCar = new UsersCars();

            newCar.CarID         = Guid.NewGuid().ToString();
            newCar.Type          = CarSelected;
            newCar.mileage       = addForm.Mileage;
            newCar.monthsOwned   = addForm.MonthsOwned;
            newCar.totalSpent    = addForm.TotalSpent;
            newCar.InspectionDue = addForm.InspectionDate;
            newCar.CarNickname   = addForm.CarNickname;
            //Create a statement that initializes a personal maintenance object
            newCar.PersonalMaintenance = dal.InitializePersonalMaintenance(newCar.mileage, newCar.totalSpent);

            //If dal.AddCar is succesful -> redirects to users setting page
            if (dal.AddCar(usersEmail, newCar))
            {
                Session["email"] = usersEmail;
                var email = (string)Session["email"];
                return(RedirectToAction("Settings", "Manage", new { email }));
            } //Not successful throw error
            else
            {
                throw new Exception("Error");
            }
        }