public async Task testAddRole() { SystemRole sr = new SystemRole { RoleName = "普通用户", RoleDescription = "拥有查看基本模块的权限" }; SystemRoleService srs = new SystemRoleService(); srs.Add(sr); int result = await srs.SaveChangesAsync(); Assert.IsTrue(result == 1); }
public int Add(SystemRole role) { if (role != null) { sr.RoleName = role.RoleName; sr.RoleDescription = role.RoleDescription; srs.Add(sr); int result = srs.SaveChanges(); return(result); } else { return(0); } }
public ActionResult RoleAdd(string RoleName, string Description) { try { if (!string.IsNullOrEmpty(RoleName) && !string.IsNullOrEmpty(Description)) { SystemRole role = _SystemRoleService.GetWhere(r => r.RoleName == RoleName).FirstOrDefault(); if (role != null) { //_role = role; //_role.Description = Description; //_SystemRoleService.Edit(role); //_SystemMenuService.Save(); return(Json(new { Code = "-3", msg = "已经存在同样的角色名称" }, JsonRequestBehavior.AllowGet)); } else { role = new SystemRole(); role.RoleName = RoleName; role.Description = Description; role.Depth = 1; role.Path = role.Id + ","; _SystemRoleService.Add(role); _SystemMenuService.Save(); return(Json(new { Code = "2", msg = "添加成功" }, JsonRequestBehavior.AllowGet)); } } return(Json(new { Code = "-2", msg = "请检查输入" }, JsonRequestBehavior.AllowGet)); } catch (Exception error) { return(Json(new { Code = "-1", msg = "添加异常:" + error.Message }, JsonRequestBehavior.AllowGet)); } }