예제 #1
0
        public async System.Threading.Tasks.Task UpdateSelectedCategory(int id)
        {
            var        CategoryIdJson = JsonConvert.SerializeObject(id);
            HttpClient httpClient     = new HttpClient();
            var        url            = $"http://localhost:5001/api/Category/{id}";
            var        res            = await httpClient.PutAsync(new Uri(url), new HttpStringContent(CategoryIdJson, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/json"));

            if (res.IsSuccessStatusCode)
            {
                Category category = Categories.FirstOrDefault(t => t.Id == id);
                //task.DoneTask = !task.DoneTask;
            }
        }
예제 #2
0
        public static async Task <bool> UpdateQuiz(Quiz quiz)
        {
            //Updates quiz
            Uri    quizUri = new Uri(quizzesBaseUri + quiz.QuizId.ToString(CultureInfo.InvariantCulture));
            string json;

            json = JsonConvert.SerializeObject(quiz, Formatting.None,
                                               new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });
            var httpContent = new HttpStringContent(json, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/json");
            var result      = await httpClient.PutAsync(quizUri, httpContent);

            return(result.IsSuccessStatusCode);
        }
예제 #3
0
        public virtual async Task <string> put(Uri link, IHttpContent content)
        {
            var cts = new CancellationTokenSource();

            cts.CancelAfter(1000);
            try
            {
                var response = await client.PutAsync(link, content);

                if (response == null || !response.IsSuccessStatusCode)
                {
                    return(null);
                }
                string jsonResponse = await response.Content.ReadAsStringAsync();

                return(jsonResponse);
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception);
                return(null);
            }
        }
예제 #4
0
        public async System.Threading.Tasks.Task UpdateItem(string itemName)
        {
            var  itemId = 0;
            Item item   = null;

            foreach (Category cat in Categories)
            {
                if (cat.Items.FirstOrDefault(i => i.Name.Equals(itemName)) != null)
                {
                    item   = cat.Items.FirstOrDefault(i => i.Name.Equals(itemName));
                    itemId = item.Id;
                }
            }
            var        itemIdJson = JsonConvert.SerializeObject(itemId);
            HttpClient httpClient = new HttpClient();
            var        url        = $"http://localhost:5001/api/Category/UpdateItem/{itemId}";
            var        res        = await httpClient.PutAsync(new Uri(url), new HttpStringContent(itemIdJson, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/json"));

            if (res.IsSuccessStatusCode)
            {
                item.DoneItem = !item.DoneItem;
            }
        }
예제 #5
0
        public async Task Upload_FileAsync()
        {
            //init_apartment();

            /*Windows.Storage.Streams.IBuffer buffer =
             *  Windows.Security.Cryptography.CryptographicBuffer.ConvertStringToBinary(
             *      "A sentence of text to encode into binary to serve as sample data.",
             *      Windows.Security.Cryptography.BinaryStringEncoding.Utf8
             *  );
             * Windows.Web.Http.HttpBufferContent binaryContent = new HttpBufferContent(buffer);*/
            // You can use the 'image/jpeg' content type to represent any binary data;
            // it's not necessarily an image file.
            fileOpenPicker.FileTypeFilter.Add(".json");
            IStorageFile jsonFile = await fileOpenPicker.PickSingleFileAsync();

            IRandomAccessStream stream = await jsonFile.OpenAsync(FileAccessMode.Read);

            Windows.Web.Http.HttpStreamContent jsonContent = new HttpStreamContent(stream);

            jsonContent.Headers.Append("Content-Type", "application/json");

            Windows.Web.Http.Headers.HttpContentDispositionHeaderValue disposition = new Windows.Web.Http.Headers.HttpContentDispositionHeaderValue(/*"form-data"*/ "render");
            jsonContent.Headers.ContentDisposition = disposition;
            // The 'name' directive contains the name of the form field representing the data.
            disposition.Name = "fileForUpload";
            // Here, the 'filename' directive is used to indicate to the server a file name
            // to use to save the uploaded data.
            disposition.FileName = "testSurveyFile.json";

            Windows.Web.Http.HttpMultipartFormDataContent postContent = new HttpMultipartFormDataContent();
            postContent.Add(jsonContent); // Add the binary data content as a part of the form data content.

            // Send the POST request asynchronously, and retrieve the response as a string.
            Windows.Web.Http.HttpResponseMessage httpResponseMessage;
            string httpResponseBody;

            try
            {
                /*Uri requestUri = new Uri("https://prodigalcompany.com/npjTest/SurveyStuff");
                 *
                 * Windows.Web.Http.Filters.HttpBaseProtocolFilter clientFilter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
                 * clientFilter.AllowAutoRedirect = false;
                 *
                 * Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient(clientFilter);
                 * httpResponseMessage = await httpClient.PutAsync(requestUri, postContent);
                 *
                 * requestUri = httpResponseMessage.Headers.Location;
                 * httpResponseMessage = await httpClient.PutAsync(requestUri, postContent);*/


                // Send the POST request.

                Uri requestUri = new Uri("https://prodigalcompany.com/npjTest/SurveyStuff/testSurveyFile.json");

                Windows.Security.Cryptography.Certificates.CertificateQuery certQuery = new Windows.Security.Cryptography.Certificates.CertificateQuery();
                certQuery.FriendlyName = "Test Certificate";    // This is the friendly name of the certificate that was just installed.
                IReadOnlyList <Windows.Security.Cryptography.Certificates.Certificate> certificates = await Windows.Security.Cryptography.Certificates.CertificateStores.FindAllAsync(certQuery);

                // TODO here you can display the certificates in the UI to make the User select.

                Debug.WriteLine("Cert? = " + certificates.Count);

                Windows.Web.Http.Filters.HttpBaseProtocolFilter filter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
                filter.ServerCredential = new Windows.Security.Credentials.PasswordCredential(
                    "prodigalcompany.com",
                    "*****@*****.**",
                    "Pr0digal1!");
                filter.AllowAutoRedirect = false;
                //filter.ClientCertificate = certificates[0];

                Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient(filter);
                httpResponseMessage = await httpClient.PutAsync(requestUri, postContent);

                httpResponseMessage.EnsureSuccessStatusCode();

                httpResponseBody = await httpResponseMessage.Content.ReadAsStringAsync();

                Debug.WriteLine(httpResponseBody);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }