// [Authorize(Roles = "Admin")] public virtual ActionResult Delete(int id) { 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); }
public virtual ActionResult Edit(string id, ManageMessageId? Message = null) { var Db = new ApplicationDbContext(); var user = Db.Users.First(u => u.UserName == id); var model = new EditUserViewModel(user); ViewBag.MessageId = Message; return View(model); }
public virtual async Task<ActionResult> Edit(EditUserViewModel model) { if (ModelState.IsValid) { var Db = new ApplicationDbContext(); var user = Db.Users.First(u => u.UserName == model.UserName); user.FirstName = model.FirstName; user.LastName = model.LastName; 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); }
public virtual 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); model.Add(u); } return View(model); }