public ActionResult EditHRSave(User model, string returnUrl = "Index") { ViewBag.Path1 = "用户"; //检查记录在权限范围内 var result = Common.GetHRQuery(db).Where(a => a.Id == model.Id).SingleOrDefault(); if (result == null) { Common.RMError(this); return Redirect(Url.Content(returnUrl)); } //end if (ModelState.IsValid) { try { result.Mail = model.Mail; db.PPSave(); Common.RMOk(this, "记录:" + result + "保存成功!"); return Redirect(Url.Content(returnUrl)); } catch (Exception e) { if (e.InnerException.Message.Contains("Cannot insert duplicate key row")) { ModelState.AddModelError(string.Empty, "相同名称的记录已存在,保存失败!"); } } } ViewBag.ReturnUrl = returnUrl; return View("EditHR", model); }
public ActionResult RestoreHRSave(User record, string returnUrl = "Index") { ViewBag.Path1 = "用户"; //检查记录在权限范围内 var result = Common.GetHRQuery(db, true).Where(a => a.IsDeleted == true).Where(a => a.Id == record.Id).SingleOrDefault(); if (result == null) { Common.RMError(this); return Redirect(Url.Content(returnUrl)); } //end try { result.IsDeleted = false; db.PPSave(); Common.RMOk(this, "记录:" + result + "恢复成功!"); return Redirect(Url.Content(returnUrl)); } catch (Exception e) { Common.RMOk(this, "记录" + result + "恢复失败!" + e.ToString()); } return Redirect(Url.Content(returnUrl)); }