Ejemplo n.º 1
0
        async Task IUserService.DeleteUser(DeleteUserCommand command)
        {
            Check.NotNull(command, name: "Command");
            await validationService.Validate(command);

            var user = await userRepository.GetUserById(command.UserId);

            if (user == null)
            {
                return;
            }

            var currentPrincipal = await currentUserResolver.ResolveCurrentClaimsPrincipalAsync();

            var operation = command.ForceDelete ? Operation.ForceDelete : Operation.Delete;
            await authorizationService.AuthorizeResource(currentPrincipal, operation, user);

            try
            {
                await userRepository.DeleteUser(user, command.ForceDelete);
            }
            catch (RelationshipException ex)
            {
                throw new DeleteUserException("There are time entries associated with this user, try force delete.", ex);
            }

            await userManager.RemoveUser(user.Id);
        }
Ejemplo n.º 2
0
        async Task ITimeEntryService.DeleteTimeEntry(DeleteTimeEntryCommand command)
        {
            var currentPrincipal = await currentUserResolver.ResolveCurrentClaimsPrincipalAsync();

            await authorizationService.AuthorizeResourceType(currentPrincipal, Operation.Delete, typeof(TimeEntry));

            Check.NotNull(command, errorMessage: "Command can not be null.");
            await validationService.Validate(command);

            var existingTimeEntry = await timeEntryRepository.GetTimeEntryById(command.TimeEntryId);

            if (existingTimeEntry == null)
            {
                return;
            }

            await authorizationService.AuthorizeResource(currentPrincipal, Operation.Delete, existingTimeEntry);

            await timeEntryRepository.DeleteTimeEntry(existingTimeEntry);
        }