public async Task DelPermission([FromQuery] int id) { var del = new PermissionEntity { Id = id }; pcontext.Entry(del).State = EntityState.Deleted; await pcontext.SaveChangesAsync(); }
public async Task SetRole([FromQuery] int userid, [FromBody] int[] roleids) { var maps = await pcontext.UserRoleMap.Where(map => map.UserId == userid).ToListAsync(); maps.ForEach(map => { if (!roleids.Contains(map.RoleId)) { pcontext.Entry(map).State = EntityState.Deleted; } }); foreach (var roleid in roleids) { if (!maps.Any(m => m.RoleId == roleid)) { pcontext.UserRoleMap.Add(new UserRoleMap { UserId = userid, RoleId = roleid }); } } await pcontext.SaveChangesAsync(); }
public async Task SetAdmin([FromQuery] int id, [FromBody] string[] appcodes) { var maps = await pcontext.RoleAppAdmin.Where(map => map.RoleId == id).ToListAsync(); maps.ForEach(map => { if (!appcodes.Contains(map.Code)) { pcontext.Entry(map).State = EntityState.Deleted; } }); foreach (var code in appcodes) { if (!maps.Any(m => m.Code == code)) { pcontext.RoleAppAdmin.Add(new RoleAppAdmin { RoleId = id, Code = code }); } } await pcontext.SaveChangesAsync(); }