public Adv24au Apply(Product product) { //var adv = product.Advs.First(a => a.Product.Id == product.Id && a.Marketplace.Id == this.Id); var adv = product.Advs.FirstOrDefault(a => a.Marketplace.Id == this.Id); bool save = false; if (adv == null) { var category = GetCategory(product); adv = new Adv24au(product, category, this); product.Advs.Add(adv); save = true; } if (!adv.Active) { adv.Active = true; save = true; } if (save) { Context.Save(); } return adv; }
public void Apply(Product product, BegemotProduct bproduct) { var needAdd = !product.SpecialStyle.Any(s => s.Id == Id); if (needAdd) { product.SpecialStyle.Add(this); } product.ReApplyStyle(); }
public Adv24au GetAdv(Product product) { var adv = product.Advs.FirstOrDefault(a => a.Marketplace.Id == this.Id); if (adv == null) { adv = Apply(product); } return adv; }
public Adv24au(Product product, AdvCategory category, Marketplace market) { Product = product; Category = category; Marketplace = market; Days = DeafaultDays; DateUpdate = DateTime.Now; DateExpire = DateTime.Now; Active = true; }
public static decimal CalcOldPrice(Product product, BegemotProduct begemotProduct, BegemotSalePrice sale) { decimal oldPrice; if (sale == null) { oldPrice = begemotProduct.RetailPrice * Context.OldPriceCoefficient; } else { oldPrice = sale.RetailPriceOld * Context.OldPriceCoefficient; } return oldPrice; }
public void Apply(Product product, BegemotProduct bproduct, BegemotSalePrice bsale) { var needAdd = !product.Sales.Any(s => s.Id == Id); if (needAdd) { product.Sales.Add(this); } product.RecalcPrice(bproduct, bsale); if (Style != null) { product.ReApplyStyle(); } }
public static decimal CalcPrice(Product product, BegemotProduct begemotProduct, BegemotSalePrice bsale, Sale sale) { decimal retPrice = CalcRetailPrice(begemotProduct, bsale); product.Price = retPrice; product.PriceOld = retPrice; if (sale != null) { decimal selfPrice = CalcSelfPrice(begemotProduct, bsale); retPrice = sale.CalcSalePrice(retPrice, selfPrice); product.Price = retPrice; } return retPrice; }
public static string GetCode(Product product) { var style = product.GetSpecialStyle(); var sale = product.GetActiveSale(); string prodCode = prefix; prodCode += string.Format("-p{0}", Encode(product.Id)); if (style != null) { if (!prodCode.IsEmpty()) prodCode += "-"; prodCode += style.GetCode(); } if (sale != null) { if (!prodCode.IsEmpty()) prodCode += "-"; prodCode += sale.GetCode(); } return prodCode; }
private void AddToDict(Product product, BegemotProduct bproduct, Style specialStyle, Sale activeSale) { valueDict.Add(StyleTag.Title, bproduct.GetClearTitle()); valueDict.Add(StyleTag.TitleShort, bproduct.GetTitleShort()); valueDict.Add(StyleTag.TitleClear, bproduct.GetClearTitle()); valueDict.Add(StyleTag.TitleClearShort, bproduct.GetClearShortTitle()); valueDict.Add(StyleTag.Description, bproduct.GetClearDescrption()); valueDict.Add(StyleTag.Price, product.Price.ToString("f2")); valueDict.Add(StyleTag.PriceOld, product.PriceOld.ToString("f2")); var codeProduct = product.GetCode(); valueDict.Add(StyleTag.CodeProduct, codeProduct); if (specialStyle != null) { var codeStyle = specialStyle.GetCode(true); //codeStyle = HttpUtility.UrlEncode(codeStyle); valueDict.Add(StyleTag.CodeStyle, codeStyle); } if (activeSale != null) { var codeSale = activeSale.GetCode(true); // codeSale = HttpUtility.UrlEncode(codeSale); valueDict.Add(StyleTag.CodeSale, codeSale); } var salesLinks = SalesLinks(); valueDict.Add(StyleTag.Sales, salesLinks); var menuLinks = MenuLinks(); valueDict.Add(StyleTag.Menu, menuLinks); }
public void ApplyStyles(Product product, BegemotProduct bproduct, Style specialStyle, Style saleStyle, Style marketStyle, Marketplace market, Adv24au adv) { //bool isNoStyles = specialStyle == null && saleStyle == null && marketStyle == null; var activeSale = product.GetActiveSale(); Style defultStyle = Style.GetDefault(); valueDict = new Dictionary<string, string>(); AddToDict(product, bproduct, specialStyle, activeSale); AppleResult ar = null; ar = Apply(defultStyle, StyleType.SpecialDescrition); ar = Apply(specialStyle, StyleType.SpecialDescrition); ar = Apply(saleStyle, StyleType.Sale); ar = Apply(marketStyle, StyleType.MarketPlace); ar.ClearTags(); //ar.ClearPolicyWords(market); var title = ar.GetResultTitle(); var description = ar.GetResultDescription(); if (adv == null) { product.Title = title; product.Description = description; } else { title = market.PrepareTitle(title); description = market.PrepareDescription(description); adv.Title = title; adv.Description = description; } }
public void ApplyStyles(Product product, BegemotProduct bproduct, Adv24au adv = null) { Marketplace market = adv.Marketplace; var specialStyle = product.GetSpecialStyle(); var saleStyle = product.GetSaleStyle(); var marketStyle = market == null ? null : market.GetActiveStyle(); ApplyStyles(product, bproduct, specialStyle, saleStyle, marketStyle, market, adv); }
public static Product FromBegemotProduct(BegemotProduct begemotProduct) { var product = new Product(); product.Article = begemotProduct.Article; product.Title = begemotProduct.GetClearTitle(); product.Description = begemotProduct.GetDescription(); product.Price = begemotProduct.RetailPrice; begemotProduct.GetImagePath(); product.Category = ProductCategory.FromBegemotProduct(begemotProduct); product.Active = true; return product; }
private static MarketCategory GetMarketCategory(Product product) { MarketCategory result; var style = product.GetSpecialStyle(); if (style == null) { result = MarketCategory.Default; } else { result = style.DefMarketCategoryObj; } return result; }
//private string RemovePolicyWords(string title) //{ // var policyWords = PolicyWords; // foreach (var policyWord in policyWords) // { // title = title.Replace(policyWord + " ", ""); // title = title.Replace(" " + policyWord, ""); // } // return title; //} //private string PrepareCamelCase(string title) //{ // var largeWords = title.Split(new[] { " ", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList(); // var sb = new StringBuilder(); // for (int i = 0; i < largeWords.Count; i++) // { // if (i > 0) sb.Append(" "); // var largeWord = largeWords[i]; // if (largeWord.Length > 5) // { // var substring = largeWord.Substring(0, 6); // bool manyApperCase = substring.ToUpper() == substring; // if (manyApperCase) // { // largeWord = ToCamelCase(largeWord); // } // } // // sb.Append(largeWord); // title = title.Replace(largeWords[i], largeWord); // } // string result; // //string result = sb.ToString(); // result = title; // return result; //} //private string ToCamelCase(string largeWord) //{ // string result = largeWord[0] + largeWord.Substring(1).ToLower(); // return result; //} //public string[] PolicyWords = { "в ассортименте", "в ассорт", @"regex\d+\s?шт", "гипермаркет", "супермаркет", "бегемот" }; public AdvCategory GetCategory(Product product) { var marketCategory = GetMarketCategory(product); var advCategory = GetAdvCategory(marketCategory); return advCategory; }