public IQueryable<Product> GetProduct([QueryString("productID")] int? productId) { var _db = new CaliforniaPep.Models.ProductContext(); if (productId.HasValue && productId > 0) { IQueryable<Product> query1 = _db.Products.Where(en => en.ProductId == productId); return query1; } else { IQueryable<Product> query2 = _db.Products; return query2; } //var _db = new CaliforniaPep.Models.ProductContext(); //IQueryable<Product> query = _db.Products; //if (productId.HasValue && productId > 0) //{ // query = query.Where(p => p.ProductID == productId); //} //else //{ // query = null; //} //return query; }
public IQueryable<Category> GetCategories2([QueryString("ProductID")] int? productId) { var _db = new CaliforniaPep.Models.ProductContext(); if (productId == null) { return null; } else { IQueryable<Category> query = _db.ProductCategories.Where(en => en.ProductId == productId).Select( s => s.Category); return query; } }
public IQueryable<Product> GetProducts([QueryString("id")] int? categoryId) { var _db = new CaliforniaPep.Models.ProductContext(); if (categoryId.HasValue && categoryId > 0) { IQueryable<Product> query1 = _db.ProductCategories.Where(en => en.CategoryId == categoryId).Select(w => w.Product); return query1; } else { IQueryable<Product> query2 = _db.Products; return query2; } }
/////////////////////// public string InsertFromUrl(string b) { //StringReader strReader = new StringReader(myString); WebClient client = new WebClient(); string a = client.DownloadString(b); string ProductName = getBetween(a, "<div class=\"field field-title\"><h2>", "</h2></div></div><div class=\"nd-region-middle-wrapper").Trim(); //a.Substring(0, a.IndexOf(Environment.NewLine)).Trim(); string Sequence = getBetween(a, "Sequence: </div>", "</div>").Trim(); string strMolecularWeight = getBetween(a, "Molecular Weight: </div>", "</div>").Trim(); double MolecularWeight = 0.00; if (strMolecularWeight != "") { MolecularWeight = Convert.ToDouble(strMolecularWeight); } string CatalogNumber = getBetween(a, "Catalog Number: </div>", "</div>").Trim(); string Categories = "";//to return if (a.Contains("Categories")) { Categories = getBetween(a, "Categories</em>: </div><a href=\"", "Peptide Image").Trim(); } string strAmount = (getBetween(a, "<span class=\"field-content\">", "mg for").Trim()); double Amount = 0.00; if (strAmount != "") { Amount = Convert.ToDouble(strAmount); } string strUnitPrice = (getBetween(a, "mg for <span class=\"uc-price-product uc-price-sell_price uc-price\">", "</span></span>").Trim()); decimal UnitPrice = 0.00m; if (strUnitPrice != "") { UnitPrice = Convert.ToDecimal(strUnitPrice.TrimStart('$')); } //string strDescription = getBetween(a, "Peptide Image", "PURCHASE THIS PRODUCT").Trim(); using (ProductContext db = new ProductContext()) { var newProduct = new Product(); newProduct.ProductName = ProductName; newProduct.Sequence = Sequence; newProduct.MolecularWeight = MolecularWeight; newProduct.CatalogNumber = CatalogNumber; newProduct.Amount = Amount; newProduct.Unit = 0; newProduct.UnitPrice = UnitPrice; newProduct.ImagePath = "productimage.png"; newProduct.Description = ""; db.Products.Add(newProduct); if (Categories != "") { if (Categories.Contains("Alzheimer's"))//1 { var newProductcategory = new ProductCategory(); newProductcategory.ProductId = newProduct.ProductId; newProductcategory.CategoryId = 1; db.ProductCategories.Add(newProductcategory); //db.SaveChanges(); } if (Categories.Contains("Cardiovascular"))//2 { var newProductcategory = new ProductCategory(); newProductcategory.ProductId = newProduct.ProductId; newProductcategory.CategoryId = 2; db.ProductCategories.Add(newProductcategory); //db.SaveChanges(); } if (Categories.Contains("Caspase"))//3 { var newProductcategory = new ProductCategory(); newProductcategory.ProductId = newProduct.ProductId; newProductcategory.CategoryId = 3; db.ProductCategories.Add(newProductcategory); //db.SaveChanges(); } if (Categories.Contains("Central Nervous System"))//4 { var newProductcategory = new ProductCategory(); newProductcategory.ProductId = newProduct.ProductId; newProductcategory.CategoryId = 4; db.ProductCategories.Add(newProductcategory); //db.SaveChanges(); } if (Categories.Contains("Enzyme Substrates"))//5 { var newProductcategory = new ProductCategory(); newProductcategory.ProductId = newProduct.ProductId; newProductcategory.CategoryId = 5; db.ProductCategories.Add(newProductcategory); //db.SaveChanges(); } if (Categories.Contains("Gastrointestinal"))//6 { var newProductcategory = new ProductCategory(); newProductcategory.ProductId = newProduct.ProductId; newProductcategory.CategoryId = 6; db.ProductCategories.Add(newProductcategory); //db.SaveChanges(); } if (Categories.Contains("Metabolic / Diabetes"))//7 { var newProductcategory = new ProductCategory(); newProductcategory.ProductId = newProduct.ProductId; newProductcategory.CategoryId = 7; db.ProductCategories.Add(newProductcategory); //db.SaveChanges(); } if (Categories.Contains("Neuropeptides & Hormones"))//8 { var newProductcategory = new ProductCategory(); newProductcategory.ProductId = newProduct.ProductId; newProductcategory.CategoryId = 8; db.ProductCategories.Add(newProductcategory); //db.SaveChanges(); } if (Categories.Contains("Obesity"))//9 { var newProductcategory = new ProductCategory(); newProductcategory.ProductId = newProduct.ProductId; newProductcategory.CategoryId = 9; db.ProductCategories.Add(newProductcategory); //db.SaveChanges(); } if (Categories.Contains("Human"))//10 { var newProductcategory = new ProductCategory(); newProductcategory.ProductId = newProduct.ProductId; newProductcategory.CategoryId = 10; db.ProductCategories.Add(newProductcategory); //db.SaveChanges(); } if (Categories.Contains("Featured Products"))//11 { var newProductcategory = new ProductCategory(); newProductcategory.ProductId = newProduct.ProductId; newProductcategory.CategoryId = 11; db.ProductCategories.Add(newProductcategory); //db.SaveChanges(); } } try { db.SaveChanges(); return " Ok! " + ProductName + " for " + UnitPrice; } catch { return "Error!"; } } }
public IQueryable<Category> GetCategories() { var _db = new CaliforniaPep.Models.ProductContext(); IQueryable<Category> query = _db.Categories; return query; }