Beispiel #1
0
        public ActionResult Index()
        {
            var Db = new ApplicationDbContext();
            var users = Db.Users;
            var model = new List<EditUserViewModel>();

            foreach (var user in users)
            {
                var u = new EditUserViewModel(user);
                var role = user.Roles.FirstOrDefault();

                if(role != null)
                {
                    u.RoleName = Db.Roles.Where(m => m.Id == role.RoleId).Select(m=>m.Name).FirstOrDefault();
                }

                model.Add(u);
            }

            return View(model);
        }
Beispiel #2
0
 public ActionResult Edit(string id, SEATS.Controllers.ManageController.ManageMessageId? Message = null)
 {
     var Db = new ApplicationDbContext();
     var user = Db.Users.First(u => u.Id == id);
     var model = new EditUserViewModel(user);
     ViewBag.MessageId = Message;
     return View(model);
 }
Beispiel #3
0
        public ActionResult Delete(string id = null)
        {
            var Db = new ApplicationDbContext();
            var user = Db.Users.First(u => u.Id == id);
            var model = new EditUserViewModel(user);

            if (user == null)
            {
                return HttpNotFound();
            }

            return View(model);
        }
Beispiel #4
0
        public async Task<ActionResult> Edit(EditUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var Db = new ApplicationDbContext();
                var user = Db.Users.First(u => u.Id == model.Id);

                // Update the user data:

                user.Email = model.Email;
                Db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                await Db.SaveChangesAsync();
                return RedirectToAction("Index");
            }

            // If we got this far, something failed, redisplay form

            return View(model);
        }