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; } } }
public bool AddPaidAccountDetail(PaidAccountDetail _paidAccountDetail) { using (var db = new KoontabiDBEntities()) { try { db.Database.BeginTransaction(); db.PaidAccountDetails.Add(_paidAccountDetail); var result = db.PaidAccounts.Find(_paidAccountDetail.PaidAccountID); result.AmountPending -= _paidAccountDetail.Payment; if (result.AmountPending == 0) { result.State = db.SP_GET_STATUS(2).FirstOrDefault().STATUS; result.DayDelay = 0; } db.SaveChanges(); db.Database.CurrentTransaction.Commit(); return(true); } catch (Exception) { db.Database.CurrentTransaction.Rollback(); throw; } } }
public void Update(Customer entity) { using (var db = new KoontabiDBEntities()) { db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); } }
public Invoice Add(Invoice entity) { using (var db = new KoontabiDBEntities()) { try { db.Database.BeginTransaction(); db.Invoices.Add(entity); if (entity.TypeOfPayID == 2) { decimal subtotal = 0; decimal discount = 0; decimal itbis = 0; foreach (var item in entity.InvoiceDetails) { subtotal += item.Quantity * item.UnitPrice; } if (entity.DisCount.HasValue) { discount = ((decimal)entity.DisCount.Value * 100) * subtotal / 100; } if (entity.TaxID.HasValue) { Tax t = db.Taxes.Find(entity.TaxID.Value); itbis = (t.TaxValue * subtotal) / 100; } subtotal -= discount; subtotal += itbis; PaidAccount p = new PaidAccount(); p.InvoiceID = entity.InvoiceID; p.DateEmit = entity.InvoiceDate; p.ExpirationDate = entity.ExpirationInvoiceDate; p.Amount = subtotal; p.AmountPending = subtotal; p.DayDelay = Convert.ToInt32((entity.InvoiceDate - entity.ExpirationInvoiceDate).TotalDays); p.State = db.SP_GET_STATUS(1).FirstOrDefault().STATUS; db.PaidAccounts.Add(p); } db.SaveChanges(); db.Database.CurrentTransaction.Commit(); return(new Invoice() { InvoiceID = entity.InvoiceID }); } catch (Exception) { db.Database.CurrentTransaction.Rollback(); throw; } } }
public Customer Add(Customer entity) { using (var db = new KoontabiDBEntities()) { db.Customers.Add(entity); db.SaveChanges(); return(entity); } }
public Product Add(Product entity) { using (var db = new KoontabiDBEntities()) { db.Products.Add(entity); db.SaveChanges(); return(entity); } }
public int AddKardex(Kardex _k) { using (var db = new KoontabiDBEntities()) { var tempKardexID = db.Kardexes.Add(_k).KardexID; db.SaveChanges(); return(tempKardexID); } }
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(); } }
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 Category Add(Category entity) { using (var db = new KoontabiDBEntities()) { try { db.Database.BeginTransaction(); db.Categories.Add(entity); db.SaveChanges(); db.Database.CurrentTransaction.Commit(); return(entity); } 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; } } }
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; } } }
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; } } }
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; } } }