Beispiel #1
0
 public void Update(Product entity)
 {
     using (var db = new KoontabiDBEntities())
     {
         db.Entry(entity).State = System.Data.Entity.EntityState.Modified;
         foreach (var item in entity.ProductDetails)
         {
             db.Entry(item).State = EntityState.Modified;
         }
         db.SaveChanges();
     }
 }
Beispiel #2
0
 public void Delete(int idEntity)
 {
     using (var db = new KoontabiDBEntities()) {
         try
         {
             db.Database.BeginTransaction();
             var currentObj = db.Categories.Find(idEntity);
             if (currentObj != null)
             {
                 db.Entry(currentObj).State = System.Data.Entity.EntityState.Deleted;
                 db.SaveChanges();
             }
             else
             {
                 throw new Exception("No existe categoria");
             }
             db.Database.CurrentTransaction.Commit();
         }
         catch (Exception)
         {
             db.Database.CurrentTransaction.Rollback();
             throw;
         }
     }
 }
Beispiel #3
0
 public void Update(Customer entity)
 {
     using (var db = new KoontabiDBEntities())
     {
         db.Entry(entity).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
        public void Update(Invoice invoice, ICollection <InvoiceDetail> collectionToAddNew)
        {
            using (var db = new KoontabiDBEntities())
            {
                try
                {
                    db.Database.BeginTransaction();
                    var objectContext = ((IObjectContextAdapter)db).ObjectContext;
                    db.Entry(invoice).State = System.Data.Entity.EntityState.Unchanged;
                    //Delete al details and kardex from collectionToDelete
                    foreach (var item in invoice.InvoiceDetails.ToList())
                    {
                        /*
                         *  Eliminando la linea del Kardex y
                         *  el detalle de la factura
                         *
                         * Nota:
                         */

                        objectContext.DeleteObject(item.Kardex);
                        objectContext.DeleteObject(item);
                    }

                    foreach (var itemToAdd in collectionToAddNew)
                    {
                        invoice.InvoiceDetails.Add(itemToAdd);
                    }

                    db.Entry(invoice).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    db.Database.CurrentTransaction.Commit();
                }
                catch (Exception)
                {
                    db.Database.CurrentTransaction.Rollback();
                    throw;
                }
            }
        }
Beispiel #5
0
 public void Update(Category entity)
 {
     try
     {
         using (var db = new KoontabiDBEntities()) {
             db.Entry(entity).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
 public void Update(Unit entity)
 {
     using (var db = new KoontabiDBEntities())
     {
         try
         {
             db.Database.BeginTransaction();
             db.Entry(entity).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
             db.Database.CurrentTransaction.Commit();
         }
         catch (Exception)
         {
             db.Database.CurrentTransaction.Rollback();
             throw;
         }
     }
 }
 public void Delete(int idEntity)
 {
     using (var db = new KoontabiDBEntities())
     {
         try
         {
             db.Database.BeginTransaction();
             var objTemp = db.Units.Find(idEntity);
             db.Entry(objTemp).State = System.Data.Entity.EntityState.Deleted;
             db.SaveChanges();
             db.Database.CurrentTransaction.Commit();
         }
         catch (Exception)
         {
             db.Database.CurrentTransaction.Rollback();
             throw;
         }
     }
 }
Beispiel #8
0
        public void Delete(int idEntity)
        {
            using (var db = new KoontabiDBEntities())
            {
                try
                {
                    var tempCustomer = db.Customers.Find(idEntity);

                    if (tempCustomer.Invoices.Count > 0)
                    {
                        throw new Exception("No puede eliminar este cliente.");
                    }
                    db.Entry(tempCustomer).State = EntityState.Deleted;
                    //tempCustomer.State = CustomerState.ELIMINADO;
                    db.SaveChanges();
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Beispiel #9
0
 public void UpdateStockByProductIDAndBodegaID(int stock, int productID, int bodegaID)
 {
     using (var db = new KoontabiDBEntities())
     {
         try
         {
             db.Database.BeginTransaction();
             var productTemp = (from pd in db.ProductDetails
                                where pd.ProductID == productID
                                where pd.BodegaID == bodegaID
                                select pd).FirstOrDefault();
             productTemp.Stock           = stock;
             db.Entry(productTemp).State = EntityState.Modified;
             db.SaveChanges();
             db.Database.CurrentTransaction.Commit();
         }
         catch (Exception)
         {
             db.Database.CurrentTransaction.Rollback();
             throw;
         }
     }
 }