public string GetSearchByKeyword(string keyword, int pageSize, string TokenJSON, string filters, int? userCode) { int UserCode = userCode == null ? new Base().UserKey : (int)userCode; User user = new DataModelEntities().Users.FirstOrDefault(f => f.User_Code == userCode); dynamic filterObject = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<dynamic>(filters); EbayServiceBL serviceBL = new EbayServiceBL(UserCode); FindItemsByKeywordsResponse response = serviceBL.SearchItems(keyword, pageSize, 1, filterObject); SearchResult result = response.searchResult; if (result == null) return null; // get all Items Details SimpleItemType[] simpleItems = serviceBL.GetMultipleItemsDetails(result); List<EbaySearchItem> searchItems = new List<EbaySearchItem>(); Dictionary<string, int> tokens = (Dictionary<string, int>)Common.Deserialize(TokenJSON, typeof(Dictionary<string, int>)); string[] mySellerIDs = tokens.Select(t => t.Key).ToArray(); // Looping through response object for result foreach (SearchItem item in result.item) { SimpleItemType simpleItem = simpleItems.FirstOrDefault(i => i.ItemID == item.itemId); if (simpleItem.ReserveMetSpecified == false || simpleItem.ReserveMet == true) { EbaySearchItem searchItem = new EbaySearchItem(); string timeLeft = item.sellingStatus.timeLeft, days = string.Empty, temp = string.Empty; if (timeLeft.IndexOf('D') != -1) days = timeLeft.Substring(timeLeft.IndexOf('P') + 1, timeLeft.IndexOf('D') - 1) + "d "; if (days == "0d ") days = ""; temp = days + timeLeft.Substring(timeLeft.IndexOf('T') + 1, timeLeft.IndexOf('H') - timeLeft.IndexOf('T') - 1) + "h "; if (days == "") timeLeft = temp + timeLeft.Substring(timeLeft.IndexOf('H') + 1, timeLeft.IndexOf('M') - timeLeft.IndexOf('H') - 1) + "m"; else timeLeft = temp; searchItem.ItemID = item.itemId; searchItem.Title = item.title; searchItem.Price = item.sellingStatus.currentPrice.Value; searchItem.TimeRemaining = timeLeft; searchItem.ViewURL = item.viewItemURL; searchItem.ImageURL = item.galleryURL; searchItem.SellerID = simpleItem.Seller.UserID; searchItem.TopRatedSeller = simpleItem.Seller.TopRatedSeller; searchItem.SellerScore = simpleItem.Seller.PositiveFeedbackPercent; searchItem.ConvertedPrice = item.sellingStatus.convertedCurrentPrice.Value; searchItem.TotalCost = searchItem.ConvertedPrice;//will be shown on search result //We are ignoring Shipping cost for the time being because we dont have solution to get converted shipping cost if (item.shippingInfo.shippingServiceCost != null) searchItem.ShippingCost = item.shippingInfo.shippingServiceCost.Value; else searchItem.ShippingCost = 0; /*If user have selected include shipping in settings shippingcost + price*/ if (user.Automation_Include_Shipping != null && user.Automation_Include_Shipping == true) searchItem.TotalCostIncludingShipping = searchItem.ShippingCost + searchItem.ConvertedPrice; else searchItem.TotalCostIncludingShipping = searchItem.ConvertedPrice; if (mySellerIDs.Contains(searchItem.SellerID)) searchItem.IsMyProduct = true; else searchItem.IsMyProduct = false; searchItems.Add(searchItem); } } var data = searchItems.OrderBy(o => o.TotalCostIncludingShipping).ToList(); return Common.Serialize(data); }
public string GetProductRankTitle(string filterJSON, int pageSize, string TokenJSON, int? userCode) { int UserCode = userCode == null ? new Base().UserKey : (int)userCode; User user = new DataModelEntities().Users.FirstOrDefault(f => f.User_Code == UserCode); pageSize = user.Search_Only_Top_Items == null || user.Search_Only_Top_Items == 0 ? 25 : (int)user.Search_Only_Top_Items; SellerItem sellerItem = null; if (!string.IsNullOrEmpty(filterJSON)) { sellerItem = (SellerItem)Common.Deserialize(filterJSON, typeof(SellerItem)); } if (sellerItem != null) { //EbayServiceBL serviceBL = new EbayServiceBL(UserCode); EbayServiceBL serviceBL = new EbayServiceBL(UserCode, (int)sellerItem.Country_Code); FindItemsByKeywordsResponse response = null; SearchResult result = null; //There is no filter for ignored words //I am requesting api to give 60 items so that i can ignore items based on ingored words if (!string.IsNullOrEmpty(sellerItem.Ignore_Words)) { response = serviceBL.SearchItems(sellerItem, 60, 1); result = response.searchResult; if (result == null || result.count == 0) return null; string[] ignoredWords = sellerItem.Ignore_Words.Split(','); SearchItem[] shortResult = result.item.AsEnumerable().Where(w => !ignoredWords.Any(a => !string.IsNullOrEmpty(a) && w.title.ToLower().Contains(a.ToLower()))).Take(pageSize).ToArray(); if (shortResult.Length > 0) { result.item = shortResult; result.count = shortResult.Length; } else return null; } else { response = serviceBL.SearchItems(sellerItem, pageSize, 1); result = response.searchResult; if (result == null || result.count == 0) return null; } //FindItemsByKeywordsResponse response = serviceBL.SearchItems(sellerItem, pageSize, 1); //SearchResult result = response.searchResult; //if (result == null || result.count == 0) // return null; // get all Items Details SimpleItemType[] simpleItems = serviceBL.GetMultipleItemsDetails(result); List<EbaySearchItem> searchItems = new List<EbaySearchItem>(); Dictionary<string, int> tokens = (Dictionary<string, int>)Common.Deserialize(TokenJSON, typeof(Dictionary<string, int>)); string[] mySellerIDs = tokens.Select(t => t.Key).ToArray(); // Looping through response object for result foreach (SearchItem item in result.item) { SimpleItemType simpleItem = simpleItems.FirstOrDefault(i => i.ItemID == item.itemId); if (simpleItem.ReserveMetSpecified == false || simpleItem.ReserveMet == true) { EbaySearchItem searchItem = new EbaySearchItem(); string timeLeft = item.sellingStatus.timeLeft, days = string.Empty, temp = string.Empty; if (timeLeft.IndexOf('D') != -1) days = timeLeft.Substring(timeLeft.IndexOf('P') + 1, timeLeft.IndexOf('D') - 1) + "d "; if (days == "0d ") days = ""; temp = days + timeLeft.Substring(timeLeft.IndexOf('T') + 1, timeLeft.IndexOf('H') - timeLeft.IndexOf('T') - 1) + "h "; if (days == "") timeLeft = temp + timeLeft.Substring(timeLeft.IndexOf('H') + 1, timeLeft.IndexOf('M') - timeLeft.IndexOf('H') - 1) + "m"; else timeLeft = temp; searchItem.ItemID = item.itemId; searchItem.Title = item.title; searchItem.Price = item.sellingStatus.currentPrice.Value; searchItem.TimeRemaining = timeLeft; searchItem.ViewURL = item.viewItemURL; searchItem.ImageURL = item.galleryURL; searchItem.SellerID = simpleItem.Seller.UserID; searchItem.TopRatedSeller = simpleItem.Seller.TopRatedSeller; searchItem.SellerScore = simpleItem.Seller.PositiveFeedbackPercent; searchItem.ConvertedPrice = item.sellingStatus.convertedCurrentPrice.Value; searchItem.TotalCost = searchItem.ConvertedPrice;//will be shown on search result //We are ignoring Shipping cost for the time being because we dont have solution to get converted shipping cost //if (item.shippingInfo.shippingServiceCost != null && user.Country1.Country_Abbr.ToUpper() == sellerItem.LocatedIn.ToUpper()) // searchItem.ShippingCost = item.shippingInfo.shippingServiceCost.Value; //else // searchItem.ShippingCost = 0; /*If user have selected include shipping in settings shippingcost + price*/ if (user.Automation_Include_Shipping != null && user.Automation_Include_Shipping == true) searchItem.TotalCostIncludingShipping = searchItem.ShippingCost + searchItem.ConvertedPrice; else searchItem.TotalCostIncludingShipping = searchItem.ConvertedPrice; if (mySellerIDs.Contains(searchItem.SellerID)) searchItem.IsMyProduct = true; else searchItem.IsMyProduct = false; searchItems.Add(searchItem); } } var data = searchItems.Where(w => w.ItemID == sellerItem.Item_ID || w.IsMyProduct == false).ToList().OrderBy(o => o.TotalCost); return Common.Serialize(data); } else return null; }