コード例 #1
0
        public async Task <bool> UpdateTask(string listId, Models.Api.Task task)
        {
            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var                 json     = JsonConvert.SerializeObject(task);
                StringContent       content  = new StringContent(json, Encoding.UTF8, "application/json");
                HttpResponseMessage response = await client.PutAsync(ListsResource + $"/{listId}/tasks/{task.Id}", content);

                return(response.IsSuccessStatusCode);
            }
        }
コード例 #2
0
ファイル: TasksController.cs プロジェクト: msivers/AzureLists
        public async Task <ActionResult> Update(string listId, [Bind(Include = "Id,Title,DueDate,Notes,Important")] Models.Api.Task task)
        {
            if (ModelState.IsValid)
            {
                var result = await _listsService.UpdateTask(listId, task);

                if (result)
                {
                    return(RedirectToAction("Index", "Home", new { list = listId }));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
コード例 #3
0
ファイル: TasksController.cs プロジェクト: msivers/AzureLists
        public async Task <ActionResult> Create(string listId, [Bind(Include = "Title, Important")] Models.Api.Task task)
        {
            if (ModelState.IsValid)
            {
                var result = await _listsService.AddTaskToList(listId, task);

                if (result.success)
                {
                    return(RedirectToAction("Index", "Home", new { list = listId }));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
コード例 #4
0
        public async Task <Models.Api.Task> GetTask(string listId, string taskId)
        {
            Models.Api.Task tsk = null;

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage response = await client.GetAsync(ListsResource + $"/{listId}/tasks/{taskId}");

                if (response.IsSuccessStatusCode)
                {
                    var stringContent = await response.Content.ReadAsStringAsync();

                    tsk = JsonConvert.DeserializeObject <Models.Api.Task>(stringContent);
                }
            }
            return(tsk);
        }
コード例 #5
0
        public async Task <(bool success, string newTaskId)> AddTaskToList(string listId, Models.Api.Task task)
        {
            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var                 json     = JsonConvert.SerializeObject(task);
                StringContent       content  = new StringContent(json, Encoding.UTF8, "application/json");
                HttpResponseMessage response = await client.PostAsync(ListsResource + $"/{listId}/tasks", content);

                if (response.IsSuccessStatusCode)
                {
                    var responseString = await response.Content.ReadAsStringAsync();

                    var outputList = JsonConvert.DeserializeObject <Models.Api.Task>(responseString);
                    return(success : true, newTaskId : outputList.Id);
                }
                else
                {
                    return(success : false, newTaskId : "");
                }
            }
        }