Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        public async Task ReplaceRoles(User user, Guid roleId)
        {
            var role = await roleRepo.FindById(roleId) ?? throw new EntityNotFoundException();

            await roleRepo.AddToUser(user, role, true);
        }