public ActionResult AddOrUpdateRole(FormCollection formCollection, RolesContract rolesContract) { if (ModelState.IsValid) { //用于判断是否立即编辑权限 int num; int.TryParse(formCollection["IsMenu"], out num); bool boo = false; //获取角色ID用于设置权限 int roleId = 0; if (rolesContract.RoleID == 0) { boo = int.TryParse(rolesServices.AddRole(rolesContract), out roleId); } else { boo = rolesServices.UpdateRole(rolesContract); } if (boo) { roleId = rolesContract.RoleID == 0 ? roleId : rolesContract.RoleID; if (num != 0) { //执行成功信息 ViewData["msg"] = "角色信息操作成功!"; //成功后要跳转的路径(如果无须跳转,直接留在当前页面,不写即可) ViewData["url"] = new UrlHelper(Request.RequestContext).Action("RolesList"); //成功视图 return View("Success"); } return RedirectToAction("Update_Role_Authority", "AuthorityManager", new { id = roleId }); } //执行成功信息 ViewData["msg"] = "角色信息操作失败!"; return View("Error"); } return View(rolesContract); }
/// <summary> /// 添加角色信息 /// </summary> /// <param name="roles"></param> /// <returns></returns> public string AddRole(RolesContract rolesContract) { Roles roles = rolesContract.ToPO<Roles>(); return rolesRepository.AddRole(roles: roles); }
/// <summary> /// 添加或者更新角色 /// </summary> /// <param name="tag"></param> /// <param name="id"></param> /// <returns></returns> public ActionResult AddOrUpdateRole(string tag, string id) { //创建空实体 RolesContract rolesContract = new RolesContract(); if (!("add").Equals(tag)) { rolesContract = rolesServices.GetRoleEntity(id); } return View(rolesContract); }
/// <summary> /// 更新角色信息 /// </summary> /// <param name="roles"></param> /// <returns></returns> public bool UpdateRole(RolesContract rolesContract) { Roles roles = rolesContract.ToPO<Roles>(); return rolesRepository.UpdateRole(roles: roles); }