private async Task <int> Edit(Employee employee) { db.Employee.Update(employee); var roleIds = employee.EmpRole.Select(x => x.RoleId).ToList(); var removeRole = await db.EmpRole.Where(x => x.EmpId == employee.Id && !roleIds.Contains(x.RoleId)).ToListAsync(); db.RemoveRange(removeRole); return(await db.SaveChangesAsync()); }
private async Task <int> ChangePowerMenu(int pId, int[] mId) { var menus = await db.RoleMenu.Where(x => x.PowerId == pId).ToListAsync(); var mIds = menus.Select(x => x.MenuId).ToList(); var delMs = menus.Where(x => !mId.Contains(x.MenuId)).ToList(); db.RemoveRange(delMs); var addRps = mId.Where(x => !mIds.Contains(x)).Select(x => new RoleMenu() { PowerId = pId, MenuId = x }).ToList(); await db.AddRangeAsync(addRps); return(await db.SaveChangesAsync()); }
private async Task <int> ChangePoweRole(int rId, int[] pId) { var rp = await db.RolePower.Where(x => x.RoleId == rId).ToListAsync(); var rpIds = rp.Select(x => x.PowerId).ToList(); var delRps = rp.Where(x => !pId.Contains(x.PowerId)).ToList(); db.RemoveRange(delRps); var addRps = pId.Where(x => !rpIds.Contains(x)).Select(x => new RolePower() { RoleId = rId, PowerId = x }).ToList(); await db.AddRangeAsync(addRps); return(await db.SaveChangesAsync()); }