public ActionResult Edit(User user) { try { if (ModelState.IsValid) { if (user.Password == null) { user.Password = String.Empty; } dbContext.Users.Attach(user); var entry = dbContext.Entry(user); entry.State = EntityState.Modified; if (user.Password == String.Empty) { entry.Property(u => u.Password).IsModified = false; } else /*triggered if the password was updated/changed*/ { user.PasswordExpireAt = DateTime.Now.AddDays(Util.GetPasswordExpirationDays()); } dbContext.SaveChanges(); return RedirectToAction("Details", new { id = user.UserId }); } else { LoadLookupValues(ViewBag, user.AgentId ?? 0); return View(user); } } catch (Exception ex) { Util.HandleException(ex.GetBaseException()); return RedirectToAction("Error", "Default", null); } }
public ActionResult Create(User user) { try { if (ModelState.IsValid) { user.PasswordExpireAt = DateTime.Now.AddDays(Util.GetPasswordExpirationDays()); dbContext.Users.Add(user); dbContext.SaveChanges(); return RedirectToAction("Details", new { id = user.UserId }); } else { LoadLookupValues(ViewBag); } } catch (Exception ex) { Util.HandleException(ex.GetBaseException()); return RedirectToAction("Error", "Default", null); } return View(user); }