public virtual void Delete(TEntity entityToDelete) { if (context.Entry(entityToDelete).State == EntityState.Detached) { dbSet.Attach(entityToDelete); } dbSet.Remove(entityToDelete); }
public virtual void Delete(List <TEntity> entityToDelete) { foreach (var entity in entityToDelete) { if (context.Entry(entity).State == EntityState.Detached) { dbSet.Attach(entity); } dbSet.Remove(entity); } }
public void Update(T entity) { using (var db = new ModelDb()) { db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); } }
public void Delete(Guid ProductID) { using (var db = new ModelDb()) { var Product = this.Find(ProductID); if (Product != null) { Product.ProductIsActive = false; db.Entry(Product).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } }
public void Delete(Guid CustomerID) { using (var db = new ModelDb()) { var Customer = this.Find(CustomerID); if (Customer != null) { Customer.CustomerIsActive = false; db.Entry(Customer).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } }
public void Edit(ProductEntity Product) { //Validando datos this.Validation(Product); using (var db = new ModelDb()) { //Se carga el producto var p = db.Products.Where(c => c.ProductID == Product.ProductID).FirstOrDefault(); //Se verifica que existe if (p != null) { //Validando Código var pExist = this.Find(Product.ProductCode); if (pExist != null) // Si existe, entra { if (pExist.ProductID != p.ProductID) { throw new Exception("Ya existe un producto con este Código"); } } //Se editan los datos p.ProductCode = Product.ProductCode; p.ProductName = Product.ProductName; p.ProductPrice = Product.ProductPrice; p.ProductDescription = Product.ProductDescription; p.MarkID = Product.MarkID; p.LineID = Product.LineID; //Se prepara para la edición db.Entry(p).State = System.Data.Entity.EntityState.Modified; //Se guardan los datos db.SaveChanges(); } } }