Exemple #1
0
 /// <summary>
 /// Check good for business rules for this supplier.
 /// </summary>
 /// <param name="good">Created good.</param>
 public void BusinessRulesCheck(CraftGood good)
 {
     // декодируем имя.
     good.Name = System.Net.WebUtility.HtmlDecode(good.Name);
 }
Exemple #2
0
        /// <summary>
        /// Prepare good.
        /// </summary>
        /// <param name="node">Htmlnode</param>
        /// <returns>Good.</returns>
        public CraftGood CreateAndFillCraftGood(HtmlNode node)
        {
            var good = new CraftGood(Id);
            try
            {
                good.CategoryUrl = CurrentCategoryUrl;
                // set name and goodurl.
                var nameNode = node.SelectSingleNode("div[@class='prdbrief_name']/a[@href]");
                if (nameNode != null && !String.IsNullOrWhiteSpace(nameNode.InnerText))
                {
                    good.Name = nameNode.InnerText.Trim();
                    if (!String.IsNullOrWhiteSpace(nameNode.Attributes["href"].Value))
                    {
                        var goodLinkValue = nameNode.Attributes["href"].Value;
                        good.GoodUrl = Utils.GetCorrectLink(Url, goodLinkValue);
                    }
                }

                // set picture url.
                var pictureNode =
                    node.SelectSingleNode("div[@class='prdbrief_thumbnail']/table/tr/td/div/a/div/img[@src]");
                if (pictureNode != null && pictureNode.Attributes.Contains("src") &&
                    pictureNode.Attributes["src"].Value != null)
                {
                    var pictureUrlValue = pictureNode.Attributes["src"].Value;
                    good.PictureUrl = Utils.GetCorrectLink(Url, pictureUrlValue);
                }

                // set article.
                var articleNode = node.SelectSingleNode("div[@class='prdbrief_name']/i");
                if (articleNode != null && !String.IsNullOrWhiteSpace(articleNode.InnerText))
                {
                    good.Article = articleNode.InnerText.Trim();
                }

                // set price and availability.
                var priceNode = node.SelectSingleNode("div[@class='prdbrief_price']/span[@class='totalPrice wod']");
                if (priceNode != null)
                {
                    // remove руб.
                    var priceText = priceNode.InnerText.Replace("руб.", "").Trim();
                    float price;
                    if (float.TryParse(priceText, out price))
                    {
                        good.Price = price;
                        if (!(good.Price > 0)) good.IsAvailable = false;
                    }
                    else good.IsAvailable = false;
                }
                else
                {
                    good.IsAvailable = false;
                }

                // check business rules.
                BusinessRulesCheck(good);
            }
            catch (Exception ex)
            {
                Log.LogError(ex);
            }

            return good;
        }
Exemple #3
0
 /// <summary>
 /// Check good for business rules for this supplier.
 /// </summary>
 /// <param name="good">Created good.</param>
 public void BusinessRulesCheck(CraftGood good)
 {
     // remove В НАЛИЧИИ
     if (good.Name.Contains(Constants.BusinessCheck.InOrder))
         good.Name = good.Name.Replace(Constants.BusinessCheck.InOrder, "").Trim();
 }