public ActionResult Create(UserDTO entity) { int errors = 0; string message = string.Empty; if (Const.IsNullOrEmpty(entity.Login_ID)) { errors++; message = "帐号名不能为空。<br/>"; } if (Const.IsNullOrEmpty(entity.Username)) { errors++; message = "用户名不能为空。<br/>"; } if (Const.IsNullOrEmpty(entity.Role_Code)) entity.Role_Code = "Guest"; if (entity.Department_ID <= 0) entity.Department_ID = 1; using (DataClassesDataContext data = new DataClassesDataContext()) { if (data.UserDTO.Where(u => u.Login_ID == entity.Login_ID).Count() > 0) { errors++; message = entity.Login_ID + " 帐号已经存在。<br/>"; } if (errors == 0) { entity.Password = "******"; data.UserDTO.InsertOnSubmit(entity); data.SubmitChanges(); } } return Json(new {success = (errors == 0), message = message}, JsonRequestBehavior.AllowGet); }
public ActionResult Update(UserDTO entity) { try { if (entity.Login_ID == "Admin") { return Json(new { success = false, message = "Admin 帐号不能修改。<br/>" }, JsonRequestBehavior.AllowGet); } int errors = 0; string message = string.Empty; if (Const.IsNullOrEmpty(entity.Login_ID)) { errors++; message = "帐号不能为空。<br/>"; } if (Const.IsNullOrEmpty(entity.Username)) { errors++; message = "用户名不能为空。<br/>"; } if (Const.IsNullOrEmpty(entity.Role_Code)) entity.Role_Code = "Guest"; if (entity.Department_ID <= 0) entity.Department_ID = 1; using (DataClassesDataContext data = new DataClassesDataContext()) { var items = data.UserDTO.Where(u => u.Login_ID == entity.Login_ID) .ToList(); if (items.Count == 0) { errors++; message = entity.Login_ID + " 帐号不存在。<br/>"; } if (errors == 0) { var e = items.First(); e.Login_ID = entity.Login_ID; e.Department_ID = entity.Department_ID; e.Role_Code = entity.Role_Code; e.Username = entity.Username; data.SubmitChanges(); } } return Json(new { success = (errors == 0), message = message }, JsonRequestBehavior.AllowGet); } catch { return View(); } }
partial void UpdateUserDTO(UserDTO instance);
partial void DeleteUserDTO(UserDTO instance);
partial void InsertUserDTO(UserDTO instance);