Ejemplo n.º 1
0
        private async void buttonRegister_Click(object sender, EventArgs e)
        {
            labelRegisterErrors.Text  = String.Empty;
            pictureBoxLoading.Visible = true;

            var email    = textBoxEmail.Text;
            var password = textBoxPassword.Text;

            try
            {
                var response = await ServerConnectionLogic.RegisterUser(email, password);

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

                    var errorDto = JsonConvert.DeserializeObject <ValidationErrorDto>(responseString);

                    foreach (var errorsValue in errorDto.Errors.Values)
                    {
                        labelRegisterErrors.Text += errorsValue[0];
                    }
                }
                else
                {
                    MessageBox.Show("Konto zostało poprawnie utworzone!", "Konto utworzone", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Close();
                }
            }
            catch (Exception)
            {
                labelRegisterErrors.Text = "Błąd podczas łączenia z serwerem!";
            }

            pictureBoxLoading.Visible = false;
        }