示例#1
0
        private void RegistButton_Clicked(object sender, RoutedEventArgs e)
        {
            try
            {
                if (VerificateFields())
                {
                    IndependientUserApi independientUserApi = new IndependientUserApi();
                    IndependientUser    independientUser    = new IndependientUser(name: NameTextBox.Text);
                    User  generalUser = new User(email: EmailTextBox.Text);
                    Media perfilImage = new Media();

                    generalUser.City     = CityTextBox.Text;
                    generalUser.Country  = CountryTextBox.Text;
                    generalUser.Password = Encrypt.GetSHA256(PasswordTextBox.Password);

                    if (myStream != null)
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            myStream.CopyTo(ms);
                            byte[] imageFile = ms.ToArray();
                            perfilImage.File         = imageFile;
                            generalUser.ProfilePhoto = perfilImage;
                        }
                    }

                    independientUser.Surnames            = LastNameTextBox.Text;
                    independientUser.Ocupation           = OcupationTextBox.Text;
                    independientUser.PersoanlDescription = GeneralDescripctionTextBox.Text;
                    independientUser.User = generalUser;

                    var response = independientUserApi.RegisterIndpendientUserWithHttpInfo(independientUser);
                    CustomMessageBox.ShowOK("El usuario ha sido registrado con éxito.", "Registro exitoso", "Aceptar");

                    string fullName   = independientUser.Name + " " + independientUser.Surnames;
                    var    mainWindow = (MainWindow)Application.Current.MainWindow;
                    mainWindow?.ChangeView(new ValidateUser(independientUser.User.Email, fullName));
                    return;
                }
            }
            catch (ApiException ex)
            {
                if (ex.ErrorCode == 401)
                {
                    CustomMessageBox.ShowOK("Ya existe un usuario con el correo " + EmailTextBox.Text, "Usuario existente", "Aceptar");
                }
                if (ex.ErrorCode == 500)
                {
                    CustomMessageBox.ShowOK("Ocurrió un error en la conexión con la base de datos. Por favor intentelo más tarde", "Error de conexión", "Aceptar");
                    Restarter.RestarEmployex();
                }
            }
        }
        private void UpdateButton_Clicked(object sender, RoutedEventArgs e)
        {
            try
            {
                if (VerificateFields())
                {
                    IndependientUserApi independientUserApi = new IndependientUserApi();

                    independientUser.Name         = NameTextBox.Text;
                    independientUser.User.City    = CityTextBox.Text;
                    independientUser.User.Country = CountryTextBox.Text;

                    if (myStream != null)
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            myStream.CopyTo(ms);
                            byte[] imageFile = ms.ToArray();
                            independientUser.User.ProfilePhoto.File = imageFile;
                        }
                    }

                    independientUser.Surnames            = LastNameTextBox.Text;
                    independientUser.Ocupation           = OcupationTextBox.Text;
                    independientUser.PersoanlDescription = GeneralDescripctionTextBox.Text;

                    independientUserApi.PatchIndependintUserById(independientUser, independientUser.User.Email);
                    CustomMessageBox.ShowOK("Los datos se han actualizado con éxito.", "Actualización exitosa", "Aceptar");
                    BackIcon_Clicked(new object(), new RoutedEventArgs());
                }
            }
            catch (ApiException ex)
            {
                if (ex.ErrorCode == 500)
                {
                    CustomMessageBox.ShowOK("Ocurrió un error en la conexión con la base de datos. Por favor intentelo más tarde", "Error de conexión", "Aceptar");
                    Restarter.RestarEmployex();
                }
            }
        }
        private void GetProfileInfo(string userID)
        {
            ProgressBar.Visibility         = Visibility.Visible;
            ProfileScrollViewer.Visibility = Visibility.Collapsed;

            IndependientUserApi independientUserApi = new IndependientUserApi();

            try
            {
                independientUser          = independientUserApi.GetIndependintUserById(userID);
                NameTextBlock.Text        = independientUser.Name + " " + independientUser.Surnames;
                OcupationTextBlock.Text   = independientUser.Ocupation;
                LocationTextBlock.Text    = independientUser.User.City + ", " + independientUser.User.Country;
                DescriptionTextBlock.Text = independientUser.PersoanlDescription;
                EmailTextBlock.Text       = independientUser.User.Email;
                if (independientUser.User.ProfilePhoto != null)
                {
                    ShowProfileImage(independientUser.User.ProfilePhoto.File);
                }
                ShowLaboralExperienceInfo(independientUser);
                ShowEducationInfo(independientUser);
                ShowCertifications(independientUser);
                ShowSections(independientUser);
            }
            catch (ApiException ex)
            {
                if (ex.ErrorCode.Equals(404))
                {
                    CustomMessageBox.Show("No hay más ofertas que mostrar");
                }
            }
            finally
            {
                ProfileScrollViewer.Visibility = Visibility.Visible;
                ProgressBar.Visibility         = Visibility.Collapsed;
            }
        }