Ejemplo n.º 1
0
        public async Task <TodoItemDTO> CreateTodoItemAsync(TodoItemDTO todoItemDTO)
        {
            if (todoItemDTO.Id != 0)
            {
                _logger.LogWarning($"Creating a todoItem {todoItemDTO.Name} with id set {todoItemDTO.Id}");
            }

            TodoItem todoItem = new TodoItem
            {
                Name       = todoItemDTO.Name,
                IsComplete = todoItemDTO.IsComplete
            };

            _context.TodoItems.Add(todoItem);
            await _context.SaveChangesAsync();

            // Create a new TodoItemDTO because the todoItem.id is set to the real value and needed by the caller.
            return(new TodoItemDTO(todoItem));
        }
Ejemplo n.º 2
0
        public async Task <bool> SaveChangesAsync()
        {
            var returnVal = await _context.SaveChangesAsync();

            return(returnVal >= 0);
        }