Beispiel #1
0
        public async Task UpdateProducts([FromBody] RemoveProductLog logData)
        {
            try
            {
                var productIds     = logData.ProductData.Select(c => c.ProductId);
                var productAddress = new Uri(logData.PageAddress).PathAndQuery;
                var host           = await _hostDictionary.GetHostByIdAsync(logData.HostId);

                if (host == null || host.Id == 0)
                {
                    return;
                }
                #region SecurityCheck
                if (_configurations.SecurityCheck)
                {
                    var origin = Request.Headers[CommonStrings.Origin].ToString();
                    if (!string.IsNullOrEmpty(origin))
                    {
                        var aut = new Uri(origin).Host;
                        aut = aut.ToLower();
                        var topdomain = string.Empty;
                        if (aut.IndexOf(CommonStrings.Dot) == aut.LastIndexOf(CommonStrings.Dot))
                        {
                            topdomain = aut;
                        }
                        else
                        {
                            topdomain = aut.Substring(aut.IndexOf(CommonStrings.Dot) + 1);
                        }
                        if (host.Host != topdomain)
                        {
                            return;
                        }
                    }
                }
                #endregion
                await _hostScriptChecker.UpdateBuyValidation(logData.HostId);

                foreach (var item in productIds)
                {
                    var cachedProduct = await _productCache.FindProduct(logData.HostId, item);

                    if (cachedProduct.Id != string.Empty)
                    {
                        await _kafkaLogger.SendMessage(new DruidData()
                        {
                            CategoryName = cachedProduct.CategoryName,
                            Date         = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:sszzz"),
                            HostName     = host.Host,
                            ImageAddress = cachedProduct.ImageAddress,
                            Price        = cachedProduct.Price,
                            ProductName  = cachedProduct.ProductName,
                            PageAddress  = cachedProduct.Url,
                            ProductId    = item,
                            StatType     = StatTypes.ProductPurchase,
                            UserId       = logData.UserId.ToString(),
                            HostId       = logData.HostId.ToString(),
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                await _errorLogger.LogError("Operation:Buy =>" + ex.Message);
            }
        }
Beispiel #2
0
        public async Task <string> UpdateProducts([FromBody] AddToCartLog logData)
        {
            try
            {
                var host = await _hostCache.GetHostByIdAsync(logData.HostId);

                if (host == null || host.Id == 0)
                {
                    return(CommonStrings.NoHost);
                }
                #region SecurityCheck
                if (_configurations.SecurityCheck)
                {
                    var origin = Request.Headers[CommonStrings.Origin].ToString();
                    if (!string.IsNullOrEmpty(origin))
                    {
                        var aut = new Uri(origin).Host;
                        aut = aut.ToLower();
                        var topdomain = string.Empty;
                        if (aut.IndexOf(CommonStrings.Dot) == aut.LastIndexOf(CommonStrings.Dot))
                        {
                            topdomain = aut;
                        }
                        else
                        {
                            topdomain = aut.Substring(aut.IndexOf(CommonStrings.Dot) + 1);
                        }
                        if (host.Host != topdomain)
                        {
                            return(CommonStrings.NoHostAccess);
                        }
                    }
                }
                #endregion

                var productad = logData.ProductData.OrderByDescending(c => c.ProductId).ToList();
                if (!productad.Any())
                {
                    return(string.Empty);
                }
                await _hostScriptChecker.UpdateCartValidation(logData.HostId);

                await _totalVisitUpdater.UpdateTotalVisit(logData.HostId);

                foreach (var item in productad)
                {
                    var cachedProduct = await _productCache.FindProduct(logData.HostId, item.ProductId);

                    if (cachedProduct.Id != string.Empty)
                    {
                        await _kafkaLogger.SendMessage(new DruidData()
                        {
                            CategoryName = cachedProduct.CategoryName,
                            Date         = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:sszzz"),
                            HostName     = host.Host,
                            ImageAddress = cachedProduct.ImageAddress,
                            Price        = cachedProduct.Price,
                            ProductName  = cachedProduct.ProductName,
                            PageAddress  = cachedProduct.Url,
                            ProductId    = item.ProductId,
                            StatType     = StatTypes.AddToCart,
                            UserId       = logData.UserId.ToString(),
                            HostId       = logData.HostId.ToString(),
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                await _errorLogger.LogError("Operations:AdToCart->" + ex.Message);
            }



            return("");
        }