Пример #1
0
        private void SaveCommandHandler(Object sender, ExecutedRoutedEventArgs e)
        {
            if (commercial_nameTextBox.Text == "")
            {
                MessageBox.Show("El campo nombre comercial no puede estar vacio)");
                return;
            }
            try
            {
                using (Models.solutecEntities context = new Models.solutecEntities())
                {
                    Models.brands newBrand = new Models.brands();
                    newBrand.commercial_name = commercial_nameTextBox.Text;
                    newBrand.is_active       = true;
                    newBrand.nit             = nitTextBox.Text;
                    newBrand.nrc             = nrcTextBox.Text;
                    newBrand.start_date      = start_dateDatePicker.DisplayDate;
                    context.brands.Add(newBrand);
                    context.SaveChanges();
                    lblNotification.Content          = "Marca registrada correctamente";
                    notification.Visibility          = Visibility.Visible;
                    commercial_nameTextBox.IsEnabled = false;
                    nitTextBox.IsEnabled             = false;
                    nrcTextBox.IsEnabled             = false;
                    start_dateDatePicker.IsEnabled   = false;
                    btnSave.IsEnabled = false;

                    mainw.Succesful("brand");
                }
            }
            catch (DbEntityValidationException i)
            {
                foreach (var eve in i.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }
Пример #2
0
        private void SaveCommandHandler(Object sender, ExecutedRoutedEventArgs e)
        {
            if (userTextBox.Text == "" || password.Password == "")
            {
                MessageBox.Show("Los campos usuario y contraseña no deben estar vacios");
                return;
            }

            try
            {
                using (Models.solutecEntities context = new Models.solutecEntities())
                {
                    Models.users newUser = new Models.users();
                    newUser.user      = userTextBox.Text;
                    newUser.is_active = true;
                    newUser.password  = mainw.GetSHA1(password.Password);
                    short user_type = 0;
                    switch (user_typeComboBox.Text)
                    {
                    case "Administrador":
                        user_type = 1;

                        break;

                    case "Atencion al cliente":
                        user_type = 2;
                        break;

                    case "Tecnico":
                        user_type = 3;
                        break;

                    default:
                        user_type = 1;
                        break;
                    }
                    newUser.user_type = user_type;
                    context.users.Add(newUser);
                    context.SaveChanges();
                    lblNotification.Content     = "Usuario registrado correctamente";
                    notification.Visibility     = Visibility.Visible;
                    userTextBox.IsEnabled       = false;
                    password.IsEnabled          = false;
                    user_typeComboBox.IsEnabled = false;
                    btnSave.IsEnabled           = false;

                    mainw.Succesful("user");
                }
            }
            catch (DbEntityValidationException i)
            {
                foreach (var eve in i.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }