/// <summary> /// GetCompletedItems(service, request, currentPageNumber) returns a FindCompletedItemsResponse which has property, searchResult /// Iterate the seller's sold items, fetching sales history /// </summary> /// <param name="result"></param> /// <returns></returns> public static List <Listing> MapSearchResultToListing(SearchResult result) { var listings = new List <Listing>(); try { // Iterate completed items foreach (SearchItem searchItem in result.item) { var listing = new Listing(); ISellerListing sellerListing = new SellerListing(); sellerListing.Title = searchItem.title; listing.ItemID = searchItem.itemId; sellerListing.EbayURL = searchItem.viewItemURL; listing.PrimaryCategoryID = searchItem.primaryCategory.categoryId; listing.PrimaryCategoryName = searchItem.primaryCategory.categoryName; sellerListing.SellerPrice = (decimal)searchItem.sellingStatus.currentPrice.Value; sellerListing.Variation = searchItem.isMultiVariationListing; //listing.SellerListing = sellerListing; listings.Add(listing); } return(listings); } catch (Exception exc) { string msg = dsutil.DSUtil.ErrMsg("MapSearchResultToListing", exc); dsutil.DSUtil.WriteFile(_logfile, msg, ""); return(null); } }
/// <summary> /// This is where a SellerListing record is created. /// </summary> /// <param name="settings"></param> /// <param name="rptNumber"></param> /// <returns></returns> public static async Task <string> StoreToListing(IUserSettingsView settings, int storeID) { string ret = "Copied 0 records."; int copiedRecords = 0; try { var recs = _repository.Context.UpdateToListing.AsNoTracking().Where(p => p.StoreID == storeID && p.ToListing).ToList(); foreach (var updateToList in recs) { var oh = _repository.Context.OrderHistory.AsNoTracking().Where(p => p.ItemID == updateToList.ItemID).SingleOrDefault(); var ohObj = _repository.Context.OrderHistory.AsNoTracking().Include("ItemSpecifics").AsNoTracking().Where(p => p.ItemID == updateToList.ItemID).SingleOrDefault(); var UPC = ohObj.ItemSpecifics.Where(p => p.ItemName == "UPC").Select(q => q.ItemValue).FirstOrDefault(); var MPN = ohObj.ItemSpecifics.Where(p => p.ItemName == "MPN").Select(q => q.ItemValue).FirstOrDefault(); string foundResult = _repository.ProdIDExists(UPC, MPN, storeID); if (foundResult == null) { var listing = new Listing(); listing.ItemID = ohObj.ItemID; listing.ListingTitle = ohObj.Title; if (ohObj.ProposePrice.HasValue) { listing.ListingPrice = ohObj.ProposePrice.Value; } var supplierItem = _repository.GetSupplierItem(oh.SupplierItemID.Value); listing.SupplierID = supplierItem.ID; listing.Profit = 0; listing.ProfitMargin = 0; listing.StoreID = storeID; var descr = supplierItem.Description; listing.Description = descr; var upc = _repository.Context.OrderHistoryItemSpecifics.AsNoTracking().Where(i => i.SellerItemID == ohObj.ItemID && i.ItemName == "UPC").SingleOrDefault(); if (upc != null) { listing.UPC = upc.ItemValue; } // MPN may have been collected twice - which one to use? For now, pick first one. var mpn = _repository.Context.OrderHistoryItemSpecifics.AsNoTracking().Where(i => i.SellerItemID == ohObj.ItemID && i.ItemName == "MPN").FirstOrDefault(); if (mpn != null) { listing.MPN = mpn.ItemValue; } var si = await eBayUtility.ebayAPIs.GetSingleItem(settings, listing.ItemID, true); listing.PrimaryCategoryID = si.PrimaryCategoryID; listing.PrimaryCategoryName = si.PrimaryCategoryName; if (_repository.GetSellerListing(ohObj.ItemID) == null) { var sellerListing = new SellerListing(); sellerListing.ItemID = ohObj.ItemID; sellerListing.Title = ohObj.Title; sellerListing.Seller = si.Seller; sellerListing.PrimaryCategoryID = si.PrimaryCategoryID; sellerListing.PrimaryCategoryName = si.PrimaryCategoryName; sellerListing.Description = si.Description; sellerListing.ListingStatus = si.ListingStatus; sellerListing.EbayURL = si.EbayURL; sellerListing.PictureURL = si.PictureURL; sellerListing.SellerPrice = si.SellerPrice; sellerListing.Updated = DateTime.Now; sellerListing.ItemSpecifics = _repository.CopyFromOrderHistory(ohObj.ItemSpecifics); //listing.SellerListing = sellerListing; } await _repository.ListingSaveAsync(settings, listing, true); var obj = new UpdateToListing() { StoreID = storeID, ItemID = ohObj.ItemID }; await _repository.UpdateToListingRemove(obj); ++copiedRecords; ret = "Copied records: " + copiedRecords.ToString(); } else { return(foundResult); } } } catch (Exception exc) { ret = dsutil.DSUtil.ErrMsg("StoreToListing", exc); dsutil.DSUtil.WriteFile(_logfile, ret, "admin"); } return(ret); }