public bool NewProduct(Product p, int categoryid) { using (TiendaTestEntities ent = new TiendaTestEntities()) { Product pp = (from pr in ent.Product where pr.Producto == p.Producto select pr).SingleOrDefault(); if (pp == null) { pp = new Product(); pp.Producto = p.Producto; pp.Precio = p.Precio; Category ct = (from c in ent.Category where c.Id == categoryid select c).SingleOrDefault(); pp.Category.Add(ct); ent.AddToProduct(pp); ent.SaveChanges(); return(true); } else { return(false); } } }
public List <Product> GetProduct() { using (TiendaTestEntities ent = new TiendaTestEntities()) { List <Product> p = (from pr in ent.Product select pr).ToList(); return(p); } }