コード例 #1
0
    public bool UpdateProductRank()
    {
        try
        {
            //string TokenJSON = GetTokenJSON(26);//"{\"brucewl1964\": 62, \"williamgerardit\": 64}";
            int pageSize = 20;
            DateTime today = System.DateTime.Today;
            DataModelEntities context = new DataModelEntities();
            var sellerItems = context.SellerItems.Where(w => w.Is_Active == true && w.Is_Automated == true && w.Is_Promo_Item == false && w.End_Date > today)
                                                 .AsEnumerable()
                                                 .Select(a => new
                                                 {
                                                        a.Algo,
                                                        a.BIN_Price,
                                                        a.Ceiling_Price,
                                                        a.Current_Price,
                                                        a.End_Date,
                                                        a.Floor_Price,
                                                        a.Item_Code,
                                                        a.Item_ID,
                                                        a.Item_Name,
                                                        a.Item_SKU,
                                                        a.Start_Date,
                                                        a.Keywords,
                                                        a.Is_Automated,
                                                        a.User_Code,
                                                        Algo_Name = Common.GetAlgoName(a.Algo),
                                                        a.Minimum_Feedback,
                                                        a.Maximum_Feedback,
                                                        a.Minimum_Price,
                                                        a.Maximum_Price,
                                                        a.Minimum_Quantity,
                                                        a.Maximum_Quantity,
                                                        a.Inclued_Sellers,
                                                        a.Exclude_Sellers,
                                                        a.Maximum_Handling_Time,
                                                        a.Is_Fixed_Price,
                                                        a.Is_Auctions,
                                                        a.Is_Returns_Accepted,
                                                        a.Is_Location_AU,
                                                        a.Is_Hide_Duplicates,
                                                        a.Is_Top_Rated_Only,
                                                        a.Exclude_Category_Codes,
                                                        a.Include_Condtion_Codes,
                                                        a.Item_Category_ID,
                                                        a.Item_Category_Name,
                                                        a.Less_To_Lowest_Price,
                                                        a.Item_Rank,
                                                        a.Ignore_Words,
                                                        a.Is_Round_To_Nearest,
                                                        a.Country_Code,
                                                        a.LocatedIn

                                                 }).ToList();

            if (sellerItems.Count > 0)
            {
                foreach (var sellerItem in sellerItems)
                {
                    try
                    {
                        string TokenJSON = GetTokenJSON((int)sellerItem.User_Code);
                        GeneralSvc genSvc = new GeneralSvc();
                        string filterJSON = Common.Serialize(sellerItem);
                        string response = genSvc.GetProductRank(filterJSON, pageSize, TokenJSON, sellerItem.User_Code);
                        if (!string.IsNullOrEmpty(response))
                        {
                            List<EbaySearchItem> searchItems = (List<EbaySearchItem>)Common.Deserialize(response, typeof(List<EbaySearchItem>));
                            string ItemID = sellerItem.Item_ID;
                            EbaySearchItem myItem = searchItems.FirstOrDefault(f => f.ItemID == ItemID);
                            if (myItem != null)
                            {

                                int rank = searchItems.IndexOf(myItem);
                                SellerItem si = context.SellerItems.First(f => f.Item_Code == sellerItem.Item_Code);
                                si.Item_Rank = rank + 1;
                            }
                            else
                            {
                                SellerItem si = context.SellerItems.First(f => f.Item_Code == sellerItem.Item_Code);
                                si.Item_Rank = null;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.WriteLog(LogType.Error, ex.ToString());
                    }
                }
                context.SaveChanges();
            }
            return true;
        }
        catch (Exception ex)
        {
            Logging.WriteLog(LogType.Error, ex.ToString());
            return false;
        }
    }
コード例 #2
0
    public bool UpdateProductPrice(int timeDelay)
    {
        try
        {
            int pageSize = 20;
            DateTime today = System.DateTime.Today;
            DataModelEntities context = new DataModelEntities();
            var sellerItems = context.SellerItems.Where(w => w.User.Is_Active == true && w.User.Is_Locked != true && w.User.Is_Verified == true && ((timeDelay == (int)Constant.PriceAutomationTimeDelay.Hrs12 && (w.User.Automation_Time_Delay == null || w.User.Automation_Time_Delay == (int)Constant.PriceAutomationTimeDelay.NotSpecified)) || (w.User.Automation_Time_Delay == timeDelay)) && w.Is_Active == true && w.Is_Automated == true && w.Is_Promo_Item != true && w.End_Date > today)
                                                 .AsEnumerable()
                                                 .Select(a => new
                                                 {
                                                     a.Algo,
                                                     a.BIN_Price,
                                                     a.Ceiling_Price,
                                                     a.Current_Price,
                                                     a.End_Date,
                                                     a.Floor_Price,
                                                     a.Item_Code,
                                                     a.Item_ID,
                                                     a.Item_Name,
                                                     a.Item_SKU,
                                                     a.Start_Date,
                                                     a.Keywords,
                                                     a.Is_Automated,
                                                     a.User_Code,
                                                     a.User_Account_Code,
                                                     Algo_Name = Common.GetAlgoName(a.Algo),
                                                     a.Minimum_Feedback,
                                                     a.Maximum_Feedback,
                                                     a.Minimum_Price,
                                                     a.Maximum_Price,
                                                     a.Minimum_Quantity,
                                                     a.Maximum_Quantity,
                                                     a.Inclued_Sellers,
                                                     a.Exclude_Sellers,
                                                     a.Maximum_Handling_Time,
                                                     a.Is_Fixed_Price,
                                                     a.Is_Auctions,
                                                     a.Is_Returns_Accepted,
                                                     a.Is_Location_AU,
                                                     a.Is_Hide_Duplicates,
                                                     a.Is_Top_Rated_Only,
                                                     a.Exclude_Category_Codes,
                                                     a.Include_Condtion_Codes,
                                                     a.Item_Category_ID,
                                                     a.Item_Category_Name,
                                                     a.Less_To_Lowest_Price,
                                                     a.Item_Rank,
                                                     a.Ignore_Words,
                                                     a.Is_Round_To_Nearest,
                                                     a.Country_Code,
                                                     a.LocatedIn
                                                 }).ToList();

            if (sellerItems.Count > 0)
            {
                foreach (var sellerItem in sellerItems)
                {
                    try
                    {
                        string TokenJSON = GetTokenJSON((int)sellerItem.User_Code);
                        GeneralSvc genSvc = new GeneralSvc();
                        string filterJSON = Common.Serialize(sellerItem);
                        string response = genSvc.GetProductRank(filterJSON, pageSize, TokenJSON, sellerItem.User_Code);
                        if (!string.IsNullOrEmpty(response))
                        {
                            SellerItem si = context.SellerItems.First(f => f.Item_Code == sellerItem.Item_Code);
                            UpdateProductPrice(response, si);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.WriteLog(LogType.Error, ex.ToString());
                    }
                }
                context.SaveChanges();
            }
            return true;
        }
        catch (Exception ex)
        {
            Logging.WriteLog(LogType.Error, ex.ToString());
            return false;
        }
    }