public virtual async Task <ToDoItemDto> UpdateToDoItem(Guid key, ToDoItemDto toDoItem, CancellationToken cancellationToken) { if (toDoItem == null) { throw new BadRequestException("ToDoItemCouldNotBeNull"); } Guid userId = Guid.Parse(UserInformationProvider.GetCurrentUserId()); ToDoItem toDoItemToBeModified = await ToDoItemsRepository.GetByIdAsync(cancellationToken, key); if (toDoItemToBeModified == null) { throw new ResourceNotFoundException("ToDoItemCouldNotBeFound"); } ToDoItemOptions toDoItemOptionsToBeModified = await ToDoItemOptionsListRepository.GetAll() .FirstAsync(tdio => tdio.UserId == userId && tdio.ToDoItemId == key, cancellationToken); if (toDoItemOptionsToBeModified == null) { throw new ResourceNotFoundException("ToDoItemCouldNotBeFound"); } if (toDoItem.ToDoGroupId != toDoItemToBeModified.ToDoGroupId) { throw new BadRequestException("ChangingToDoGroupIdIsNotSupportedAtTheMoment"); } toDoItemToBeModified.Title = toDoItem.Title; toDoItemToBeModified.IsImportant = toDoItem.IsImportant; toDoItemToBeModified.Notes = toDoItem.Notes; toDoItemToBeModified.DueDate = toDoItem.DueDate; toDoItemToBeModified.ModifiedOn = DateTimeProvider.GetCurrentUtcDateTime(); if (toDoItemToBeModified.IsCompleted == false && toDoItem.IsCompleted == true) { toDoItemToBeModified.IsCompleted = true; toDoItemToBeModified.CompletedById = userId; } else if (toDoItemToBeModified.IsCompleted == true && toDoItem.IsCompleted == false) { toDoItemToBeModified.IsCompleted = false; toDoItemToBeModified.CompletedById = null; } toDoItemOptionsToBeModified.RemindOn = toDoItem.RemindOn; toDoItemOptionsToBeModified.ShowInMyDayOn = toDoItem.ShowInMyDay == true ? (DateTimeOffset?)DateTimeProvider.GetCurrentUtcDateTime() : null; await ToDoItemsRepository.UpdateAsync(toDoItemToBeModified, cancellationToken); await ToDoItemOptionsListRepository.UpdateAsync(toDoItemOptionsToBeModified, cancellationToken); return(await GetMyToDoItems() .FirstAsync(tdi => tdi.Id == key, cancellationToken)); }
public virtual async Task DeleteToDoItem(Guid key, CancellationToken cancellationToken) { Guid userId = Guid.Parse(UserInformationProvider.GetCurrentUserId()); ToDoItem toDoItemToBeDeleted = await ToDoItemsRepository.GetByIdAsync(cancellationToken, key); if (toDoItemToBeDeleted == null) { throw new ResourceNotFoundException("ToDoItemCouldNotBeFound"); } await ToDoItemsRepository.DeleteAsync(toDoItemToBeDeleted, cancellationToken); }