예제 #1
0
        /// <summary>
        ///     Updates the task.
        /// </summary>
        /// <param name="changedTask">The changed task.</param>
        /// <returns></returns>
        public async Task <bool> UpdateTask(Task changedTask)
        {
            var putBody  = JsonConvert.SerializeObject(changedTask);
            var response = await _client.PutAsync($"tasks\\{changedTask.TaskId}",
                                                  new StringContent(putBody, Encoding.UTF8, "application/json")).ConfigureAwait(false);

            return(response.IsSuccessStatusCode);
        }
예제 #2
0
        /// <summary>
        ///     Adds the task.
        /// </summary>
        /// <param name="newTask">The new task.</param>
        /// <returns></returns>
        /// <exception cref="WebException"></exception>
        /// <exception cref="InvalidDataException"></exception>
        public async Task <Task> AddTask(Task newTask)
        {
            var postBody = JsonConvert.SerializeObject(newTask);
            var response = await _client
                           .PostAsync("tasks", new StringContent(postBody, Encoding.UTF8, "application/json"))
                           .ConfigureAwait(false);

            if (!response.IsSuccessStatusCode)
            {
                if (!NetworkInterface.GetIsNetworkAvailable())
                {
                    throw new WebException();
                }
                throw new InvalidDataException();
            }

            var responseBody = await response.Content.ReadAsStringAsync();

            var createdTask = JsonConvert.DeserializeObject <Task>(responseBody);

            Users.Instance.SessionUser.Tasks.Add(createdTask);
            return(createdTask);
        }
예제 #3
0
        /// <summary>
        ///     Deletes the task.
        /// </summary>
        /// <param name="task">The task.</param>
        /// <returns></returns>
        public async Task <bool> DeleteTask(Task task)
        {
            var response = await _client.DeleteAsync($"tasks\\{task.TaskId}").ConfigureAwait(false);

            return(response.IsSuccessStatusCode || response.StatusCode == HttpStatusCode.NotFound);
        }