public IHttpActionResult PostProductStorage(string appToken, Product product) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var storage = db.ProductStorages.SingleOrDefault(_ => _.UserGroup.AppToken == appToken); if (storage == null && product != null) { return NotFound(); } storage.Products.Add(product); return Ok(); }
public static void SaveAllProductsToDb(IEnumerable<string> recipeLinks) { var productLinks = new List<string>(); recipeLinks.ForEach(recipelink => { var html = new HtmlDocument(); html.LoadHtml(GetHtmlString(recipelink)); var root = html.DocumentNode; var currentPageProductLinks = root.SelectNodes("/html/body/div/div/div/div/div/article/div/div/div/div/table/tbody/tr//*[@class=\"name\"]") .Select(_ => _.InnerText) .ToList(); productLinks = productLinks.Concat(currentPageProductLinks).ToList(); }); foreach (var productLink in productLinks.Distinct()) { var product = new Product { Name = productLink.Replace("«", "\"").Replace("»", "\"") }; Context.Products.Add(product); } Context.SaveChanges(); }