Example #1
0
        private async Task PopulateUserList()
        {
            Invoke(new Action(listBoxUsers.Items.Clear));
            var userList = await ServerConnectionLogic.GetUserList(_token);

            foreach (var userDto in userList)
            {
                if (!userDto.Email.Equals(_userEmail))
                {
                    Invoke(new Func <UserDto, int>(listBoxUsers.Items.Add), userDto);
                }
            }
        }
Example #2
0
        private async void buttonLogin_Click(object sender, EventArgs e)
        {
            labelLoginErrors.Text = String.Empty;
            ChangeControlsStatus(false);


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

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

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

                if (!response.IsSuccessStatusCode)
                {
                    var errorDto = JsonConvert.DeserializeObject <ValidationErrorDto>(responseString);

                    foreach (var errorsValue in errorDto.Errors.Values)
                    {
                        labelLoginErrors.Text += errorsValue[0];
                    }
                }
                else
                {
                    AuthData = JsonConvert.DeserializeObject <AuthData>(responseString);
                    using (var fileStream = new FileStream(_filePath, FileMode.Create))
                        using (var streamWriter = new StreamWriter(fileStream))
                        {
                            await streamWriter.WriteAsync(responseString);
                        }
                    Close();
                }
            }
            catch (Exception)
            {
                labelLoginErrors.Text = "Błąd podczas łączenia z serwerem!";
            }

            ChangeControlsStatus(true);
        }
        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;
        }