Example #1
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            CustomerInfo customerInfo = new CustomerInfo();

            customerInfo.CustomerID = this.customerID;
            customerInfo.Name       = CustomerNameTextBox.Text;
            customerInfo.Mobile     = CustomerMobileTextBox.Text;
            customerInfo.Address    = CustomerAddressTextBox.Text;

            if (IsValid())
            {
                if (this.IsUpdate)
                {
                    using (MyPOSContext db = new MyPOSContext())
                    {
                        db.Entry(customerInfo).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                        MessageBox.Show("Customer detail is updated succesfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ClearControls();
                    }
                }
                else
                {
                    using (MyPOSContext db = new MyPOSContext())
                    {
                        db.CustomerInfoes.Add(customerInfo);
                        db.SaveChanges();
                        MessageBox.Show("Customer detail is saved succesfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ClearControls();
                    }
                }
            }
        }
Example #2
0
 public void SalvarModificacoes(List <TEntity> objEntity)
 {
     using (MyPOSContext context = new MyPOSContext())
     {
         objEntity.ForEach(e => context.Entry(e).State = EntityState.Modified);
         context.SaveChanges();
     }
 }
Example #3
0
 public void SalvarModificacoes(TEntity objEntity)
 {
     using (MyPOSContext context = new MyPOSContext())
     {
         context.Entry(objEntity).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Example #4
0
 public void RemoverItem(TEntity objEntity)
 {
     using (MyPOSContext context = new MyPOSContext())
     {
         context.Entry(objEntity).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Example #5
0
 public void InserirNovo(TEntity objEntity)
 {
     using (MyPOSContext context = new MyPOSContext())
     {
         context.Set <TEntity>().Add(objEntity);
         context.Entry(objEntity).State = EntityState.Added;
         context.SaveChanges();
     }
 }
Example #6
0
        public void InsertOrUpdate(TEntity objEntity)
        {
            using (MyPOSContext context = new MyPOSContext())
            {
                var obj = Obter(objEntity);

                if (obj is null)
                {
                    context.Entry(objEntity).State = EntityState.Added;
                }
                else
                {
                    context.Entry(obj).State = EntityState.Modified;
                }

                context.SaveChanges();
            }
        }