public virtual async Task DeleteToDoGroup(Guid key, CancellationToken cancellationToken) { Guid userId = Guid.Parse(UserInformationProvider.GetCurrentUserId()); ToDoGroup toDoGroupToBeDeleted = await ToDoGroupsRepository.GetByIdAsync(cancellationToken, key); if (toDoGroupToBeDeleted == null) { throw new ResourceNotFoundException("ToDoGroupCouldNotBeFound"); } if (toDoGroupToBeDeleted.CreatedById != userId) { throw new DomainLogicException("OnlyOwnerCanDeleteTheToDoGroup"); } await ToDoGroupsRepository.DeleteAsync(toDoGroupToBeDeleted, cancellationToken); }
public virtual async Task <ToDoGroupDto> UpdateToDoGroup(Guid key, ToDoGroupDto toDoGroup, CancellationToken cancellationToken) { if (toDoGroup == null) { throw new BadRequestException("ToDoGroupMayNotBeNull"); } Guid userId = Guid.Parse(UserInformationProvider.GetCurrentUserId()); ToDoGroup toDoGroupToBeModified = await ToDoGroupsRepository.GetByIdAsync(cancellationToken, key); if (toDoGroupToBeModified == null) { throw new ResourceNotFoundException("ToDoGroupCouldNotBeFound"); } ToDoGroupOptions toDoGroupOptionsToBeModified = await ToDoGroupOptionsListRepository.GetAll() .FirstAsync(tdgo => tdgo.UserId == userId && tdgo.ToDoGroupId == key, cancellationToken); if (toDoGroupOptionsToBeModified == null) { throw new ResourceNotFoundException("ToDoGroupCouldNotBeFound"); } toDoGroupToBeModified.Title = toDoGroup.Title; toDoGroupToBeModified.ModifiedOn = DateTimeProvider.GetCurrentUtcDateTime(); toDoGroupOptionsToBeModified.Theme = toDoGroup.Theme; toDoGroupOptionsToBeModified.HideCompletedToDoItems = toDoGroup.HideCompletedToDoItems; toDoGroupOptionsToBeModified.SortedBy = toDoGroup.SortedBy; await ToDoGroupsRepository.UpdateAsync(toDoGroupToBeModified, cancellationToken); await ToDoGroupOptionsListRepository.UpdateAsync(toDoGroupOptionsToBeModified, cancellationToken); return(await GetMyToDoGroups() .FirstAsync(tdg => tdg.Id == key, cancellationToken)); }