Example #1
0
        public async Task <ActionResult <TodoItem> > PostTodoItem(TodoItem item)
        {
            await _repository.AddTodoItemAsync(item);

            await _repository.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetTodoItem), new { id = item.Id }, item));
        }
Example #2
0
        private async Task AddTodoItem(string description)
        {
            var todoItem = await _todoRepository.AddTodoItemAsync(new TodoItem()
            {
                Description = description
            });

            _todoCache.Add(todoItem);

            var indexPath = NSIndexPath.FromRowSection(_todoCache.Count - 1, 0);

            InvokeOnMainThread(() => TableView.InsertRows(new[] { indexPath }, UITableViewRowAnimation.Automatic));
        }
Example #3
0
        public TodoController(ITodoRepository repository)
        {
            _repository = repository;

            if (_repository.TodoItemsExist())
            {
                // Create a new TodoItem if collection is empty,
                // which means you can't delete all TodoItems.
                _repository.AddTodoItemAsync(new TodoItem
                {
                    Name = "Item1"
                });
                _repository.SaveChangesAsync();
            }
        }