Пример #1
0
        public async Task <ToDoListResponse> DeleteAsync(int id)
        {
            var existingToDoListItem = await _toDoListRepository.FindByIdAsync(id);

            if (existingToDoListItem == null)
            {
                return(new ToDoListResponse("ToDoListItem not found."));
            }

            try
            {
                _toDoListRepository.Remove(existingToDoListItem);
                await _unitOfWork.CompleteAsync();

                return(new ToDoListResponse(existingToDoListItem));
            }
            catch (Exception ex)
            {
                return(new ToDoListResponse($"An error occurred when deleting the ToDoListItem: {ex.Message}"));
            }
        }