public RedirectToRouteResult Create(User model) { if (ModelState.IsValid) { model.IsActive = true; context.Users.Add(model); context.SaveChanges(); TempData["create"] = "Success"; } return RedirectToAction("Index"); }
public ActionResult Edit(User model) { var user = context.Users.FirstOrDefault(x => x.Username == model.Username); string message; if (user != null) { if (model.Password != null) { user.Password = model.Password; } user.RoleId = model.RoleId; context.SaveChanges(); message = "Success"; } else { message = "Failed"; } TempData["edit"] = message; return RedirectToAction("Index"); }
public void CreateAccount(RegisterModel model) { using (var context = new SmartBuyEntities()) { // Duplicate account var account = context.Users.FirstOrDefault(x => x.Username == model.UserName); if (account != null) { throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateUserName); } var newUser = new User { Username = model.UserName, Password = model.Password, RoleId = model.RoleId, IsActive = true }; context.Users.Add(newUser); context.SaveChanges(); } }
public ActionResult SetActive(string username) { var user = context.Users.FirstOrDefault(x => x.Username == username); bool statusFlag = false; if (ModelState.IsValid) { if (user.IsActive == true) { user.IsActive = false; statusFlag = false; } else { user.IsActive = true; statusFlag = true; } context.SaveChanges(); } // Display the confirmation message var results = new User { IsActive = statusFlag }; return Json(results); }