private static List <TimesSold> FilterMatch(IUserSettingsView settings, int rptNumber, int minSold, int daysBack, int?minPrice, int?maxPrice, bool?activeStatusOnly, bool?isSellerVariation, string itemID) { DateTime ModTimeTo = DateTime.Now.ToUniversalTime(); DateTime ModTimeFrom = ModTimeTo.AddDays(-daysBack); itemID = (itemID == "null") ? null : itemID; var x = _repository.GetSalesData(rptNumber, ModTimeFrom, settings.StoreID, itemID); // filter by min and max price if (minPrice.HasValue) { x = x.Where(p => p.Price >= minPrice); } if (maxPrice.HasValue) { x = x.Where(p => p.Price <= maxPrice); } x = x.Where(p => p.SoldQty >= minSold); if (activeStatusOnly.HasValue) { if (activeStatusOnly.Value) { x = x.Where(p => p.ListingStatus == "Active"); } } if (isSellerVariation.HasValue) { if (isSellerVariation.Value) { x = x.Where(p => !p.IsSellerVariation.Value); } } return(x.ToList()); }
public static eBayAPIInterfaceService eBayServiceCall(IUserSettingsView settings, string CallName, string siteID) { string endpoint = "https://api.ebay.com/wsapi"; //string siteId = "0"; string appId = settings.AppID; string devId = settings.DevID; string certId = settings.CertID; string version = "965"; // Build the request URL string requestURL = endpoint + "?callname=" + CallName + "&siteid=" + siteID + "&appid=" + appId + "&version=" + version + "&routing=default"; eBayAPIInterfaceService service = new eBayAPIInterfaceService(); // Assign the request URL to the service locator. service.Url = requestURL; // Set credentials service.RequesterCredentials = new CustomSecurityHeaderType(); service.RequesterCredentials.eBayAuthToken = settings.Token; service.RequesterCredentials.Credentials = new UserIdPasswordType(); service.RequesterCredentials.Credentials.AppId = appId; service.RequesterCredentials.Credentials.DevId = devId; service.RequesterCredentials.Credentials.AuthCert = certId; return(service); }
protected override void Context() { _view = A.Fake <IUserSettingsView>(); _skinManager = A.Fake <ISkinManager>(); _userSettingsPersistor = A.Fake <IUserSettingsPersistor>(); _dialogCreator = A.Fake <IDialogCreator>(); _configuration = A.Fake <IPKSimConfiguration>(); _userSettings = A.Fake <IUserSettings>(); _speciesRepostiory = A.Fake <ISpeciesRepository>(); sut = new UserSettingsPresenter(_view, _userSettings, _skinManager, _userSettingsPersistor, _dialogCreator, _configuration, _speciesRepostiory); }
public UserSettingsPresenter( IUserSettingsView view, ITranslator translator, IGlobalSettingsRepository globalSettingsRepository, IResourceHandler resourceHandler, HttpContextBase context) { if (view == null) throw new ArgumentNullException("view"); if (translator == null) throw new ArgumentNullException("translator"); if (globalSettingsRepository == null) throw new ArgumentNullException("globalSettingsRepository"); if (resourceHandler == null) throw new ArgumentNullException("resourceHandler"); if (context == null) throw new ArgumentNullException("context"); _view = view; _translator = translator; _globalSettingsRepository = globalSettingsRepository; _resourceHandler = resourceHandler; _context = context; _log = Log.For(this); _view.LoadUserSettings += HandleLoadSettings; _view.SaveUserSettings += HandleSaveSettings; }
public UserSettingsPresenter( IUserSettingsView view, ITranslator translator, IGlobalSettingsRepository globalSettingsRepository, IResourceHandler resourceHandler, HttpContextBase context) { if (view == null) { throw new ArgumentNullException("view"); } if (translator == null) { throw new ArgumentNullException("translator"); } if (globalSettingsRepository == null) { throw new ArgumentNullException("globalSettingsRepository"); } if (resourceHandler == null) { throw new ArgumentNullException("resourceHandler"); } if (context == null) { throw new ArgumentNullException("context"); } _view = view; _translator = translator; _globalSettingsRepository = globalSettingsRepository; _resourceHandler = resourceHandler; _context = context; _log = Log.For(this); _view.LoadUserSettings += HandleLoadSettings; _view.SaveUserSettings += HandleSaveSettings; }
/// <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); }
/// <summary> /// Based on filtering a seller's sales, try to match a prodID with a prodID on walmart /// </summary> /// <param name="settings"></param> /// <param name="rptNumber"></param> /// <param name="minSold"></param> /// <param name="daysBack"></param> /// <param name="minPrice"></param> /// <param name="maxPrice"></param> /// <param name="activeStatusOnly"></param> /// <param name="nonVariation"></param> /// <param name="itemID"></param> /// <param name="pctProfit"></param> /// <returns></returns> private static async Task UPCMatch(IUserSettingsView settings, int rptNumber, int minSold, int daysBack, int?minPrice, int?maxPrice, bool?activeStatusOnly, bool?isSellerVariation, string itemID, double pctProfit, decimal wmShipping, decimal wmFreeShippingMin, double eBayPct, int imgLimit) { string loopItemID = null; try { var mv = new ModelViewTimesSold(); mv.TimesSoldRpt = FilterMatch(settings, rptNumber, minSold, daysBack, minPrice, maxPrice, activeStatusOnly, isSellerVariation, itemID); foreach (var row in mv.TimesSoldRpt) { loopItemID = row.ItemID; bool tryAgain = false; WalmartSearchProdIDResponse response; //var walitem = new SupplierItem(); ISupplierItem walitem; if (row.SellerUPC != null) { response = wallib.wmUtility.SearchProdID(row.SellerUPC); if (response.Count == 1) { walitem = await wallib.wmUtility.GetDetail(response.URL, imgLimit, false); // If can't get supplier pics, not much point in posting. // Can happen when not matching correctly on something like an eBook or giftcard where walmart // is not providing "standard" images. (error is logged in GetDetail()). if (!string.IsNullOrEmpty(walitem.SupplierPicURL)) { walitem.UPC = row.SellerUPC; walitem.Updated = DateTime.Now; _repository.SupplierItemUpdateByProdID(row.SellerUPC, "", walitem as SupplierItem, "Updated", "ItemURL", "SoldAndShippedBySupplier", "SupplierBrand", "SupplierPrice", "IsVariation", "SupplierPicURL", "IsFreightShipping"); var oh = new OrderHistory(); oh.ItemID = row.ItemID; oh.MatchCount = response.Count; oh.MatchType = 1; oh.SourceID = walitem.SourceID; oh.SupplierItemID = walitem.ID; if (walitem.SupplierPrice.HasValue) { var p = wallib.wmUtility.wmNewPrice(walitem.SupplierPrice.Value, pctProfit, wmShipping, wmFreeShippingMin, eBayPct); oh.ProposePrice = p.ProposePrice; _repository.OrderHistoryUpdate(oh, "ProposePrice", "MatchType", "MatchCount", "SourceID", "SupplierItemID"); } else { _repository.OrderHistoryUpdate(oh, "MatchType", "MatchCount", "SourceID", "SupplierItemID"); } } } else { tryAgain = true; } } else { tryAgain = true; } if (tryAgain) { if (row.SellerMPN != null) { response = wallib.wmUtility.SearchProdID(row.SellerMPN); if (response.Count == 1) { walitem = await wallib.wmUtility.GetDetail(response.URL, imgLimit, false); // If can't get supplier pics, not much point in posting. // Can happen when not matching correctly on something like an eBook or giftcard where walmart // is not providing "standard" images. (error is logged in GetDetail()). if (!string.IsNullOrEmpty(walitem.SupplierPicURL)) { walitem.MPN = row.SellerMPN; walitem.Updated = DateTime.Now; _repository.SupplierItemUpdateByProdID("", row.SellerMPN, walitem as SupplierItem, "Updated", "ItemURL", "SoldAndShippedBySupplier", "SupplierBrand", "SupplierPrice", "IsVariation", "SupplierPicURL"); // now update the ebay seller item specific UPC // but walmart doesn't always give a UPC if (!string.IsNullOrEmpty(walitem.UPC)) { var itemSpecific = new OrderHistoryItemSpecific(); itemSpecific.SellerItemID = row.ItemID; itemSpecific.ItemName = "UPC"; itemSpecific.ItemValue = walitem.UPC; itemSpecific.Flags = true; _repository.OrderHistoryItemSpecificUpdate(itemSpecific); } if (walitem.SupplierPrice.HasValue) { var oh = new OrderHistory(); oh.ItemID = row.ItemID; var p = wallib.wmUtility.wmNewPrice(walitem.SupplierPrice.Value, pctProfit, wmShipping, wmFreeShippingMin, eBayPct); oh.ProposePrice = p.ProposePrice; oh.MatchCount = response.Count; oh.MatchType = 1; oh.SourceID = walitem.SourceID; oh.SupplierItemID = walitem.ID; _repository.OrderHistoryUpdate(oh, "ProposePrice", "MatchType", "MatchCount", "SourceID", "SupplierItemID"); } } } } } } } catch (Exception exc) { string msgItemID = (!string.IsNullOrEmpty(loopItemID)) ? "ItemID: " + loopItemID : ""; string header = "UPCMatch RptNumber: " + rptNumber.ToString() + " " + msgItemID; string msg = dsutil.DSUtil.ErrMsg(header, exc); dsutil.DSUtil.WriteFile(_logfile, msg, ""); } }
/// <summary> /// Are we calculating for just one seller or all active? /// </summary> /// <param name="settings"></param> /// <param name="rptNumber">Pass either rptNumber or storeID.</param> /// <param name="minSold"></param> /// <param name="daysBack"></param> /// <param name="minPrice"></param> /// <param name="maxPrice"></param> /// <param name="activeStatusOnly"></param> /// <param name="isSellerVariation"></param> /// <param name="itemID"></param> /// <param name="pctProfit"></param> /// <param name="storeID">Pass storeID to run all sellers in store.</param> /// <returns></returns> public static async Task <string> CalculateMatch(IUserSettingsView settings, int rptNumber, int minSold, int daysBack, int?minPrice, int?maxPrice, bool?activeStatusOnly, bool?isSellerVariation, string itemID, double pctProfit, int storeID, decimal wmShipping, decimal wmFreeShippingMin, double eBayPct, int imgLimit, string supplierTag) { string ret = null; try { var sh = new SearchHistory(); if (rptNumber > 0 && storeID > 0) { ret = "Invalid call to FillMatch."; dsutil.DSUtil.WriteFile(_logfile, ret, ""); } else if (rptNumber > 0) // Called from Display Scans - run a single reportID { sh.ID = rptNumber; sh.CalculateMatch = DateTime.Now; _repository.SearchHistoryUpdate(sh, "CalculateMatch"); _repository.ClearOrderHistory(rptNumber); await UPCMatch(settings, rptNumber, minSold, daysBack, minPrice, maxPrice, activeStatusOnly, isSellerVariation, itemID, pctProfit, wmShipping, wmFreeShippingMin, eBayPct, imgLimit); // 03.17.2020 currently not happy with accuracy //await SearchEngineMatch(settings, rptNumber, minSold, daysBack, minPrice, maxPrice, activeStatusOnly, isSellerVariation, itemID, pctProfit, wmShipping, wmFreeShippingMin, eBayPct, imgLimit, supplierTag); } else if (storeID > 0) // Used by CalculateMatch console app to run entire store { var sellers = _repository.GetSellers(); bool runScan = false; foreach (var seller in sellers) { Console.WriteLine(seller.Seller); runScan = false; var sellerProfile = await _repository.SellerProfileGet(seller.Seller); if (sellerProfile == null) { runScan = true; } else { if (sellerProfile.Active) { runScan = true; } } if (runScan) { int?latest = _repository.LatestRptNumber(seller.Seller); var tgtSearchHistory = seller.SearchHistory.Where(p => p.ID == latest).SingleOrDefault(); if (tgtSearchHistory != null) { if (tgtSearchHistory.CalculateMatch == null || tgtSearchHistory.CalculateMatch < tgtSearchHistory.Updated) { sh.CalculateMatch = DateTime.Now; sh.Updated = DateTime.Now; sh.ID = tgtSearchHistory.ID; _repository.SearchHistoryUpdate(sh, "CalculateMatch", "Updated"); await UPCMatch(settings, tgtSearchHistory.ID, minSold, daysBack, minPrice, maxPrice, activeStatusOnly, isSellerVariation, itemID, pctProfit, wmShipping, wmFreeShippingMin, eBayPct, imgLimit); //await SearchEngineMatch(settings, rptNumber, minSold, daysBack, minPrice, maxPrice, activeStatusOnly, isSellerVariation, itemID, pctProfit, wmShipping, wmFreeShippingMin, eBayPct, imgLimit, supplierTag); dsutil.DSUtil.WriteFile(_logfile, seller.Seller + ": Ran FillMatch", ""); } Thread.Sleep(2000); } } } } else { ret = "Invalid call to FillMatch."; dsutil.DSUtil.WriteFile(_logfile, ret, ""); } } catch (Exception exc) { ret = dsutil.DSUtil.ErrMsg("CalculateMatch", exc); dsutil.DSUtil.WriteFile(_logfile, ret, "admin"); } return(ret); }