public async override Task Execute(AddRoleToUserCommand input, User?user) { var userToRemoveFrom = await userRepo.FindById(input.UserId) ?? throw new EntityNotFoundException(); var role = await roleRepo.FindById(input.RoleId) ?? throw new EntityNotFoundException(); await roleRepo.AddToUser(userToRemoveFrom, role); }
public async override Task Execute(RoleDeleteCommand input, User?user) { var r = await repo.FindById(input.Id) ?? throw new EntityNotFoundException(); await spec.CheckAndThrow(r); await repo.Delete(r); }
public async override Task Execute(RoleUpdateCommand input, User?user) { var r = await repo.FindById(input.Id) ?? throw new EntityNotFoundException(); r.Name = input.Name; r.PermissionIds = input.PermissionIds.Distinct().ToList(); await nameUniqueSpec.CheckAndThrow(r); await permissionsDistinctSpec.CheckAndThrow(r); await repo.Update(r); }
public async Task ReplaceRoles(User user, Guid roleId) { var role = await roleRepo.FindById(roleId) ?? throw new EntityNotFoundException(); await roleRepo.AddToUser(user, role, true); }