Ejemplo n.º 1
0
        private async void buttonUpload_Click(object sender, EventArgs e)
        {
            if (
                FormImageUploadValidator.ValidRequiredTextBoxFields(errorProvider, textBoxRequestNumber, textBoxUserName) &&
                FormImageUploadValidator.ValidateFileInputField(errorProvider, openFileDialog, buttonAddFile) &&
                FormImageUploadValidator.ValidateRequestNumber(errorProvider, textBoxRequestNumber)
                )
            {
                disableAllButtons();

                var response = await HTTPUtility.PostData(
                    ConfigurationManager.AppSettings["SurityRestAPIBaseURL"] + ConfigurationManager.AppSettings["ImageUploadEndpoint"],
                    new
                {
                    RequestNumber = textBoxRequestNumber.Text,
                    UserName      = textBoxUserName.Text,
                    ImageName     = openFileDialog.SafeFileName,
                    ImageData     = File.ReadAllBytes(openFileDialog.FileName)
                }
                    );

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    errorProvider.SetError(buttonUpload, string.Empty);
                    showUploadSuccessText();
                }
                else
                {
                    errorProvider.SetError(buttonUpload, await response.Content.ReadAsStringAsync());
                    labelUploadSuccess.Text = string.Empty;
                }

                enableAllButtons();
            }
        }