public Dictionary <string, object> modify([FromBody] sysRole role) { if (string.IsNullOrEmpty(role.RoleName)) { result["code"] = "failed"; message.Add("角色名称必填"); } if (result["code"].ToString() == "success") { sysRole newRole = db.sysRoles.FirstOrDefault(w => w.RoleId == role.RoleId); Ricky.ObjectCopy.Copy <sysRole>(role, newRole); var a = from b in db.sysAuthorInRoles where b.RoleId == role.RoleId select b; db.sysAuthorInRoles.RemoveRange(a); db.SaveChanges(); foreach (int AuthorId in role.AuthorIds) { sysAuthorInRole authorRole = new sysAuthorInRole(); authorRole.RoleId = role.RoleId; authorRole.AuthorId = AuthorId; db.sysAuthorInRoles.Add(authorRole); } db.SaveChanges(); } result["message"] = message; return(result); }
public Dictionary <string, object> add([FromBody] sysRole role) { if (string.IsNullOrEmpty(role.RoleName)) { result["code"] = "failed"; message.Add("角色名称必填"); } if (result["code"].ToString() == "success") { db.sysRoles.Add(role); db.SaveChanges(); foreach (int AuthorId in role.AuthorIds) { sysAuthorInRole authorRole = new sysAuthorInRole(); authorRole.RoleId = role.RoleId; authorRole.AuthorId = AuthorId; db.sysAuthorInRoles.Add(authorRole); } db.SaveChanges(); } result["message"] = message; return(result); }