// // GET: /Manage/Order/ #region ORDER public ActionResult Index(int?page, long?loadShop = -1, int?stateOrder = -1, int?loadPaid = -1) { ViewBag.Mes = string.Empty; ViewBag.ShopId = loadShop; ViewBag.states = stateOrder; ViewBag.paid = loadPaid; ViewBag.loadShop = LoadCombo.LoadDropShop(); ViewBag.stateOrder = LoadCombo.LoadDropOrder(stateOrder); ViewBag.loadPaid = LoadCombo.LoadDropOrderPaid(loadPaid); int currentPageIndex = page.HasValue ? page.Value : 1; ViewBag.page = currentPageIndex; var listObj = _orderBussiness.GetList(loadShop, stateOrder, loadPaid); IPagedList <Order> obj = listObj.ToPagedList(currentPageIndex, 10); if (obj.Any()) { // obj=obj.ToPagedList(currentPageIndex, 20); return(View(obj)); } { ViewBag.Mes = "Chưa có đơn hàng"; // obj=(IPagedList<Order>) new List<Order>(); return(View()); } }
private async Task <bool> HasInProgressBuildAsync(IBuildHttpClient client, int pipelineId, Guid projectId) { IPagedList <Build> builds = await client.GetBuildsAsync( projectId, definitions : new int[] { pipelineId }, statusFilter : BuildStatus.InProgress); return(builds.Any()); }
public IPagedList <Post> GetConsultRequestsPreview(IQueryable <Post> Posts, int?currentPage, int itemPerPage = 10, bool toSetLastPageIfCurrPageEmpty = true) { if (currentPage == null || currentPage <= 0) { currentPage = 1; } if (itemPerPage <= 0) { itemPerPage = 10; } IPagedList <Post> PostList = Posts != null?Posts.OrderBy(r => r.Id).ToPagedList((int)currentPage, itemPerPage) : null; if (toSetLastPageIfCurrPageEmpty && Posts.Any() && !PostList.Any()) { PostList = Posts != null?Posts.OrderBy(r => r.Id).ToPagedList(PostList.PageCount, itemPerPage) : null; } int previewPostLength = 15; foreach (Post Post in PostList) { if (!string.IsNullOrWhiteSpace(Post.Text) && Post.Text.Length > previewPostLength) { Post.Text = Post.Text.Substring(0, previewPostLength); int lastSpacePlace = Post.Text.LastIndexOf(' '); Post.Text = Post.Text.Substring(0, lastSpacePlace) + " ..."; } } return(PostList); }
public async Task<CategoryModel> Handle(GetCategory request, CancellationToken cancellationToken) { var model = request.Category.ToModel(request.Language); var customer = request.Customer; var storeId = request.Store.Id; var languageId = request.Language.Id; var currency = request.Currency; if (request.Command != null && request.Command.OrderBy == null && request.Category.DefaultSort >= 0) request.Command.OrderBy = request.Category.DefaultSort; //view/sorting/page size var options = await _mediator.Send(new GetViewSortSizeOptions() { Command = request.Command, PagingFilteringModel = request.Command, Language = request.Language, AllowCustomersToSelectPageSize = request.Category.AllowCustomersToSelectPageSize, PageSizeOptions = request.Category.PageSizeOptions, PageSize = request.Category.PageSize }); model.PagingFilteringContext = options.command; //price ranges model.PagingFilteringContext.PriceRangeFilter.LoadPriceRangeFilters(request.Category.PriceRanges, _webHelper, _priceFormatter); var selectedPriceRange = model.PagingFilteringContext.PriceRangeFilter.GetSelectedPriceRange(_webHelper, request.Category.PriceRanges); decimal? minPriceConverted = null; decimal? maxPriceConverted = null; if (selectedPriceRange != null) { if (selectedPriceRange.From.HasValue) minPriceConverted = await _currencyService.ConvertToPrimaryStoreCurrency(selectedPriceRange.From.Value, currency); if (selectedPriceRange.To.HasValue) maxPriceConverted = await _currencyService.ConvertToPrimaryStoreCurrency(selectedPriceRange.To.Value, currency); } //category breadcrumb if (_catalogSettings.CategoryBreadcrumbEnabled) { model.DisplayCategoryBreadcrumb = true; string breadcrumbCacheKey = string.Format(ModelCacheEventConst.CATEGORY_BREADCRUMB_KEY, request.Category.Id, string.Join(",", customer.GetCustomerRoleIds()), storeId, languageId); model.CategoryBreadcrumb = await _cacheManager.GetAsync(breadcrumbCacheKey, async () => (await _categoryService.GetCategoryBreadCrumb(request.Category)) .Select(catBr => new CategoryModel { Id = catBr.Id, Name = catBr.GetLocalized(x => x.Name, languageId), SeName = catBr.GetSeName(languageId) }) .ToList() ); } //subcategories var subCategories = new List<CategoryModel.SubCategoryModel>(); foreach (var x in (await _categoryService.GetAllCategoriesByParentCategoryId(request.Category.Id)).Where(x => !x.HideOnCatalog)) { var subCatModel = new CategoryModel.SubCategoryModel { Id = x.Id, Name = x.GetLocalized(y => y.Name, languageId), SeName = x.GetSeName(languageId), Description = x.GetLocalized(y => y.Description, languageId), Flag = x.Flag, FlagStyle = x.FlagStyle }; //prepare picture model subCatModel.PictureModel = new PictureModel { Id = x.PictureId, FullSizeImageUrl = await _pictureService.GetPictureUrl(x.PictureId), ImageUrl = await _pictureService.GetPictureUrl(x.PictureId, _mediaSettings.CategoryThumbPictureSize), Title = string.Format(_localizationService.GetResource("Media.Category.ImageLinkTitleFormat"), subCatModel.Name), AlternateText = string.Format(_localizationService.GetResource("Media.Category.ImageAlternateTextFormat"), subCatModel.Name) }; subCategories.Add(subCatModel); }; model.SubCategories = subCategories; //featured products if (!_catalogSettings.IgnoreFeaturedProducts) { //We cache a value indicating whether we have featured products IPagedList<Product> featuredProducts = null; string cacheKey = string.Format(ModelCacheEventConst.CATEGORY_HAS_FEATURED_PRODUCTS_KEY, request.Category.Id, string.Join(",", customer.GetCustomerRoleIds()), storeId); var hasFeaturedProductsCache = await _cacheManager.GetAsync<bool?>(cacheKey); if (!hasFeaturedProductsCache.HasValue) { //no value in the cache yet //let's load products and cache the result (true/false) featuredProducts = (await _mediator.Send(new GetSearchProductsQuery() { PageSize = _catalogSettings.LimitOfFeaturedProducts, CategoryIds = new List<string> { request.Category.Id }, Customer = request.Customer, StoreId = storeId, VisibleIndividuallyOnly = true, FeaturedProducts = true })).products; hasFeaturedProductsCache = featuredProducts.Any(); await _cacheManager.SetAsync(cacheKey, hasFeaturedProductsCache, CommonHelper.CacheTimeMinutes); } if (hasFeaturedProductsCache.Value && featuredProducts == null) { //cache indicates that the category has featured products //let's load them featuredProducts = (await _mediator.Send(new GetSearchProductsQuery() { PageSize = _catalogSettings.LimitOfFeaturedProducts, CategoryIds = new List<string> { request.Category.Id }, Customer = request.Customer, StoreId = storeId, VisibleIndividuallyOnly = true, FeaturedProducts = true })).products; } if (featuredProducts != null && featuredProducts.Any()) { model.FeaturedProducts = (await _mediator.Send(new GetProductOverview() { Products = featuredProducts, })).ToList(); } } var categoryIds = new List<string>(); categoryIds.Add(request.Category.Id); if (_catalogSettings.ShowProductsFromSubcategories) { //include subcategories categoryIds.AddRange(await _mediator.Send(new GetChildCategoryIds() { ParentCategoryId = request.Category.Id, Customer = request.Customer, Store = request.Store })); } //products IList<string> alreadyFilteredSpecOptionIds = await model.PagingFilteringContext.SpecificationFilter.GetAlreadyFilteredSpecOptionIds(_httpContextAccessor, _specificationAttributeService); var products = (await _mediator.Send(new GetSearchProductsQuery() { LoadFilterableSpecificationAttributeOptionIds = !_catalogSettings.IgnoreFilterableSpecAttributeOption, CategoryIds = categoryIds, Customer = request.Customer, StoreId = storeId, VisibleIndividuallyOnly = true, FeaturedProducts = _catalogSettings.IncludeFeaturedProductsInNormalLists ? null : (bool?)false, PriceMin = minPriceConverted, PriceMax = maxPriceConverted, FilteredSpecs = alreadyFilteredSpecOptionIds, OrderBy = (ProductSortingEnum)request.Command.OrderBy, PageIndex = request.Command.PageNumber - 1, PageSize = request.Command.PageSize })); model.Products = (await _mediator.Send(new GetProductOverview() { PrepareSpecificationAttributes = _catalogSettings.ShowSpecAttributeOnCatalogPages, Products = products.products, })).ToList(); model.PagingFilteringContext.LoadPagedList(products.products); //specs await model.PagingFilteringContext.SpecificationFilter.PrepareSpecsFilters(alreadyFilteredSpecOptionIds, products.filterableSpecificationAttributeOptionIds, _specificationAttributeService, _webHelper, _cacheManager, request.Language.Id); return model; }
public async Task <IList <CategoryModel> > Handle(GetCategoryFeaturedProducts request, CancellationToken cancellationToken) { string categoriesCacheKey = string.Format(ModelCacheEventConst.CATEGORY_FEATURED_PRODUCTS_HOMEPAGE_KEY, string.Join(",", request.Customer.GetCustomerRoleIds()), request.Store.Id, request.Language.Id); var model = await _cacheManager.GetAsync(categoriesCacheKey, async() => { var catlistmodel = new List <CategoryModel>(); foreach (var x in await _categoryService.GetAllCategoriesFeaturedProductsOnHomePage()) { var catModel = x.ToModel(request.Language); //prepare picture model catModel.PictureModel = new PictureModel { Id = x.PictureId, FullSizeImageUrl = await _pictureService.GetPictureUrl(x.PictureId), ImageUrl = await _pictureService.GetPictureUrl(x.PictureId, _mediaSettings.CategoryThumbPictureSize), Title = string.Format(_localizationService.GetResource("Media.Category.ImageLinkTitleFormat"), catModel.Name), AlternateText = string.Format(_localizationService.GetResource("Media.Category.ImageAlternateTextFormat"), catModel.Name) }; catlistmodel.Add(catModel); } return(catlistmodel); }); foreach (var item in model) { //We cache a value indicating whether we have featured products IPagedList <Product> featuredProducts = null; string cacheKey = string.Format(ModelCacheEventConst.CATEGORY_HAS_FEATURED_PRODUCTS_KEY, item.Id, string.Join(",", request.Customer.GetCustomerRoleIds()), request.Store.Id); var hasFeaturedProductsCache = await _cacheManager.GetAsync <bool?>(cacheKey); if (!hasFeaturedProductsCache.HasValue) { //no value in the cache yet //let's load products and cache the result (true/false) featuredProducts = (await _productService.SearchProducts( pageSize: _catalogSettings.LimitOfFeaturedProducts, categoryIds: new List <string> { item.Id }, storeId: request.Store.Id, visibleIndividuallyOnly: true, featuredProducts: true)).products; hasFeaturedProductsCache = featuredProducts.Any(); await _cacheManager.SetAsync(cacheKey, hasFeaturedProductsCache, CommonHelper.CacheTimeMinutes); } if (hasFeaturedProductsCache.Value && featuredProducts == null) { //cache indicates that the category has featured products //let's load them featuredProducts = (await _productService.SearchProducts( pageSize: _catalogSettings.LimitOfFeaturedProducts, categoryIds: new List <string> { item.Id }, storeId: request.Store.Id, visibleIndividuallyOnly: true, featuredProducts: true)).products; } if (featuredProducts != null) { item.FeaturedProducts = (await _mediator.Send(new GetProductOverview() { PrepareSpecificationAttributes = _catalogSettings.ShowSpecAttributeOnCatalogPages, Products = featuredProducts, })).ToList(); } } return(model); }
public async Task <IList <CollectionModel> > Handle(GetCollectionFeaturedProducts request, CancellationToken cancellationToken) { string manufCacheKey = string.Format(CacheKeyConst.COLLECTION_FEATURED_PRODUCT_HOMEPAGE_KEY, string.Join(",", request.Customer.GetCustomerGroupIds()), request.Store.Id, request.Language.Id); var model = await _cacheBase.GetAsync(manufCacheKey, async() => { var manufList = new List <CollectionModel>(); var manufmodel = await _collectionService.GetAllCollectionFeaturedProductsOnHomePage(); foreach (var x in manufmodel) { var manModel = x.ToModel(request.Language); //prepare picture model manModel.PictureModel = new PictureModel { Id = x.PictureId, FullSizeImageUrl = await _pictureService.GetPictureUrl(x.PictureId), ImageUrl = await _pictureService.GetPictureUrl(x.PictureId, _mediaSettings.CategoryThumbPictureSize), Title = string.Format(_translationService.GetResource("Media.Category.ImageLinkTitleFormat"), manModel.Name), AlternateText = string.Format(_translationService.GetResource("Media.Category.ImageAlternateTextFormat"), manModel.Name) }; manufList.Add(manModel); } return(manufList); }); foreach (var item in model) { //We cache a value indicating whether we have featured products IPagedList <Product> featuredProducts = null; string cacheKey = string.Format(CacheKeyConst.COLLECTION_HAS_FEATURED_PRODUCTS_KEY, item.Id, string.Join(",", request.Customer.GetCustomerGroupIds()), request.Store.Id); var hasFeaturedProductsCache = await _cacheBase.GetAsync <bool?>(cacheKey, async() => { featuredProducts = (await _mediator.Send(new GetSearchProductsQuery() { PageSize = _catalogSettings.LimitOfFeaturedProducts, CollectionId = item.Id, Customer = request.Customer, StoreId = request.Store.Id, VisibleIndividuallyOnly = true, FeaturedProducts = true })).products; return(featuredProducts.Any()); }); if (hasFeaturedProductsCache.Value && featuredProducts == null) { //cache indicates that the collection has featured products featuredProducts = (await _mediator.Send(new GetSearchProductsQuery() { PageSize = _catalogSettings.LimitOfFeaturedProducts, Customer = request.Customer, CollectionId = item.Id, StoreId = request.Store.Id, VisibleIndividuallyOnly = true, FeaturedProducts = true })).products; } if (featuredProducts != null && featuredProducts.Any()) { item.FeaturedProducts = (await _mediator.Send(new GetProductOverview() { Products = featuredProducts, })).ToList(); } } return(model); }
public async Task <ManufacturerModel> Handle(GetManufacturer request, CancellationToken cancellationToken) { var model = request.Manufacturer.ToModel(request.Language); if (request.Command != null && request.Command.OrderBy == null && request.Manufacturer.DefaultSort >= 0) { request.Command.OrderBy = request.Manufacturer.DefaultSort; } //view/sorting/page size var options = await _mediator.Send(new GetViewSortSizeOptions() { Command = request.Command, PagingFilteringModel = request.Command, Language = request.Language, AllowCustomersToSelectPageSize = request.Manufacturer.AllowCustomersToSelectPageSize, PageSizeOptions = request.Manufacturer.PageSizeOptions, PageSize = request.Manufacturer.PageSize }); model.PagingFilteringContext = options.command; //price ranges model.PagingFilteringContext.PriceRangeFilter.LoadPriceRangeFilters(request.Manufacturer.PriceRanges, _webHelper, _priceFormatter); var selectedPriceRange = model.PagingFilteringContext.PriceRangeFilter.GetSelectedPriceRange(_webHelper, request.Manufacturer.PriceRanges); decimal?minPriceConverted = null; decimal?maxPriceConverted = null; if (selectedPriceRange != null) { if (selectedPriceRange.From.HasValue) { minPriceConverted = await _currencyService.ConvertToPrimaryStoreCurrency(selectedPriceRange.From.Value, request.Currency); } if (selectedPriceRange.To.HasValue) { maxPriceConverted = await _currencyService.ConvertToPrimaryStoreCurrency(selectedPriceRange.To.Value, request.Currency); } } //featured products if (!_catalogSettings.IgnoreFeaturedProducts) { IPagedList <Product> featuredProducts = null; //We cache a value indicating whether we have featured products string cacheKey = string.Format(ModelCacheEventConst.MANUFACTURER_HAS_FEATURED_PRODUCTS_KEY, request.Manufacturer.Id, string.Join(",", request.Customer.GetCustomerRoleIds()), request.Store.Id); var hasFeaturedProductsCache = await _cacheManager.GetAsync <bool?>(cacheKey); if (!hasFeaturedProductsCache.HasValue) { //no value in the cache yet //let's load products and cache the result (true/false) featuredProducts = (await _mediator.Send(new GetSearchProductsQuery() { PageSize = _catalogSettings.LimitOfFeaturedProducts, ManufacturerId = request.Manufacturer.Id, Customer = request.Customer, StoreId = request.Store.Id, VisibleIndividuallyOnly = true, FeaturedProducts = true })).products; hasFeaturedProductsCache = featuredProducts.Any(); await _cacheManager.SetAsync(cacheKey, hasFeaturedProductsCache, CommonHelper.CacheTimeMinutes); } if (hasFeaturedProductsCache.Value && featuredProducts == null) { //cache indicates that the manufacturer has featured products //let's load them featuredProducts = (await _mediator.Send(new GetSearchProductsQuery() { PageSize = _catalogSettings.LimitOfFeaturedProducts, ManufacturerId = request.Manufacturer.Id, Customer = request.Customer, StoreId = request.Store.Id, VisibleIndividuallyOnly = true, FeaturedProducts = true })).products; } if (featuredProducts != null && featuredProducts.Any()) { model.FeaturedProducts = (await _mediator.Send(new GetProductOverview() { Products = featuredProducts, })).ToList(); } } IList <string> alreadyFilteredSpecOptionIds = await model.PagingFilteringContext.SpecificationFilter.GetAlreadyFilteredSpecOptionIds (_httpContextAccessor, _specificationAttributeService); var products = (await _mediator.Send(new GetSearchProductsQuery() { LoadFilterableSpecificationAttributeOptionIds = !_catalogSettings.IgnoreFilterableSpecAttributeOption, ManufacturerId = request.Manufacturer.Id, Customer = request.Customer, StoreId = request.Store.Id, VisibleIndividuallyOnly = true, FeaturedProducts = _catalogSettings.IncludeFeaturedProductsInNormalLists ? null : (bool?)false, PriceMin = minPriceConverted, PriceMax = maxPriceConverted, FilteredSpecs = alreadyFilteredSpecOptionIds, OrderBy = (ProductSortingEnum)request.Command.OrderBy, PageIndex = request.Command.PageNumber - 1, PageSize = request.Command.PageSize })); model.Products = (await _mediator.Send(new GetProductOverview() { Products = products.products, PrepareSpecificationAttributes = _catalogSettings.ShowSpecAttributeOnCatalogPages })).ToList(); model.PagingFilteringContext.LoadPagedList(products.products); //specs await model.PagingFilteringContext.SpecificationFilter.PrepareSpecsFilters(alreadyFilteredSpecOptionIds, products.filterableSpecificationAttributeOptionIds, _specificationAttributeService, _webHelper, _cacheManager, request.Language.Id); return(model); }
public async Task <IList <ManufacturerModel> > Handle(GetManufacturerFeaturedProducts request, CancellationToken cancellationToken) { string manufCacheKey = string.Format(ModelCacheEventConst.MANUFACTURER_FEATURED_PRODUCT_HOMEPAGE_KEY, string.Join(",", request.Customer.GetCustomerRoleIds()), request.Store.Id, request.Language.Id); var model = await _cacheManager.GetAsync(manufCacheKey, async() => { var manufList = new List <ManufacturerModel>(); var manufmodel = await _manufacturerService.GetAllManufacturerFeaturedProductsOnHomePage(); foreach (var x in manufmodel) { var manModel = x.ToModel(request.Language); //prepare picture model manModel.PictureModel = new PictureModel { Id = x.PictureId, FullSizeImageUrl = await _pictureService.GetPictureUrl(x.PictureId), ImageUrl = await _pictureService.GetPictureUrl(x.PictureId, _mediaSettings.CategoryThumbPictureSize), Title = string.Format(_localizationService.GetResource("Media.Category.ImageLinkTitleFormat"), manModel.Name), AlternateText = string.Format(_localizationService.GetResource("Media.Category.ImageAlternateTextFormat"), manModel.Name) }; manufList.Add(manModel); } return(manufList); }); foreach (var item in model) { //We cache a value indicating whether we have featured products IPagedList <Product> featuredProducts = null; string cacheKey = string.Format(ModelCacheEventConst.MANUFACTURER_HAS_FEATURED_PRODUCTS_KEY, item.Id, string.Join(",", request.Customer.GetCustomerRoleIds()), request.Store.Id); var hasFeaturedProductsCache = await _cacheManager.GetAsync <bool?>(cacheKey); if (!hasFeaturedProductsCache.HasValue) { //no value in the cache yet //let's load products and cache the result (true/false) featuredProducts = (await _mediator.Send(new GetSearchProductsQuery() { PageSize = _catalogSettings.LimitOfFeaturedProducts, ManufacturerId = item.Id, Customer = request.Customer, StoreId = request.Store.Id, VisibleIndividuallyOnly = true, FeaturedProducts = true })).products; hasFeaturedProductsCache = featuredProducts.Any(); await _cacheManager.SetAsync(cacheKey, hasFeaturedProductsCache, CommonHelper.CacheTimeMinutes); } if (hasFeaturedProductsCache.Value && featuredProducts == null) { //cache indicates that the manufacturer has featured products //let's load them featuredProducts = (await _mediator.Send(new GetSearchProductsQuery() { PageSize = _catalogSettings.LimitOfFeaturedProducts, Customer = request.Customer, ManufacturerId = item.Id, StoreId = request.Store.Id, VisibleIndividuallyOnly = true, FeaturedProducts = true })).products; } if (featuredProducts != null && featuredProducts.Any()) { item.FeaturedProducts = (await _mediator.Send(new GetProductOverview() { Products = featuredProducts, })).ToList(); } } return(model); }