public ActionResult Create(RoleModel model) { try { RoleDto dto = new RoleDto(); dto.RoleName = model.RoleName; dto.RoleDescription = model.RoleDescription; string JsonString = JsonHelper.JsonSerializerBySingleData(dto); Message msg = CMSService.Insert("Role", JsonString); return RedirectTo("/Role/Index", msg.MessageInfo); } catch { Message msg = new Message(); msg.MessageStatus = "Error"; msg.MessageInfo = "操作出错了"; ViewBag.Status = msg.MessageStatus; ViewBag.msg = msg.MessageInfo; return View(); } }
public ActionResult Edit(RoleModel model) { try{ RoleDto dto = new RoleDto(); DataTable dt = CMSService.SelectOne("Role", "CMSRole", "RoleId=" + model.RoleId); foreach (DataRow dr in dt.Rows) { dto = RoleMapping.getDTO(dr); dto.RoleName = model.RoleName; dto.RoleDescription = model.RoleDescription; } string JsonString = JsonHelper.JsonSerializerBySingleData(dto); Message msg = CMSService.Update("Role", JsonString); // TODO: Add update logic here return RedirectToAction("Index"); } catch { Message msg = new Message(); msg.MessageStatus = "Error"; msg.MessageInfo = "操作出错了"; ViewBag.Status = msg.MessageStatus; ViewBag.msg = msg.MessageInfo; return View(); } }
// // GET: /Role/Edit/5 public ActionResult Edit(int id) { RoleModel model = new RoleModel(); DataTable dt = CMSService.SelectOne("Role", "CMSRole", "RoleId=" + id); foreach (DataRow dr in dt.Rows) { RoleDto dto = new RoleDto(); dto = RoleMapping.getDTO(dr); model.RoleName = dto.RoleName; model.RoleDescription = dto.RoleDescription; model.RoleId = dto.RoleId; } return View(model); }