Exemplo n.º 1
0
        private void Actualizar()
        {
            int id = Convert.ToInt32(txtCustomerId.Text);

            using (AdventureEntities context = new AdventureEntities()) {
                Customer oCliente = context.Customer.SingleOrDefault(p => p.CustomerID == id);

                //MessageBox.Show(oCliente.LastName);

                oCliente.NameStyle    = ckbNameStyle.Checked;
                oCliente.Title        = txtTitle.Text;
                oCliente.FirstName    = txtFirstName.Text;
                oCliente.MiddleName   = txtMiddleName.Text;
                oCliente.LastName     = txtLastName.Text;
                oCliente.Suffix       = txtSuflix.Text;
                oCliente.CompanyName  = txtCompany.Text;
                oCliente.SalesPerson  = txtSalePerson.Text;
                oCliente.EmailAddress = txtEmail.Text;
                oCliente.Phone        = txtPhone.Text;
                oCliente.PasswordHash = txtPassHash.Text;
                oCliente.PasswordSalt = txtPassSalt.Text;

                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        private void Insertar()
        {
            try
            {
                using (AdventureEntities context = new AdventureEntities()) {
                    Customer oCliente = new Customer
                    {
                        NameStyle    = ckbNameStyle.Checked,
                        Title        = txtTitle.Text,
                        FirstName    = txtFirstName.Text,
                        MiddleName   = txtMiddleName.Text,
                        LastName     = txtLastName.Text,
                        Suffix       = txtSuflix.Text,
                        CompanyName  = txtCompany.Text,
                        SalesPerson  = txtSalePerson.Text,
                        EmailAddress = txtEmail.Text,
                        Phone        = txtPhone.Text,
                        PasswordHash = txtPassHash.Text,
                        PasswordSalt = txtPassSalt.Text,
                        ModifiedDate = DateTime.Now
                    };

                    context.Customer.Add(oCliente);
                    context.SaveChanges();
                }
            }
            catch (DbEntityValidationException ex) {
                foreach (var validationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        MessageBox.Show(string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally {
                CargarGrid();
            }
        }
Exemplo n.º 3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(txtCustomerId.Text);

            using (AdventureEntities context = new AdventureEntities())
            {
                //Ejemplo 1:
                //Customer oCliente = context.Customer.SingleOrDefault(p => p.CustomerID == id);

                //Ejemplo 2:
                Customer oCliente = (from q in context.Customer
                                     where q.CustomerID == id
                                     select q).First();

                try {
                    context.Customer.Remove(oCliente);
                    context.SaveChanges();

                    CargarGrid();
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            }
        }