Esempio n. 1
0
        public ActionResult Edit(int ID)
        {
            SubDbContext context = new SubDbContext();
            User         user    = context.Users.Find(ID);

            if (null == user)
            {
                return(RedirectToAction("ShowUsersList"));
            }

            return(View(MapToUserViewModel(user)));
        }
Esempio n. 2
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"));
        }
Esempio n. 3
0
        public ActionResult ShowUsersList()
        {
            SubDbContext db = new SubDbContext();

            List <UserViewModel> models = new List <UserViewModel>();

            foreach (User user in db.Users)
            {
                UserViewModel model = MapToUserViewModel(user);
                models.Add(model);
            }

            return(View(models));
        }
Esempio n. 4
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 }));
        }
Esempio n. 5
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"));
        }
Esempio n. 6
0
        public ActionResult ShowCarsList(int userID)
        {
            SubDbContext db = new SubDbContext();

            List <CarViewModel> models = new List <CarViewModel>();

            ViewBag.userID = userID;

            foreach (Car car in db.Cars)
            {
                if (car.UserID == userID)
                {
                    CarViewModel model = MapToCarViewModel(car);
                    models.Add(model);
                }
            }

            return(View(models));
        }
Esempio n. 7
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"));
        }
Esempio n. 8
0
 public UserRepository(SubDbContext context)
 {
     this.context = context;
 }