Exemple #1
0
        public ActionResult Delete(int ID)
        {
            SubDbContext context = new SubDbContext();
            User         user    = context.Users.Find(ID);

            if (null != user)
            {
                context.Users.Remove(user);
                context.SaveChanges();
            }

            return(RedirectToAction("ShowUsersList"));
        }
Exemple #2
0
        public ActionResult Create(CarViewModel newCar)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            Car car = MapToCar(newCar);

            SubDbContext context = new SubDbContext();

            context.Cars.Add(car);
            context.SaveChanges();

            return(RedirectToAction("ShowCarsList", new { userID = newCar.UserID }));
        }
Exemple #3
0
        public ActionResult Create(UserViewModel newUser)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            User user = MapToUser(newUser);

            SubDbContext context = new SubDbContext();

            context.Users.Add(user);
            context.SaveChanges();

            return(RedirectToAction("ShowUsersList"));
        }
Exemple #4
0
        public ActionResult Edit(UserViewModel userModel)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            SubDbContext context = new SubDbContext();
            User         user    = context.Users.Find(userModel.ID);

            if (null != user)
            {
                user.FirstName     = userModel.FirstName;
                user.MiddleName    = userModel.MiddleName;
                user.LastName      = userModel.LastName;
                user.GPA           = userModel.GPA;
                user.YearsInSchool = userModel.YearsInSchool;
                user.EmailAddress  = userModel.EmailAddress;
                context.SaveChanges();
            }


            return(RedirectToAction("ShowUsersList"));
        }