public ActionResult ListProduct(bool isNotImportedOnly, int parserCategoryId, GridCommand command) { var records = _yandexMarketProductService.GetByCategory(parserCategoryId, isNotImportedOnly, command.Page - 1, command.PageSize); var productsModel = records.Select( x => { var formated = new FormatterUgContract().Format(x); var m = new YandexMarketProductModel( formated.Articul, formated.Name, formated.FullDescription, formated.ImageUrl_1, formated.Url, formated.YandexMarketCategoryRecordId, formated.Specifications.Select(s => new YandexMarketSpecModel(s.Key, s.Value)).ToList(), formated.Id); return(m); }).ToList(); var model = new GridModel <YandexMarketProductModel> { Data = productsModel, Total = records.TotalCount }; return(new JsonResult { Data = model }); }
public ActionResult ListProduct(int categoryId, GridCommand command) { var records = _yandexMarketProductService.GetByCategory(categoryId, command.Page - 1, command.PageSize); var productsModel = records .Select(x => { var m = new YandexMarketProductModel( x.Name, x.ImageUrl_1, x.YandexMarketCategoryRecordId, x.Specifications.Select(s => new YandexMarketSpecModel(s.Key, s.Value)).ToList(), x.Id); return(m); }) .ToList(); var model = new GridModel <YandexMarketProductModel> { Data = productsModel, Total = records.TotalCount }; return(new JsonResult { Data = model }); }
public virtual IPagedList <YandexMarketSpecRecord> GetByCategory(int categoryId, int pageIndex = 0, int pageSize = int.MaxValue) { var products = _yandexMarketProductService.GetByCategory(categoryId); var allSpecs = new List <YandexMarketSpecRecord>(); foreach (var currentProduct in products) // collecting { allSpecs.AddRange(currentProduct.Specifications); } return(new PagedList <YandexMarketSpecRecord>(allSpecs, pageIndex, pageSize)); }
public void Init(string catalogName, int parserCategoryId, int parseNotMoreThen, string productsPageUrl, ILogger logger, IYandexMarketProductService yandexMarketProductService) { this.mImageFolderPathForProductList = catalogName; this.ParseNotMoreThen = parseNotMoreThen; this.mLogger = logger; ParserCategoryId = parserCategoryId; ProductsPageUrl = productsPageUrl; _yandexMarketProductService = yandexMarketProductService; ProductsArtikulsInPiceList = GetProductsArtikulsInPiceList(); // Удаляем фантомные продукты из базы, если они появились в прайсе DeleteFromDbAppearedInPriceListFantoms(ParserCategoryId, ProductsArtikulsInPiceList); ExistedProductUrlList = _yandexMarketProductService.GetByCategory(parserCategoryId, withFantoms: true, withVendorExisting: false) .Select(s => new ExistedProduct { Url = s.Url, IsFantom = s.IsNotInPriceList }) .ToList(); }
public ActionResult ListCategory(bool isWithProductCountInCategories, GridCommand command) { var availableShopCategories = _shopCategoryService.GetAllCategories(); //.Select(x => new Dictionary<int, string>( x.Id, x.Name)).ToList(); var yaCategories = _yandexMarketCategoryService.GetAll(command.Page - 1, command.PageSize); var categorysModel = yaCategories .Select(currentYaCategory => { var shopCategory = availableShopCategories.SingleOrDefault(s => s.Id == currentYaCategory.ShopCategoryId); var shopCategoryName = ""; var numberOfProducts = 0; var notImportedRecords = 0; if (shopCategory != null) { shopCategoryName = shopCategory.Name; if (isWithProductCountInCategories) { numberOfProducts = this._productService.SearchProducts( categoryIds: new List <int>() { shopCategory.Id }, priceMin: 1, storeId: _storeContext.CurrentStore.Id, pageSize: 1).TotalCount; // посчитать сколько не импортировано еще notImportedRecords = _yandexMarketProductService.GetByCategory( categoryId: currentYaCategory.Id, isNotImportedOnly: true, pageIndex: command.Page - 1, pageSize: 1).TotalCount; } } else { shopCategoryName = "---"; currentYaCategory.ShopCategoryId = 0; } var m = new YandexMarketCategoryModel() { Id = currentYaCategory.Id, Name = currentYaCategory.Name, Url = currentYaCategory.Url, ShopCategoryId = currentYaCategory.ShopCategoryId, ShopCategoryName = shopCategoryName, IsActive = currentYaCategory.IsActive, AlreadyImportedProducts = numberOfProducts, NotImportedProducts = notImportedRecords, }; return(m); }) .ForCommand(command) .ToList(); var model = new GridModel <YandexMarketCategoryModel> { Data = categorysModel, Total = yaCategories.TotalCount }; return(new JsonResult { Data = model }); }