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();
        }
예제 #2
0
        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("&#171;", "\"").Replace("&#187;", "\"")
                };

                Context.Products.Add(product);
            }

            Context.SaveChanges();
        }