public string GetTokenJSON(int userCode) { Dictionary<string, int> localTokens = new Dictionary<string, int>(); EbayServiceBL service = new EbayServiceBL(userCode); foreach (KeyValuePair<int, string> pair in service.UserTokens) { string result = service.GetUser(pair.Value); localTokens.Add(result, pair.Key); } string tokenJSON = Common.Serialize(localTokens); return tokenJSON; }
protected void Page_Load(object sender, EventArgs e) { Dictionary<string,int> localTokens = new Dictionary<string,int>(); EbayServiceBL service = new EbayServiceBL(UserKey); foreach (KeyValuePair<int, string> pair in service.UserTokens) { string result = service.GetUser(pair.Value); localTokens.Add(result, pair.Key); } string tokenJSON = Common.Serialize(localTokens); hfTokenJSON.Value = tokenJSON; }
public List<ParcelItem> GetEbayTransactions(int UserCode) { EbayServiceBL service = new EbayServiceBL(UserCode); List<ParcelItem> allEbayItems = new List<ParcelItem>(); if (service.UserTokens != null) { foreach (KeyValuePair<int, string> account in service.UserTokens) { List<ParcelItem> ebayItems = GetEbayAccountTransactions(service, account,UserCode); if (ebayItems != null) allEbayItems.AddRange(ebayItems); } return allEbayItems.OrderBy(a => a.Type).ThenBy(a => a.AccountID).ThenBy(a => a.BuyerID).ToList(); } else return null; }
public List<CategoryType> GetEbayCategories(int UserCode) { EbayServiceBL service = new EbayServiceBL(UserCode); List<CategoryType> allEbayCategories = new List<CategoryType>(); if (service.UserTokens != null) { foreach (KeyValuePair<int, string> account in service.UserTokens) { CategoryType[] Categories = service.GetCategories(account.Value.ToString()); if (Categories != null) allEbayCategories.AddRange(Categories); } return allEbayCategories.ToList(); } else return null; }
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; }
public string UpdateProductTitle(string ItemId, string Title, string TokenJSON, string userID) { Dictionary<string, int> tokens = (Dictionary<string, int>)Common.Deserialize(TokenJSON, typeof(Dictionary<string, int>)); int userAccountCode = tokens[userID]; int UserCode = new Base().UserKey; EbayServiceBL service = new EbayServiceBL(UserCode); string result = service.ReviseEbayItemTitle(ItemId, Title, service.UserTokens[userAccountCode]); return result; }
private void UpdateEbaySale(Manifest item) { DataModelEntities context = new DataModelEntities(); UserAccount account; if (item.AccountID == string.Empty) { account = context.UserAccounts.Where(u => u.User_Code == UserKey & u.Account_Code == (int)Constant.Accounts.Ebay && u.Is_Active == true).OrderBy(u => u.User_Account_Code).First(); } else { int userAccountCode = int.Parse(item.AccountID); account = context.UserAccounts.First(u => u.User_Account_Code == userAccountCode); } if (item.ItemID != string.Empty && item.TransactionID != string.Empty) // check if both itemID and transactionID are valid. { CompleteSaleResponseType response = new EbayServiceBL(UserKey).UpdateShippingInfo(item.ItemID, item.TransactionID, item.TrackingNumber, account.Config_Value1); if (response.Ack == AckCodeType.Success || response.Ack == AckCodeType.Warning) { // status updated lblUploadStatus.Text = "Success. Ebay Shipping Information updated"; // delete from database too PriceManagerDAL.ParcelItem itemToDelete = context.ParcelItems.FirstOrDefault(f => f.User_Code == UserKey && f.TransactionID == item.TransactionID && f.ItemID == item.ItemID); if (itemToDelete != null) { context.ParcelItems.DeleteObject(itemToDelete); context.SaveChanges(); } } else { // some error lblUploadStatus.Text = "Error!! " + response.Errors[0].LongMessage; } } else { lblSkippedItems.Text += item.TrackingNumber + ", "; } context = null; }
protected void btnConfirmAuthorization_Click(object sender, EventArgs e) { if (IsValid) { string sessionID = hfSessionID.Value; try { // fetch a new token using SessionID string token = new EbayServiceBL(UserKey).FetchToken(sessionID); if (string.IsNullOrEmpty(token) == false) { // save entry in database. DataModelEntities context = new DataModelEntities(); // check if user is creating a new account, or updating existing one UserAccount userAccount = null; if (hfSelectedEbayAccountID.Value == "0") { userAccount = new UserAccount(); userAccount.User_Code = UserKey; userAccount.Account_Code = (int)Constant.Accounts.Ebay; userAccount.Application_Name = string.Empty; userAccount.Config_Value1 = token; userAccount.Created_Date = DateTime.Now; userAccount.Is_Active = true; userAccount.User_IP = Request.UserHostAddress; context.UserAccounts.AddObject(userAccount); } else { int userAccountCode = Convert.ToInt32(hfSelectedEbayAccountID.Value); userAccount = context.UserAccounts.First(u => u.User_Account_Code == userAccountCode); userAccount.Config_Value1 = token; userAccount.Modified_Date = DateTime.Now; userAccount.User_IP = Request.UserHostAddress; } context.SaveChanges(); try { EbayServiceBL service = new EbayServiceBL((int)userAccount.User_Code); if (service.UserTokens != null) { Dictionary<string, int> localTokens = new Dictionary<string, int>(); foreach (KeyValuePair<int, string> pair in service.UserTokens) { string ebayUserName = service.GetUser(pair.Value); if (pair.Key == userAccount.User_Account_Code) { userAccount.Ebay_User_Name = ebayUserName; context.SaveChanges(); } } } ParcelBL objParcelBL = new ParcelBL(); System.Threading.Thread t = new System.Threading.Thread(() => objParcelBL.SaveEbayUserItems(UserKey)); t.Start(); } catch (Exception ex) { Logging.WriteLog(LogType.Critical, ex.ToString()); } ScriptManager.RegisterClientScriptBlock(this, GetType(), "1", "window.location.reload()", true); lblAuthError.Text = string.Empty; } else { lblAuthError.Text = "Either you have not authorized properly, or the Ebay servers are down for the moment. Please try agian in a while."; } } catch (Exception ex) { lblAuthError.Text = "Either you have not authorized properly, or the Ebay servers are down for the moment. Please try agian in a while."; } } }
public void UpdateProductTitle(int sellerItemCode, ItemTitle itemTitle, ItemTitle oldTitle) { DataModelEntities context = new DataModelEntities(); SellerItem sellerItem = context.SellerItems.First(f => f.Item_Code == sellerItemCode); EbayServiceBL service = new EbayServiceBL((int)sellerItem.User_Code, (int)sellerItem.Country_Code); string result = service.ReviseEbayItemTitle(sellerItem.Item_ID, itemTitle.Title, service.UserTokens[(int)sellerItem.User_Account_Code]); /*In case of success service returns null*/ if (string.IsNullOrEmpty(result)) { TitleHistory ph = new TitleHistory(); ph.Item_Code = sellerItemCode; ph.New_Title = itemTitle.Title; ph.Old_Title = oldTitle == null ? sellerItem.Item_Name : oldTitle.Title; ph.Total_Sales = oldTitle == null ? sellerItem.Current_Sales : oldTitle.TotalSales; ph.Created_Date = System.DateTime.Now; context.TitleHistories.AddObject(ph); context.SaveChanges(); Logging.WriteLog(LogType.Info, sellerItem.Item_ID + " Title revised."); } else Logging.WriteLog(LogType.Error, result); }
public void UpdateProductPrice(string productRankResponse, SellerItem sellerItem) { EbayServiceBL service = new EbayServiceBL((int)sellerItem.User_Code, (int)sellerItem.Country_Code); double? averagePrice = null; double newPrice; double? AvgORLow = null; double floorPrice = Convert.ToDouble(sellerItem.Floor_Price); double ceilingPrice = Convert.ToDouble(sellerItem.Ceiling_Price); int? rank = null; double? shippingCost = null; List<EbaySearchItem> searchItems = (List<EbaySearchItem>)Common.Deserialize(productRankResponse, typeof(List<EbaySearchItem>)); string ItemID = sellerItem.Item_ID; EbaySearchItem myItem = searchItems.FirstOrDefault(f => f.ItemID == ItemID); if (myItem != null) { shippingCost = myItem.ShippingCost; rank = searchItems.IndexOf(myItem); } else { var myItemResponse = service.SearchItemsByID(ItemID); var myItemresult = myItemResponse.searchResult; if (myItemresult != null && myItemresult.count > 0) { var myItemSearched = myItemresult.item.FirstOrDefault(f => f.itemId == ItemID); shippingCost = myItemSearched.shippingInfo.shippingServiceCost != null ? myItemSearched.shippingInfo.shippingServiceCost.Value : 0; //shippingCost = 0; } } List<EbaySearchItem> excludedMySearchItems = searchItems.Where(w => w.IsMyProduct == false).ToList(); EbaySearchItem minPriceSearchItem = excludedMySearchItems.OrderBy(o => o.TotalCostIncludingShipping).FirstOrDefault(); EbaySearchItem maxPriceSearchItem = excludedMySearchItems.OrderByDescending(o => o.TotalCostIncludingShipping).FirstOrDefault(); /*Get averagePrice Price From Seached Items Excluded User's Items*/ if (excludedMySearchItems != null) averagePrice = excludedMySearchItems.Sum(s => s.TotalCostIncludingShipping) / excludedMySearchItems.Count; /*Set New Price Of Item According to Algo which have been selected by user*/ if (sellerItem.Algo == Convert.ToString((int)Common.Algo.Lowest)) { if (sellerItem.Less_To_Lowest_Price == null) AvgORLow = minPriceSearchItem != null ? (double?)(minPriceSearchItem.TotalCostIncludingShipping - 0.1) : null; else AvgORLow = minPriceSearchItem != null ? (double?)(minPriceSearchItem.TotalCostIncludingShipping - Convert.ToDouble(sellerItem.Less_To_Lowest_Price)) : null; //AvgORLow = minPriceSearchItem != null ? (double?)(minPriceSearchItem.TotalCost - (minPriceSearchItem.TotalCost * Convert.ToDouble(sellerItem.Less_To_Lowest_Price))) : null; it was before 9th april 2014 } else if (sellerItem.Algo == Convert.ToString((int)Common.Algo.Average)) AvgORLow = averagePrice; else if (sellerItem.Algo == Convert.ToString((int)Common.Algo.MatchLowest)) AvgORLow = minPriceSearchItem.TotalCostIncludingShipping; else AvgORLow = null; /*IF AvgORLow is set and not equals to null means price will be updated */ if (AvgORLow != null) { newPrice = AvgORLow >= floorPrice && AvgORLow <= ceilingPrice ? Convert.ToDouble(AvgORLow) : AvgORLow > ceilingPrice ? ceilingPrice : floorPrice; if (sellerItem.User.Automation_Include_Shipping == true && sellerItem.User.Country1.Country_Abbr.ToUpper() == sellerItem.LocatedIn.ToUpper()) { if (shippingCost == null) return; newPrice = newPrice - Convert.ToDouble(shippingCost); } if (sellerItem.Is_Round_To_Nearest == true) newPrice = Math.Floor(newPrice / 0.10) * 0.10; if (sellerItem.Current_Price == Convert.ToDecimal(newPrice)) return; string result = service.ReviseEbayItem(sellerItem.Item_ID, (double)newPrice, service.UserTokens[(int)sellerItem.User_Account_Code]); /*In case of success service returns null*/ if (string.IsNullOrEmpty(result)) { DataModelEntities context = new DataModelEntities(); SellerItem si = context.SellerItems.First(f => f.Item_Code == sellerItem.Item_Code); PricingHistory ph = new PricingHistory(); ph.Algo = si.Algo; ph.Keyword = si.Keywords; ph.Item_Code = si.Item_Code; ph.Old_Price = si.Current_Price; ph.New_Price = Convert.ToDecimal(newPrice); ph.Created_Date = System.DateTime.Now; ph.Currency = sellerItem.Currency; context.PricingHistories.AddObject(ph); si.Current_Price = Convert.ToDecimal(newPrice); si.Item_Rank = rank != null ? rank + 1 : null; context.SaveChanges(); if (sellerItem.Floor_Price == Convert.ToDecimal(newPrice)) { /*Send Floor limit Reaced Notification*/ System.Threading.Thread t = new System.Threading.Thread(() => SendFloorLimitReachedAlert(sellerItem)); t.Start(); } if (sellerItem.Ceiling_Price == Convert.ToDecimal(newPrice)) { /*Send Floor limit Reaced Notification*/ System.Threading.Thread t = new System.Threading.Thread(() => SendFloorLimitReachedAlert(sellerItem)); t.Start(); } Logging.WriteLog(LogType.Info, sellerItem.Item_ID + " Price revised."); } else Logging.WriteLog(LogType.Error, result); } }
protected void btnConfirmAuthorization_Click(object sender, EventArgs e) { if (IsValid) { string sessionID = hfSessionID.Value; try { // fetch a new token using SessionID string token = new EbayServiceBL(UserKey).FetchToken(sessionID); if (string.IsNullOrEmpty(token) == false) { // save entry in database. DataModelEntities context = new DataModelEntities(); // check if user is creating a new account, or updating existing one if (hfSelectedEbayAccountID.Value == "0") { UserAccount userAccount = new UserAccount(); userAccount.User_Code = UserKey; userAccount.Account_Code = (int)Constant.Accounts.Ebay; userAccount.Application_Name = string.Empty; userAccount.Config_Value1 = token; userAccount.Created_Date = DateTime.Now; userAccount.Is_Active = true; userAccount.User_IP = Request.UserHostAddress; context.UserAccounts.AddObject(userAccount); } else { int userAccountCode = Convert.ToInt32(hfSelectedEbayAccountID.Value); UserAccount userAccount = context.UserAccounts.First(u => u.User_Account_Code == userAccountCode); userAccount.Config_Value1 = token; userAccount.Modified_Date = DateTime.Now; userAccount.User_IP = Request.UserHostAddress; } context.SaveChanges(); ScriptManager.RegisterClientScriptBlock(this, GetType(), "1", "window.location.reload()", true); lblAuthError.Text = string.Empty; } else { lblAuthError.Text = "Either you have not authorized properly, or the Ebay servers are down for the moment. Please try agian in a while."; } } catch (Exception ex) { lblAuthError.Text = "Either you have not authorized properly, or the Ebay servers are down for the moment. Please try agian in a while."; } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Dictionary<string, int> localTokens = new Dictionary<string, int>(); EbayServiceBL service = new EbayServiceBL(UserKey); if (service.UserTokens != null) { string userNames = ""; foreach (KeyValuePair<int, string> pair in service.UserTokens) { string result = service.GetUser(pair.Value); localTokens.Add(result, pair.Key); userNames = result + ","; } hfSeller.Value = "";//userNames.Substring(0, userNames.Length - 1); string tokenJSON = Common.Serialize(localTokens); hfTokenJSON.Value = tokenJSON; AutomatePricingSettings(); BindEBayAccount(); BindCategory(); BindSettings(); BindCountry(); } else { Response.Redirect("~/pages/shopconnect.aspx", true); } } }
public void SaveEbayUserItems(int UserCode) { EbayServiceBL service = new EbayServiceBL(UserCode); DataModelEntities context = new DataModelEntities(); DateTime today = DateTime.Today; if (service.UserTokens != null) { foreach (KeyValuePair<int, string> account in service.UserTokens) { try { // List<Seller_Item> items = service.GetUserItems(account.Value); List<Seller_Item> items = service.GetUserItemsList(account.Value); foreach (Seller_Item item in items) { SellerItem sellerItem = context.SellerItems.FirstOrDefault(a => a.Is_Active == true && a.User_Account_Code == account.Key && a.Item_ID == item.ItemID && a.Country_Code == service.countryID); if (sellerItem == null) { if (item.EndDate.Date > today.Date) { /*Save to seller item*/ SellerItem dbItem = new SellerItem(); dbItem.BIN_Price = (decimal)item.BinPrice; dbItem.Created_Date = DateTime.Now; dbItem.Current_Price = (decimal)item.CurrentPrice; dbItem.End_Date = item.EndDate; dbItem.Is_Active = true; dbItem.Item_ID = item.ItemID; dbItem.Item_Name = item.ItemName; dbItem.Start_Date = item.StartDate; dbItem.Is_Automated = false; dbItem.User_Code = UserCode; dbItem.User_Account_Code = account.Key; dbItem.Picture_URL = item.PictureURL; dbItem.Item_View_URL = item.ItemViewURL; dbItem.Is_Promo_Item = item.IsPromoItem; dbItem.Item_Category_ID = item.CategoryID; dbItem.Item_Category_Name = item.CategoryName; dbItem.Currency = item.Currency; dbItem.Country_Code = item.CountryCode; dbItem.LocatedIn = item.CountryShortCode; dbItem.Current_Sales = item.CurrentSales; dbItem.QuantityAvailable = item.QuantityAvailable; context.SellerItems.AddObject(dbItem); } } else { if (item.EndDate.Date > today.Date) { sellerItem.User_Account_Code = account.Key; sellerItem.BIN_Price = (decimal)item.BinPrice; sellerItem.Current_Price = (decimal)item.CurrentPrice; sellerItem.End_Date = item.EndDate; sellerItem.Item_Name = item.ItemName; sellerItem.Start_Date = item.StartDate; sellerItem.Is_Promo_Item = item.IsPromoItem; sellerItem.Picture_URL = item.PictureURL; sellerItem.Item_View_URL = item.ItemViewURL; sellerItem.Item_Category_ID = item.CategoryID; sellerItem.Item_Category_Name = item.CategoryName; if (item.IsPromoItem == true && sellerItem.Is_Automated == true) sellerItem.Is_Automated = false; sellerItem.Currency = item.Currency; sellerItem.Country_Code = item.CountryCode; sellerItem.Current_Sales = item.CurrentSales; sellerItem.QuantityAvailable = item.QuantityAvailable; ItemTitle currentTitle = context.ItemTitles.FirstOrDefault(f => f.ItemId == sellerItem.Item_Code && (f.Is_Current == true || f.Title.ToLower() == sellerItem.Item_Name.ToLower())); if (currentTitle != null) { if(context.TitleHistories.Any(a => a.Item_Code == sellerItem.Item_Code)) { var totalSales = context.GetSalesForOldTitles(sellerItem.Item_Code, sellerItem.Item_Name).FirstOrDefault(); currentTitle.TotalSales = totalSales.TotalSales; } } } else { sellerItem.Is_Automated = false; sellerItem.Is_Active = false; } } if (1 == 1) { Decimal weightMajor = item.Weight != null ? Convert.ToDecimal(item.Weight) * 1000 : 0; //Weight Major comes in Kgs so converted in to gms Decimal weightMinor = item.Weight != null ? Convert.ToDecimal(item.WeightMinor) : 0; //Weight Minor comes in gms Decimal weight = (weightMajor + weightMinor) / 1000; // Added both major and minor and converted into kgs Item partmaster = context.Items.FirstOrDefault(a => a.Item_ID == item.ItemID && a.UserCode == UserCode && a.Country_Code == service.countryID); if (partmaster == null) { partmaster = new Item(); partmaster.Item_ID = item.ItemID; partmaster.CustomLabel = item.CustomLabel; partmaster.Description = item.ItemName; partmaster.UserCode = UserCode; partmaster.User_Account_Code = account.Key; partmaster.Height = item.Height != null ? item.Height.ToString() : string.Empty; partmaster.Length = item.Length != null ? item.Length.ToString() : string.Empty; partmaster.Width = item.Width != null ? item.Width.ToString() : string.Empty; partmaster.Weight = item.Weight != null || item.WeightMinor != null ? weight.ToString("0.00") : string.Empty; partmaster.Balance_Quantity = item.Quantity; partmaster.Current_Price = Convert.ToDecimal(item.CurrentPrice); partmaster.BIN_Price = Convert.ToDecimal(item.BinPrice); partmaster.Picture_URL = item.PictureURL; partmaster.Item_View_URL = item.ItemViewURL; partmaster.Item_Category_ID = item.CategoryID; partmaster.Item_Category_Name = item.CategoryName; partmaster.Start_Date = item.StartDate; partmaster.End_Date = item.EndDate; partmaster.User_Account_Code = account.Key; partmaster.Detail_Description = item.Discription; partmaster.Country_Code = item.CountryCode; context.AddToItems(partmaster); } else { partmaster.CustomLabel = item.CustomLabel; partmaster.Description = item.ItemName; partmaster.UserCode = UserCode; partmaster.User_Account_Code = account.Key; if (string.IsNullOrEmpty(partmaster.Height)) partmaster.Height = item.Height != null ? item.Height.ToString() : string.Empty; if (string.IsNullOrEmpty(partmaster.Length)) partmaster.Length = item.Length != null ? item.Length.ToString() : string.Empty; if (string.IsNullOrEmpty(partmaster.Width)) partmaster.Width = item.Width != null ? item.Width.ToString() : string.Empty; if (string.IsNullOrEmpty(partmaster.Weight)) partmaster.Weight = item.Weight != null || item.WeightMinor != null ? weight.ToString("0.00") : string.Empty; partmaster.Height = item.Height != null ? item.Height.ToString() : string.Empty; partmaster.Length = item.Length != null ? item.Length.ToString() : string.Empty; partmaster.Width = item.Width != null ? item.Width.ToString() : string.Empty; partmaster.Weight = item.Weight != null || item.WeightMinor != null ? weight.ToString("0.00") : string.Empty; partmaster.Current_Price = Convert.ToDecimal(item.CurrentPrice); partmaster.BIN_Price = Convert.ToDecimal(item.BinPrice); partmaster.Picture_URL = item.PictureURL; partmaster.Item_View_URL = item.ItemViewURL; partmaster.Item_Category_ID = item.CategoryID; partmaster.Item_Category_Name = item.CategoryName; partmaster.Start_Date = item.StartDate; partmaster.User_Account_Code = account.Key; partmaster.End_Date = item.EndDate; partmaster.Balance_Quantity = item.Quantity; partmaster.Country_Code = item.CountryCode; } } context.SaveChanges(); } //context.SaveChanges(); } catch (Exception ex) { Logging.WriteLog(LogType.Critical, ex.ToString()); } } } }
private List<ParcelItem> GetEbayAccountTransactions(EbayServiceBL service, KeyValuePair<int, string> account, int UserCode) { int accountID = account.Key; DataModelEntities context = new DataModelEntities(); List<PriceManagerDAL.ParcelItem> parcelItems = context.ParcelItems.Where(f => f.AccountID == accountID && f.User_Code == UserCode && f.Is_Active == true).ToList(); string currentItemID = string.Empty, currentTransactionID = string.Empty, currentRecordNo = string.Empty; SellingManagerSoldOrderType[] results = service.GetPendingShipmentItems(account.Value); if(results == null) results = new SellingManagerSoldOrderType[0]; // delete all database entries that does not exist in the API results. foreach (PriceManagerDAL.ParcelItem existingItem in parcelItems) { long transactionID = long.Parse(existingItem.TransactionID); SellingManagerSoldOrderType checkResult = results.FirstOrDefault(r => r.SellingManagerSoldTransaction.Count(c => c.ItemID == existingItem.ItemID && c.TransactionID == transactionID) > 0); if (checkResult == null) { context.ParcelItems.DeleteObject(existingItem); } } // delete entries which do not have correct shipping details foreach (PriceManagerDAL.ParcelItem existingItem in parcelItems.Where(p => string.IsNullOrEmpty(p.BuyerName) == true)) { context.ParcelItems.DeleteObject(existingItem); } // now traverse through API results and save only those which are new List<ParcelItem> items = new List<ParcelItem>(); if (results != null && results.Length > 0) { List<ChargeCode> chargeCodes = new DataModelEntities().ChargeCodes.Where(u => u.Is_Active == true && u.User_Code == UserCode).ToList(); foreach (SellingManagerSoldOrderType result in results) { foreach (SellingManagerSoldTransactionType transaction in result.SellingManagerSoldTransaction) { try { currentItemID = transaction.ItemID; currentTransactionID = transaction.TransactionID.ToString(); // ignore if the item already exists in our database if (context.ParcelItems.FirstOrDefault(f => f.AccountID == accountID && f.ItemID == currentItemID && f.TransactionID == currentTransactionID) != null) { continue; } ParcelItem item = new ParcelItem(); item.Type = "EBAY"; SellingManagerSoldOrderType itemDetails = service.GetSaleRecordDetails(transaction.ItemID, transaction.TransactionID.ToString(), account.Value); currentRecordNo = itemDetails.SaleRecordID.ToString(); item.AccountID = account.Key.ToString(); item.ItemID = transaction.ItemID; item.TransactionID = transaction.TransactionID.ToString(); item.ItemName = transaction.ItemTitle; item.CustomLabel = transaction.CustomLabel; item.CustomLabelText = transaction.SaleRecordID.ToString() + ":" + transaction.CustomLabel; if (itemDetails.ShippingAddress != null) { if (StateHelper.States.Where(s => s.Key == itemDetails.ShippingAddress.StateOrProvince.ToLower()).Count() > 0) item.State = StateHelper.States[itemDetails.ShippingAddress.StateOrProvince.ToLower()]; else item.State = itemDetails.ShippingAddress.StateOrProvince.ToLower(); item.BuyerName = itemDetails.ShippingAddress.Name; item.Street = itemDetails.ShippingAddress.Street; item.Street2 = itemDetails.ShippingAddress.Street1; item.Street3 = itemDetails.ShippingAddress.Street2; item.City = itemDetails.ShippingAddress.CityName; item.PostalCode = itemDetails.ShippingAddress.PostalCode.TrimStart('0'); ; item.Country = itemDetails.ShippingAddress.Country.ToString(); item.Phone = itemDetails.ShippingAddress.Phone; } else { } item.EmailAddress = itemDetails.BuyerEmail; item.BuyerID = itemDetails.BuyerID; item.Quantity = transaction.QuantitySold; if (itemDetails.ActualShippingCost != null) item.ShippingCost = itemDetails.ActualShippingCost.Value; item.SaleRecordId = itemDetails.SaleRecordID.ToString(); bool IspostCodeOK = true; if (itemDetails.ShippingDetails != null) { if (itemDetails.ShippingDetails.InsuranceFee == null) item.HasInsurance = false; else { item.HasInsurance = true; item.Insurance = itemDetails.ShippingDetails.InsuranceFee.Value; } if (itemDetails.ShippingDetails != null && itemDetails.ShippingDetails.ShippingServiceOptions != null) item.ShippingMethod = itemDetails.ShippingDetails.ShippingServiceOptions[0].ShippingService; else item.ShippingMethod = "N/A"; IspostCodeOK = Common.VerifyPostCode(itemDetails.ShippingAddress.PostalCode, itemDetails.ShippingAddress.CityName); if (IspostCodeOK) item.PostCodeImageURL = Constant.tickURL; else item.PostCodeImageURL = Constant.crossURL; } if (itemDetails.SellingManagerSoldTransaction != null) { item.Currency = itemDetails.SellingManagerSoldTransaction[0].ItemPrice.currencyID.ToString(); item.Price = itemDetails.SellingManagerSoldTransaction[0].ItemPrice.Value; } item.RecordNumber = itemDetails.SaleRecordID.ToString(); ChargeCode code = chargeCodes.FirstOrDefault(u => item.ShippingMethod.ToLower().Contains(u.Ebay_Code.ToLower()) == true); if (code != null && code.Charge_Code_Name.ToLower() == "ignore") { continue; // ignore the item } GetMemberMessagesResponseType messages = service.GetTransactionMessages(item.ItemID, item.BuyerID, account.Value); if (messages.MemberMessage != null) { List<ParcelMessage> ebayMessages = service.ConvertEbayMessages(messages); item.Messages = Common.Serialize(ebayMessages); } items.Add(item); currentItemID = string.Empty; currentRecordNo = string.Empty; currentTransactionID = string.Empty; } catch (Exception ex) { Logging.WriteLog(LogType.Critical, ex.ToString()); } } } context.SaveChanges(); return items.OrderBy(i => i.BuyerID).ToList(); } else { context.SaveChanges(); return null; } }