Пример #1
0
        private async void ConfirmAcceptTaskAndPostAsync(object sender, RoutedEventArgs e)
        {
            UsersClient user = (UsersClient)this.AssingmentsBox.SelectedItem;

            if (user == null)
            {
                return;
            }

            var assignmentToPost = new AssignmentsClient()
            {
                TaskID = task.TaskID,
                UserID = user.UserID
            };

            RequestHandler client = new RequestHandler();
            await client.PostDataToAPI(assignmentToPost);

            if (PopupUsers.IsOpen)
            {
                PopupUsers.IsOpen = false;
            }

            this.Frame.Navigate(typeof(MainPage));

            if (!PopupConfirmation.IsOpen)
            {
                PopupConfirmation.IsOpen  = true;
                TaskConfirmTextBlock.Text = "The task " + task.Title + "\n" + "has been accepted by " + user.FirstName;
            }
        }
Пример #2
0
        public async Task PostDataToAPI(AssignmentsClient assignmentToPost)
        {
            using (var client = UWPHttpClient.GetRequest())
            {
                StringContent       content  = new StringContent(JsonConvert.SerializeObject(assignmentToPost), Encoding.UTF8, "application/json");
                HttpResponseMessage response = await client.PostAsync("api/Assignments", content);

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception((int)response.StatusCode + "-" + response.StatusCode.ToString());
                }
            }
        }