public TodoListModel(TodoList todoList)
 {
     todoListId = todoList.TodoListId;
     userId = todoList.UserId;
     title = todoList.Title;
     todos = new ObservableCollection<TodoItemModel>(todoList.Todos.Select(todo => new TodoItemModel(todo)));
 }
        public async Task AddTodoListWithDifferentUserId()
        {
            TodoList todoList = new TodoList() { TodoListId = 2, Title = "Nice to have", UserId = invalidUsername };

            HttpResult<TodoList> result = await client.AddTodoListAsync(todoList);

            Assert.IsNotNull(result, "Result is null");
            Assert.IsTrue(result.Succeeded, GetRequestFailedMessage(result));
            Assert.AreEqual(result.Content.UserId, username);
        }
 public TodoListModel(TodoList todoList) : this()
 {
     todoListId = todoList.TodoListId;
     userId = todoList.UserId;
     title = todoList.Title;
     if (todoList.Todos != null)
     {
         todos = new ObservableCollection<TodoItemModel>(todoList.Todos.Select(todo => new TodoItemModel(todo) { TodoList = this }));
     }
 }
        public async Task AddTodoList()
        {
            TodoList todoList = new TodoList() { TodoListId = 2, Title="Nice to have" };

            HttpResult<TodoList> result = await client.AddTodoListAsync(todoList);

            Assert.IsNotNull(result, "Result is null");
            Assert.IsTrue(result.Succeeded, GetRequestFailedMessage(result));
            Assert.AreEqual(todoList.TodoListId, result.Content.TodoListId, "New TodoList ID does not match.");
            Assert.AreEqual(todoList.Title, result.Content.Title, "New TodoList title does not match");
            Assert.AreEqual(result.Content.UserId, username, "New TodoList user ID does not match");
        }
        private async void OkButton_Click(object sender, EventArgs e)
        {
            TodoList todoList = new TodoList() { TodoListId = todoListId, Title = TitleTextBox.Text };

            HttpResult result;
            using (TodoClient todoClient = ClientFactory.CreateTodoClient())
            {
                result = await todoClient.UpdateTodoListAsync(todoList);
            }

            if (result.Succeeded)
            {
                this.NavigationService.GoBack();
            }
            else
            {
                ErrorDialog.ShowErrors(result.Errors);
            }
        }
        public async Task UpdateTodoList()
        {
            string newTitle = "Nice to have";
            TodoList update = new TodoList() { TodoListId = 1, Title = newTitle, UserId = username };

            HttpResult<TodoList> result = await client.UpdateTodoListAsync(update, returnContent: true);

            Assert.IsNotNull(result, "Result is null");
            Assert.IsTrue(result.Succeeded, GetRequestFailedMessage(result));
            Assert.AreEqual(result.Content.Title, newTitle);
        }
 public Task<HttpResult<TodoList>> UpdateTodoListAsync(TodoList todoList, bool returnContent = false)
 {
     ThrowIfDisposed();
     return HttpClient.PatchAsync(GetTodoListUri(todoList.TodoListId), todoList, returnContent);
 }
 public Task<HttpResult<TodoList>> AddTodoListAsync(TodoList todoList)
 {
     ThrowIfDisposed();
     todoList.UserId = "TBD"; // UserId is required, but is not known at this point
     return HttpClient.PostAsJsonAsync<TodoList, TodoList>(TodoListsUri, todoList);
 }