Exemplo n.º 1
0
        public async Task UpdateTodoAsync(UpdatedTodoDTO updatedTodoDTO)
        {
            var todoToUpdate = _mapper.Map <UpdatedTodoDTO, Todo>(updatedTodoDTO);

            try
            {
                await _todosRepository.UpdateTodoAsync(todoToUpdate);
            }
            catch (RecordNotFoundException)
            {
                throw new TodoNotFoundException();
            }
            catch (ConcurrentAccessException)
            {
                // TODO: Add logging here to indicate that we have hit
                // a database concurrency issue. For now I'll just
                // throw a NotFound error if the todo does not actually exist.
                // If it does exist, for now I'll just rethrow the error.
                bool todoExists = await _todosRepository.Exists(updatedTodoDTO.Id.Value);

                if (!todoExists)
                {
                    throw new TodoNotFoundException();
                }

                throw;
            }
        }
Exemplo n.º 2
0
        public async Task <OperationStatus> ToggleTodoCompletedStatusAsync(int id)
        {
            var todo = await _todosRepository.GetTodoAsync(id);

            if (todo is null)
            {
                return(OperationStatus.EntityNotFound);
            }

            todo.IsComplete = !todo.IsComplete;

            if (await _todosRepository.UpdateTodoAsync(todo))
            {
                return(OperationStatus.Success);
            }

            return(OperationStatus.UnexpectedResult);
        }
Exemplo n.º 3
0
 public Task <bool> UpdateTodoAsync(TodoItem todoItem)
 {
     return(_todosRepository.UpdateTodoAsync(todoItem));
 }