/// <summary> /// Gets all tax rates /// </summary> /// <returns>Tax rates</returns> public IPagedList <YandexMarketProductRecord> GetByCategory(int categoryId = 0, bool isNotImportedOnly = false, int pageIndex = 0, int pageSize = int.MaxValue, bool withFantoms = false, bool withVendorExisting = true, bool isActiveOnly = false) { if (categoryId == -1) { return(new PagedList <YandexMarketProductRecord>(new List <YandexMarketProductRecord>(), 0, 1)); } IQueryable <YandexMarketProductRecord> query = this._productRepository.Table; if (!withFantoms) { query = query.Where(tr => tr.Name != "NotInPriceList"); } if (categoryId != 0) { query = query.Where(tr => tr.YandexMarketCategoryRecordId == categoryId); } if (isActiveOnly) { var activeYaCategoriesIds = _yandexMarketCategoryService.GetAll().Where(x => x.IsActive).Select(y => y.Id).ToList(); query = query.Where(tr => activeYaCategoriesIds.Contains(tr.YandexMarketCategoryRecordId)); } IEnumerable <YandexMarketProductRecord> res1 = query.ToList(); if (isNotImportedOnly) { var yaCategories = _yandexMarketCategoryService.GetAll(); var yaCategory = yaCategories.SingleOrDefault(x => x.Id == categoryId); var shopCategoryId = yaCategory != null ? yaCategory.ShopCategoryId : 0; var allShopProductsArtikuls = _productService.SearchProductVariants(shopCategoryId, 0, 0, "", false, 0, 2147483647, showHidden: true) .Select(x => x.Sku).ToList(); res1 = res1.Where(x => allShopProductsArtikuls.Contains(x.Articul) == false); } if (withVendorExisting) { var vendorArtikultList = _yugCatalogPriceParserService.ParseAndShow(false).ProductLineList.Select(x => x.Articul).ToList(); res1 = res1.Where(yaProduct => vendorArtikultList.Contains(yaProduct.Articul)); } res1 = res1.OrderBy(tr => tr.Name); var records = new PagedList <YandexMarketProductRecord>(res1.ToList(), pageIndex, pageSize); for (int i = 0; i < records.Count(); i++) { records[i] = records[i].Clone().FormatMe(); } return(records); }
public ActionResult ListCategory(GridCommand command) { var records = _yandexMarketCategoryService.GetAll(command.Page - 1, command.PageSize); var categorysModel = records .Select(x => { var m = new YandexMarketCategoryModel() { Id = x.Id, Name = x.Name, }; return(m); }) .ToList(); var model = new GridModel <YandexMarketCategoryModel> { Data = categorysModel, Total = records.TotalCount }; return(new JsonResult { Data = model }); }
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 }); }