public static CallResult <string> Export(IDbFactory dbFactory, ILogService log, ITime time, long companyId, BargainSearchFilterViewModel filter) { var service = new BargainSearchService(dbFactory, log, time); var marketplaceManager = new MarketplaceKeeper(dbFactory, false); marketplaceManager.Init(); AmazonApi api = (AmazonApi) new MarketFactory(marketplaceManager.GetAll(), time, log, dbFactory, null) .GetApi(companyId, MarketType.Amazon, MarketplaceKeeper.AmazonComMarketplaceId); var result = service.Search(filter.GetModel(), api); var fileName = "BargainsSearch_" + DateTime.Now.ToString("MM_dd_yyyy_hh_mm_ss") + ".xls"; var filePath = UrlHelper.GetBargainExportFilePath(fileName); service.ExportBargains(result.Bargains.Where(bi => bi.AvailableOnWalmart).ToList(), filePath); var fileUrl = UrlHelper.GetBargainExportUrl(fileName); return(CallResult <string> .Success(fileUrl)); }
public static BargainSearchResultViewModel GetAll(IDbFactory dbFactory, ILogService log, ITime time, long companyId, BargainSearchFilterViewModel filter) { var service = new BargainSearchService(dbFactory, log, time); var marketplaceManager = new MarketplaceKeeper(dbFactory, false); marketplaceManager.Init(); AmazonApi api = (AmazonApi) new MarketFactory(marketplaceManager.GetAll(), time, log, dbFactory, null) .GetApi(companyId, MarketType.Amazon, MarketplaceKeeper.AmazonComMarketplaceId); var result = service.Search(filter.GetModel(), api); return(new BargainSearchResultViewModel() { TotalResults = result.Total, Bargains = result.Bargains.Select(b => new BargainViewModel(b)).ToList() }); }