public List <Product_table2> buildlistwcf(int listlen) { StoreClient wcf = new StoreClient(); int getbyid = 1; List <Product_table2> list = new List <Product_table2>(); Product_table2 product_Table2; do { try { bazzasbazaar.Product product = wcf.GetProductById(getbyid); product_Table2 = new Product_table2() { ID = product.Id + listlen, BrandId = 0, BrandName = "No Brand", CategoryId = product.CategoryId, CategoryName = product.CategoryName, Product_Description = product.Description, Ean = product.Ean, ExpectedRestock = true, Original_Price = product.PriceForOne, Price = product.PriceForOne, Product_Name = product.Name }; list.Add(product_Table2); getbyid++; } catch (Exception e) { if (e is NullReferenceException) { Console.WriteLine("End of WCF Service Reached"); break; } else { Console.WriteLine("An error occured while creating the list"); wcf.Close(); return(null); } } } while (true); wcf.Close(); return(list); }
public List <Product_table2> buildList(string json, int listlen) { List <Product_table2> list = new List <Product_table2>(); var result2 = JsonConvert.DeserializeObject <List <Product> >(json); try { foreach (Product x in result2) { Product_table2 prod = new Product_table2() { ID = x.ID + listlen, Product_Name = x.Name, Product_Description = x.Description, Price = x.Price, Original_Price = x.Price, Ean = x.Ean, CategoryId = x.CategoryId, CategoryName = x.CategoryName, BrandId = x.BrandId, BrandName = x.BrandName, }; if (x.ExpectedRestock.Equals("")) { prod.ExpectedRestock = true; } else { prod.ExpectedRestock = false; } list.Add(prod); } return(list); } catch (Exception) { Console.WriteLine("An error occured while creating list"); return(null); } }
public string ShowProduct(Product_table2 prod) { Console.WriteLine(); return("Product ID: " + prod.ID + "Product name: " + prod.Product_Name + " Product Desc: " + prod.Product_Description + " Product price " + prod.Price); }
public void insertProduct(Product_table2 product) { context.Product_table2.Add(product); context.SaveChanges(); }