Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Remove IHttpContextAccessor from method filter specification option

KrzysztofPajak937aa274ac66
diff --git a/src/Web/Grand.Web/Features/Handlers/Catalog/GetBrandHandler.cs b/src/Web/Grand.Web/Features/Handlers/Catalog/GetBrandHandler.cs
index 33cc1b89d..813a1ad8e 100644
--- a/src/Web/Grand.Web/Features/Handlers/Catalog/GetBrandHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Catalog/GetBrandHandler.cs
@@ -8,6 +8,7 @@ using Grand.Web.Features.Models.Products;
using Grand.Web.Models.Catalog;
using MediatR;
using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Extensions;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@@ -58,7 +59,7 @@ namespace Grand.Web.Features.Handlers.Catalog
model.PagingFilteringContext = options.command;
IList<string> alreadyFilteredSpecOptionIds = await model.PagingFilteringContext.SpecificationFilter.GetAlreadyFilteredSpecOptionIds
- (_httpContextAccessor, _specificationAttributeService);
+ (_httpContextAccessor.HttpContext.Request.Query, _specificationAttributeService);
var products = (await _mediator.Send(new GetSearchProductsQuery()
{
@@ -85,7 +86,7 @@ namespace Grand.Web.Features.Handlers.Catalog
//specs
await model.PagingFilteringContext.SpecificationFilter.PrepareSpecsFilters(alreadyFilteredSpecOptionIds,
products.filterableSpecificationAttributeOptionIds,
- _specificationAttributeService, _httpContextAccessor, _cacheBase, request.Language.Id);
+ _specificationAttributeService, _httpContextAccessor.HttpContext.Request.GetDisplayUrl(), request.Language.Id);
return model;
}
diff --git a/src/Web/Grand.Web/Features/Handlers/Catalog/GetCategoryHandler.cs b/src/Web/Grand.Web/Features/Handlers/Catalog/GetCategoryHandler.cs
index d83ed6b1f..559ee2bf6 100644
--- a/src/Web/Grand.Web/Features/Handlers/Catalog/GetCategoryHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Catalog/GetCategoryHandler.cs
@@ -9,14 +9,15 @@ using Grand.Domain.Catalog;
using Grand.Domain.Customers;
using Grand.Domain.Media;
using Grand.Infrastructure.Caching;
+using Grand.Web.Events.Cache;
using Grand.Web.Extensions;
using Grand.Web.Features.Models.Catalog;
using Grand.Web.Features.Models.Products;
-using Grand.Web.Events.Cache;
using Grand.Web.Models.Catalog;
using Grand.Web.Models.Media;
using MediatR;
using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Extensions;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@@ -70,8 +71,7 @@ namespace Grand.Web.Features.Handlers.Catalog
request.Command.OrderBy = request.Category.DefaultSort;
//view/sorting/page size
- var options = await _mediator.Send(new GetViewSortSizeOptions()
- {
+ var options = await _mediator.Send(new GetViewSortSizeOptions() {
Command = request.Command,
PagingFilteringModel = request.Command,
Language = request.Language,
@@ -94,8 +94,7 @@ namespace Grand.Web.Features.Handlers.Catalog
languageId);
model.CategoryBreadcrumb = await _cacheBase.GetAsync(breadcrumbCacheKey, async () =>
(await _categoryService.GetCategoryBreadCrumb(request.Category))
- .Select(catBr => new CategoryModel
- {
+ .Select(catBr => new CategoryModel {
Id = catBr.Id,
Name = catBr.GetTranslation(x => x.Name, languageId),
SeName = catBr.GetSeName(languageId)
@@ -108,8 +107,7 @@ namespace Grand.Web.Features.Handlers.Catalog
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
- {
+ var subCatModel = new CategoryModel.SubCategoryModel {
Id = x.Id,
Name = x.GetTranslation(y => y.Name, languageId),
SeName = x.GetSeName(languageId),
@@ -119,8 +117,7 @@ namespace Grand.Web.Features.Handlers.Catalog
};
//prepare picture model
var picture = !string.IsNullOrEmpty(x.PictureId) ? await _pictureService.GetPictureById(x.PictureId) : null;
- subCatModel.PictureModel = new PictureModel
- {
+ subCatModel.PictureModel = new PictureModel {
Id = x.PictureId,
FullSizeImageUrl = await _pictureService.GetPictureUrl(x.PictureId),
ImageUrl = await _pictureService.GetPictureUrl(x.PictureId, _mediaSettings.CategoryThumbPictureSize),
@@ -149,8 +146,7 @@ namespace Grand.Web.Features.Handlers.Catalog
var hasFeaturedProductsCache = await _cacheBase.GetAsync<bool?>(cacheKey, async () =>
{
- featuredProducts = (await _mediator.Send(new GetSearchProductsQuery()
- {
+ featuredProducts = (await _mediator.Send(new GetSearchProductsQuery() {
PageSize = _catalogSettings.LimitOfFeaturedProducts,
CategoryIds = new List<string> { request.Category.Id },
Customer = request.Customer,
@@ -164,8 +160,7 @@ namespace Grand.Web.Features.Handlers.Catalog
if (hasFeaturedProductsCache.Value && featuredProducts == null)
{
//cache indicates that the category has featured products
- featuredProducts = (await _mediator.Send(new GetSearchProductsQuery()
- {
+ featuredProducts = (await _mediator.Send(new GetSearchProductsQuery() {
PageSize = _catalogSettings.LimitOfFeaturedProducts,
CategoryIds = new List<string> { request.Category.Id },
Customer = request.Customer,
@@ -176,8 +171,7 @@ namespace Grand.Web.Features.Handlers.Catalog
}
if (featuredProducts != null && featuredProducts.Any())
{
- model.FeaturedProducts = (await _mediator.Send(new GetProductOverview()
- {
+ model.FeaturedProducts = (await _mediator.Send(new GetProductOverview() {
Products = featuredProducts,
})).ToList();
}
@@ -192,9 +186,9 @@ namespace Grand.Web.Features.Handlers.Catalog
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()
- {
+ IList<string> alreadyFilteredSpecOptionIds = await model.PagingFilteringContext.SpecificationFilter.GetAlreadyFilteredSpecOptionIds(
+ _httpContextAccessor.HttpContext.Request.Query, _specificationAttributeService);
+ var products = (await _mediator.Send(new GetSearchProductsQuery() {
LoadFilterableSpecificationAttributeOptionIds = !_catalogSettings.IgnoreFilterableSpecAttributeOption,
CategoryIds = categoryIds,
Customer = request.Customer,
@@ -207,8 +201,7 @@ namespace Grand.Web.Features.Handlers.Catalog
PageSize = request.Command.PageSize
}));
- model.Products = (await _mediator.Send(new GetProductOverview()
- {
+ model.Products = (await _mediator.Send(new GetProductOverview() {
PrepareSpecificationAttributes = _catalogSettings.ShowSpecAttributeOnCatalogPages,
Products = products.products,
})).ToList();
@@ -218,7 +211,7 @@ namespace Grand.Web.Features.Handlers.Catalog
//specs
await model.PagingFilteringContext.SpecificationFilter.PrepareSpecsFilters(alreadyFilteredSpecOptionIds,
products.filterableSpecificationAttributeOptionIds,
- _specificationAttributeService, _httpContextAccessor, _cacheBase, request.Language.Id);
+ _specificationAttributeService, _httpContextAccessor.HttpContext.Request.GetDisplayUrl(), request.Language.Id);
return model;
}
diff --git a/src/Web/Grand.Web/Features/Handlers/Catalog/GetCollectionHandler.cs b/src/Web/Grand.Web/Features/Handlers/Catalog/GetCollectionHandler.cs
index 82354c030..51fe1335a 100644
--- a/src/Web/Grand.Web/Features/Handlers/Catalog/GetCollectionHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Catalog/GetCollectionHandler.cs
@@ -4,13 +4,14 @@ using Grand.Domain;
using Grand.Domain.Catalog;
using Grand.Domain.Customers;
using Grand.Infrastructure.Caching;
+using Grand.Web.Events.Cache;
using Grand.Web.Extensions;
using Grand.Web.Features.Models.Catalog;
using Grand.Web.Features.Models.Products;
-using Grand.Web.Events.Cache;
using Grand.Web.Models.Catalog;
using MediatR;
using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Extensions;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@@ -49,8 +50,7 @@ namespace Grand.Web.Features.Handlers.Catalog
request.Command.OrderBy = request.Collection.DefaultSort;
//view/sorting/page size
- var options = await _mediator.Send(new GetViewSortSizeOptions()
- {
+ var options = await _mediator.Send(new GetViewSortSizeOptions() {
Command = request.Command,
PagingFilteringModel = request.Command,
Language = request.Language,
@@ -72,8 +72,7 @@ namespace Grand.Web.Features.Handlers.Catalog
request.Store.Id);
var hasFeaturedProductsCache = await _cacheBase.GetAsync<bool?>(cacheKey, async () =>
{
- var featuredProducts = (await _mediator.Send(new GetSearchProductsQuery()
- {
+ var featuredProducts = (await _mediator.Send(new GetSearchProductsQuery() {
PageSize = _catalogSettings.LimitOfFeaturedProducts,
CollectionId = request.Collection.Id,
Customer = request.Customer,
@@ -86,8 +85,7 @@ namespace Grand.Web.Features.Handlers.Catalog
if (hasFeaturedProductsCache.Value && featuredProducts == null)
{
//cache indicates that the collection has featured products
- featuredProducts = (await _mediator.Send(new GetSearchProductsQuery()
- {
+ featuredProducts = (await _mediator.Send(new GetSearchProductsQuery() {
PageSize = _catalogSettings.LimitOfFeaturedProducts,
CollectionId = request.Collection.Id,
Customer = request.Customer,
@@ -98,18 +96,16 @@ namespace Grand.Web.Features.Handlers.Catalog
}
if (featuredProducts != null && featuredProducts.Any())
{
- model.FeaturedProducts = (await _mediator.Send(new GetProductOverview()
- {
+ model.FeaturedProducts = (await _mediator.Send(new GetProductOverview() {
Products = featuredProducts,
})).ToList();
}
}
IList<string> alreadyFilteredSpecOptionIds = await model.PagingFilteringContext.SpecificationFilter.GetAlreadyFilteredSpecOptionIds
- (_httpContextAccessor, _specificationAttributeService);
+ (_httpContextAccessor.HttpContext.Request.Query, _specificationAttributeService);
- var products = (await _mediator.Send(new GetSearchProductsQuery()
- {
+ var products = (await _mediator.Send(new GetSearchProductsQuery() {
LoadFilterableSpecificationAttributeOptionIds = !_catalogSettings.IgnoreFilterableSpecAttributeOption,
CollectionId = request.Collection.Id,
Customer = request.Customer,
@@ -122,8 +118,7 @@ namespace Grand.Web.Features.Handlers.Catalog
PageSize = request.Command.PageSize
}));
- model.Products = (await _mediator.Send(new GetProductOverview()
- {
+ model.Products = (await _mediator.Send(new GetProductOverview() {
Products = products.products,
PrepareSpecificationAttributes = _catalogSettings.ShowSpecAttributeOnCatalogPages
})).ToList();
@@ -133,7 +128,7 @@ namespace Grand.Web.Features.Handlers.Catalog
//specs
await model.PagingFilteringContext.SpecificationFilter.PrepareSpecsFilters(alreadyFilteredSpecOptionIds,
products.filterableSpecificationAttributeOptionIds,
- _specificationAttributeService, _httpContextAccessor, _cacheBase, request.Language.Id);
+ _specificationAttributeService, _httpContextAccessor.HttpContext.Request.GetDisplayUrl(), request.Language.Id);
return model;
}
diff --git a/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchHandler.cs b/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchHandler.cs
index f61bf7b7a..42f6215ad 100644
--- a/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchHandler.cs
@@ -18,6 +18,7 @@ using Grand.Web.Features.Models.Products;
using Grand.Web.Models.Catalog;
using MediatR;
using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc.Rendering;
using System;
using System.Collections.Generic;
@@ -229,7 +230,7 @@ namespace Grand.Web.Features.Handlers.Catalog
var searchInProductTags = searchInDescriptions;
IList<string> alreadyFilteredSpecOptionIds = await request.Model.PagingFilteringContext.SpecificationFilter.GetAlreadyFilteredSpecOptionIds
- (_httpContextAccessor, _specificationAttributeService);
+ (_httpContextAccessor.HttpContext.Request.Query, _specificationAttributeService);
//products
var searchproducts = (await _mediator.Send(new GetSearchProductsQuery() {
@@ -263,7 +264,7 @@ namespace Grand.Web.Features.Handlers.Catalog
//specs
await request.Model.PagingFilteringContext.SpecificationFilter.PrepareSpecsFilters(alreadyFilteredSpecOptionIds,
searchproducts.filterableSpecificationAttributeOptionIds,
- _specificationAttributeService, _httpContextAccessor, _cacheBase, request.Language.Id);
+ _specificationAttributeService, _httpContextAccessor.HttpContext.Request.GetDisplayUrl(), request.Language.Id);
request.Model.NoResults = !request.Model.Products.Any();
diff --git a/src/Web/Grand.Web/Features/Handlers/Catalog/GetVendorHandler.cs b/src/Web/Grand.Web/Features/Handlers/Catalog/GetVendorHandler.cs
index a19fb9fb7..236a52e9f 100644
--- a/src/Web/Grand.Web/Features/Handlers/Catalog/GetVendorHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Catalog/GetVendorHandler.cs
@@ -14,6 +14,7 @@ using Grand.Web.Models.Catalog;
using Grand.Web.Models.Media;
using MediatR;
using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Extensions;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@@ -58,8 +59,7 @@ namespace Grand.Web.Features.Handlers.Catalog
public async Task<VendorModel> Handle(GetVendor request, CancellationToken cancellationToken)
{
- var model = new VendorModel
- {
+ var model = new VendorModel {
Id = request.Vendor.Id,
Name = request.Vendor.GetTranslation(x => x.Name, request.Language.Id),
Description = request.Vendor.GetTranslation(x => x.Description, request.Language.Id),
@@ -71,16 +71,14 @@ namespace Grand.Web.Features.Handlers.Catalog
UserFields = request.Vendor.UserFields
};
- model.Address = await _mediator.Send(new GetVendorAddress()
- {
+ model.Address = await _mediator.Send(new GetVendorAddress() {
Language = request.Language,
Address = request.Vendor.Address,
ExcludeProperties = false,
});
//prepare picture model
- var pictureModel = new PictureModel
- {
+ var pictureModel = new PictureModel {
Id = request.Vendor.PictureId,
FullSizeImageUrl = await _pictureService.GetPictureUrl(request.Vendor.PictureId),
ImageUrl = await _pictureService.GetPictureUrl(request.Vendor.PictureId, _mediaSettings.VendorThumbPictureSize),
@@ -90,8 +88,7 @@ namespace Grand.Web.Features.Handlers.Catalog
model.PictureModel = pictureModel;
//view/sorting/page size
- var options = await _mediator.Send(new GetViewSortSizeOptions()
- {
+ var options = await _mediator.Send(new GetViewSortSizeOptions() {
Command = request.Command,
PagingFilteringModel = request.Command,
Language = request.Language,
@@ -102,11 +99,10 @@ namespace Grand.Web.Features.Handlers.Catalog
model.PagingFilteringContext = options.command;
IList<string> alreadyFilteredSpecOptionIds = await model.PagingFilteringContext.SpecificationFilter.GetAlreadyFilteredSpecOptionIds
- (_httpContextAccessor, _specificationAttributeService);
+ (_httpContextAccessor.HttpContext.Request.Query, _specificationAttributeService);
//products
- var products = (await _mediator.Send(new GetSearchProductsQuery()
- {
+ var products = (await _mediator.Send(new GetSearchProductsQuery() {
LoadFilterableSpecificationAttributeOptionIds = !_catalogSettings.IgnoreFilterableSpecAttributeOption,
Customer = request.Customer,
VendorId = request.Vendor.Id,
@@ -118,8 +114,7 @@ namespace Grand.Web.Features.Handlers.Catalog
PageSize = request.Command.PageSize
}));
- model.Products = (await _mediator.Send(new GetProductOverview()
- {
+ model.Products = (await _mediator.Send(new GetProductOverview() {
Products = products.products,
PrepareSpecificationAttributes = _catalogSettings.ShowSpecAttributeOnCatalogPages
})).ToList();
@@ -129,7 +124,7 @@ namespace Grand.Web.Features.Handlers.Catalog
//specs
await model.PagingFilteringContext.SpecificationFilter.PrepareSpecsFilters(alreadyFilteredSpecOptionIds,
products.filterableSpecificationAttributeOptionIds,
- _specificationAttributeService, _httpContextAccessor, _cacheBase, request.Language.Id);
+ _specificationAttributeService, _httpContextAccessor.HttpContext.Request.GetDisplayUrl(), request.Language.Id);
return model;
}
diff --git a/src/Web/Grand.Web/Models/Catalog/CatalogPagingFilteringModel.cs b/src/Web/Grand.Web/Models/Catalog/CatalogPagingFilteringModel.cs
index 1b0fd097d..1dd5d483c 100644
--- a/src/Web/Grand.Web/Models/Catalog/CatalogPagingFilteringModel.cs
+++ b/src/Web/Grand.Web/Models/Catalog/CatalogPagingFilteringModel.cs
@@ -1,13 +1,10 @@
using Grand.Business.Catalog.Interfaces.Products;
using Grand.Business.Common.Extensions;
-using Grand.Web.Common.Page.Paging;
using Grand.Domain.Catalog;
-using Grand.Infrastructure;
-using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Extensions;
using Grand.Infrastructure.Models;
+using Grand.Web.Common.Page.Paging;
using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc.Rendering;
using System;
using System.Collections.Generic;
@@ -102,11 +99,11 @@ namespace Grand.Web.Models.Catalog
#region Methods
public virtual async Task<List<string>> GetAlreadyFilteredSpecOptionIds
- (IHttpContextAccessor httpContextAccessor, ISpecificationAttributeService specificationAttributeService)
+ (IQueryCollection query, ISpecificationAttributeService specificationAttributeService)
{
var result = new List<string>();
- foreach (var item in httpContextAccessor.HttpContext.Request.Query)
+ foreach (var item in query)
{
var spec = await specificationAttributeService.GetSpecificationAttributeBySeName(item.Key);
if (spec != null)
@@ -133,8 +130,7 @@ namespace Grand.Web.Models.Catalog
public virtual async Task PrepareSpecsFilters(IList<string> alreadyFilteredSpecOptionIds,
IList<string> filterableSpecificationAttributeOptionIds,
ISpecificationAttributeService specificationAttributeService,
- IHttpContextAccessor httpContextAccessor,
- ICacheBase cacheBase, string langId)
+ string url, string langId)
{
Enabled = false;
@@ -144,8 +140,7 @@ namespace Grand.Web.Models.Catalog
var sa = await specificationAttributeService.GetSpecificationAttributeByOptionId(sao);
if (sa != null)
{
- allFilters.Add(new SpecificationAttributeOptionFilter
- {
+ allFilters.Add(new SpecificationAttributeOptionFilter {
SpecificationAttributeId = sa.Id,
SpecificationAttributeName = sa.GetTranslation(x => x.Name, langId),
SpecificationAttributeSeName = sa.SeName,
@@ -170,7 +165,7 @@ namespace Grand.Web.Models.Catalog
//prepare the model properties
Enabled = true;
- string removeFilterUrl = httpContextAccessor.HttpContext.Request.GetDisplayUrl();
+ var removeFilterUrl = url;
foreach (var item in allFilters.GroupBy(x => x.SpecificationAttributeSeName))
{
removeFilterUrl = CommonExtensions.ModifyQueryString(removeFilterUrl, item.Key, null);
@@ -184,10 +179,9 @@ namespace Grand.Web.Models.Catalog
var alreadyFiltered = alreadyFilteredOptions.Where(y => y.SpecificationAttributeId == x.SpecificationAttributeId).Select(z => z.SpecificationAttributeOptionSeName)
.Except(new List<string> { x.SpecificationAttributeOptionSeName }).ToList();
- var filterUrl = CommonExtensions.ModifyQueryString(httpContextAccessor.HttpContext.Request.GetDisplayUrl(), x.SpecificationAttributeSeName, GenerateFilteredSpecQueryParam(alreadyFiltered));
+ var filterUrl = CommonExtensions.ModifyQueryString(url, x.SpecificationAttributeSeName, GenerateFilteredSpecQueryParam(alreadyFiltered));
- return new SpecificationFilterItem
- {
+ return new SpecificationFilterItem {
SpecificationAttributeName = x.SpecificationAttributeName,
SpecificationAttributeSeName = x.SpecificationAttributeSeName,
SpecificationAttributeOptionName = x.SpecificationAttributeOptionName,
@@ -204,9 +198,8 @@ namespace Grand.Web.Models.Catalog
var alreadyFiltered = alreadyFilteredOptions.Where(y => y.SpecificationAttributeId == x.SpecificationAttributeId).Select(x => x.SpecificationAttributeOptionSeName)
.Concat(new List<string> { x.SpecificationAttributeOptionSeName });
- var filterUrl = CommonExtensions.ModifyQueryString(httpContextAccessor.HttpContext.Request.GetDisplayUrl(), x.SpecificationAttributeSeName, GenerateFilteredSpecQueryParam(alreadyFiltered.ToList()));
- return new SpecificationFilterItem()
- {
+ var filterUrl = CommonExtensions.ModifyQueryString(url, x.SpecificationAttributeSeName, GenerateFilteredSpecQueryParam(alreadyFiltered.ToList()));
+ return new SpecificationFilterItem() {
SpecificationAttributeName = x.SpecificationAttributeName,
SpecificationAttributeSeName = x.SpecificationAttributeSeName,
SpecificationAttributeOptionName = x.SpecificationAttributeOptionName,