public Product CreateFromAPI(string barcode, int ApiID) { Product pr = new Product(); pr = webSearch.SearchByBarcode(barcode, 1); if (pr != null) { db.Product.Add(pr); db.SaveChanges(); return pr; } return null; }
public Product Create(Product product) { Product pr = FindRecordInDB(product.barcode); if (pr == null) { pr = product; } pr.Store.Add(setStore(product)); db.Product.Add(product); db.SaveChanges(); return Get(product.barcode); }
public Product Put(Product product) { Stores st = new Stores() { name = product.Store[0].name, latitude = product.Store[0].latitude, longitude = product.Store[0].longitude, storeLocation = product.Store[0].storeLocation }; return new Product().Update(product,st); }
public Product Post(Product product) { return new Product().Create(product); }
/* public IEnumerable<Stores> getStoresByProductId(int id) { return db.Store.Where(i => i.Product_id == id); }*/ public Product Update(Product product, Stores store) { Product p = Get(product.id); // db.Store.RemoveRange(getStoresByProductId(product.id)); db.Product.Remove(p); product.Store.Add(store); db.Product.Add(product); try { db.SaveChanges(); } catch (Exception ex) { string exe = ex.InnerException.ToString(); Console.WriteLine(exe); } return Get(product.id); }
public Stores setStore(Product product) { return new Stores() { productPrice = product.Store[0].productPrice, name = product.Store[0].name, latitude = product.Store[0].latitude, longitude = product.Store[0].longitude, storeLocation = product.Store[0].storeLocation }; }