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.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
API - Refactoring mongodb
KrzysztofPajakcfd82ae697d1
diff --git a/src/API/Grand.Api/Controllers/OData/ProductController.cs b/src/API/Grand.Api/Controllers/OData/ProductController.csindex b45f51070..a07feef22 100644--- a/src/API/Grand.Api/Controllers/OData/ProductController.cs+++ b/src/API/Grand.Api/Controllers/OData/ProductController.cs@@ -167,7 +167,7 @@ namespace Grand.Api.Controllers.ODataif (!product.Any())return NotFound();- var pc = product.FirstOrDefault().Categories.Where(x => x.CategoryId == productCategory.CategoryId).FirstOrDefault();+ var pc = product.FirstOrDefault().ProductCategories.Where(x => x.CategoryId == productCategory.CategoryId).FirstOrDefault();if (pc != null)ModelState.AddModelError("", "Product category mapping found with the specified categoryid");@@ -195,7 +195,7 @@ namespace Grand.Api.Controllers.ODatareturn NotFound();- var pc = product.FirstOrDefault().Categories.Where(x => x.CategoryId == productCategory.CategoryId).FirstOrDefault();+ var pc = product.FirstOrDefault().ProductCategories.Where(x => x.CategoryId == productCategory.CategoryId).FirstOrDefault();if (pc == null)ModelState.AddModelError("", "No product category mapping found with the specified id");@@ -226,7 +226,7 @@ namespace Grand.Api.Controllers.ODatavar categoryId = parameters.FirstOrDefault(x => x.Key == "CategoryId").Value;if (categoryId != null){- var pc = product.FirstOrDefault().Categories.Where(x => x.CategoryId == categoryId.ToString()).FirstOrDefault();+ var pc = product.FirstOrDefault().ProductCategories.Where(x => x.CategoryId == categoryId.ToString()).FirstOrDefault();if (pc == null)ModelState.AddModelError("", "No product category mapping found with the specified id");@@ -260,7 +260,7 @@ namespace Grand.Api.Controllers.ODatareturn NotFound();- var pm = product.FirstOrDefault().Collections.Where(x => x.CollectionId == productCollection.CollectionId).FirstOrDefault();+ var pm = product.FirstOrDefault().ProductCollections.Where(x => x.CollectionId == productCollection.CollectionId).FirstOrDefault();if (pm != null)ModelState.AddModelError("", "Product collection mapping found with the specified collectionid");@@ -287,7 +287,7 @@ namespace Grand.Api.Controllers.ODataif (!product.Any())return NotFound();- var pm = product.FirstOrDefault().Collections.Where(x => x.CollectionId == productCollection.CollectionId).FirstOrDefault();+ var pm = product.FirstOrDefault().ProductCollections.Where(x => x.CollectionId == productCollection.CollectionId).FirstOrDefault();if (pm == null)ModelState.AddModelError("", "No product collection mapping found with the specified id");@@ -317,7 +317,7 @@ namespace Grand.Api.Controllers.ODatavar collectionId = parameters.FirstOrDefault(x => x.Key == "CollectionId").Value;if (collectionId != null){- var pm = product.FirstOrDefault().Collections.Where(x => x.CollectionId == collectionId.ToString()).FirstOrDefault();+ var pm = product.FirstOrDefault().ProductCollections.Where(x => x.CollectionId == collectionId.ToString()).FirstOrDefault();if (pm == null)ModelState.AddModelError("", "No product collection mapping found with the specified id");@@ -351,7 +351,7 @@ namespace Grand.Api.Controllers.ODatareturn NotFound();- var pp = product.FirstOrDefault().Pictures.Where(x => x.PictureId == productPicture.PictureId).FirstOrDefault();+ var pp = product.FirstOrDefault().ProductPictures.Where(x => x.PictureId == productPicture.PictureId).FirstOrDefault();if (pp != null)ModelState.AddModelError("", "Product picture mapping found with the specified pictureid");@@ -379,7 +379,7 @@ namespace Grand.Api.Controllers.ODatareturn NotFound();- var pp = product.FirstOrDefault().Pictures.Where(x => x.PictureId == productPicture.PictureId).FirstOrDefault();+ var pp = product.FirstOrDefault().ProductPictures.Where(x => x.PictureId == productPicture.PictureId).FirstOrDefault();if (pp == null)ModelState.AddModelError("", "No product picture mapping found with the specified id");@@ -410,7 +410,7 @@ namespace Grand.Api.Controllers.ODatavar pictureId = parameters.FirstOrDefault(x => x.Key == "PictureId").Value;if (pictureId != null){- var pp = product.FirstOrDefault().Pictures.Where(x => x.PictureId == pictureId.ToString()).FirstOrDefault();+ var pp = product.FirstOrDefault().ProductPictures.Where(x => x.PictureId == pictureId.ToString()).FirstOrDefault();if (pp == null)ModelState.AddModelError("", "No product picture mapping found with the specified id");@@ -443,7 +443,7 @@ namespace Grand.Api.Controllers.ODataif (!product.Any())return NotFound();- var psa = product.FirstOrDefault().SpecificationAttribute.Where(x => x.Id == productSpecification.Id).FirstOrDefault();+ var psa = product.FirstOrDefault().ProductSpecificationAttributes.Where(x => x.Id == productSpecification.Id).FirstOrDefault();if (psa != null)ModelState.AddModelError("", "Product specification mapping found with the specified id");@@ -470,7 +470,7 @@ namespace Grand.Api.Controllers.ODataif (!product.Any())return NotFound();- var psa = product.FirstOrDefault().SpecificationAttribute.Where(x => x.Id == productSpecification.Id).FirstOrDefault();+ var psa = product.FirstOrDefault().ProductSpecificationAttributes.Where(x => x.Id == productSpecification.Id).FirstOrDefault();if (psa == null)ModelState.AddModelError("", "No product specification mapping found with the specified id");@@ -501,7 +501,7 @@ namespace Grand.Api.Controllers.ODatavar specificationId = parameters.FirstOrDefault(x => x.Key == "Id").Value;if (specificationId != null){- var psa = product.FirstOrDefault().SpecificationAttribute.Where(x => x.Id == specificationId.ToString()).FirstOrDefault();+ var psa = product.FirstOrDefault().ProductSpecificationAttributes.Where(x => x.Id == specificationId.ToString()).FirstOrDefault();if (psa == null)ModelState.AddModelError("", "No product specification mapping found with the specified id");@@ -624,7 +624,7 @@ namespace Grand.Api.Controllers.ODataif (!product.Any())return NotFound();- var pam = product.FirstOrDefault().AttributeMappings.Where(x => x.Id == productAttributeMapping.Id).FirstOrDefault();+ var pam = product.FirstOrDefault().ProductAttributeMappings.Where(x => x.Id == productAttributeMapping.Id).FirstOrDefault();if (pam != null)ModelState.AddModelError("", "Product attribute mapping found with the specified id");@@ -651,7 +651,7 @@ namespace Grand.Api.Controllers.ODataif (!product.Any())return NotFound();- var pam = product.FirstOrDefault().AttributeMappings.Where(x => x.Id == productAttributeMapping.Id).FirstOrDefault();+ var pam = product.FirstOrDefault().ProductAttributeMappings.Where(x => x.Id == productAttributeMapping.Id).FirstOrDefault();if (pam == null)ModelState.AddModelError("", "No product attribute mapping found with the specified id");@@ -682,7 +682,7 @@ namespace Grand.Api.Controllers.ODatavar attrId = parameters.FirstOrDefault(x => x.Key == "Id").Value;if (attrId != null){- var pam = product.FirstOrDefault().AttributeMappings.Where(x => x.Id == attrId.ToString()).FirstOrDefault();+ var pam = product.FirstOrDefault().ProductAttributeMappings.Where(x => x.Id == attrId.ToString()).FirstOrDefault();if (pam == null)ModelState.AddModelError("", "No product attribute mapping found with the specified id");diff --git a/src/API/Grand.Api/DTOs/Catalog/ProductAttributeMappingDto.cs b/src/API/Grand.Api/DTOs/Catalog/ProductAttributeMappingDto.csindex ce6237212..3f6d38579 100644--- a/src/API/Grand.Api/DTOs/Catalog/ProductAttributeMappingDto.cs+++ b/src/API/Grand.Api/DTOs/Catalog/ProductAttributeMappingDto.cs@@ -1,6 +1,5 @@using Grand.Domain.Catalog;using Grand.Api.Models;-using MongoDB.Bson.Serialization.Attributes;using System.Collections.Generic;namespace Grand.Api.DTOs.Catalog@@ -9,7 +8,7 @@ namespace Grand.Api.DTOs.Catalog{public ProductAttributeMappingDto(){- this.ProductAttributeValues = new List<ProductAttributeValueDto>();+ ProductAttributeValues = new List<ProductAttributeValueDto>();}public string ProductAttributeId { get; set; }public string TextPrompt { get; set; }@@ -21,8 +20,7 @@ namespace Grand.Api.DTOs.Catalogpublic int? ValidationFileMaximumSize { get; set; }public string DefaultValue { get; set; }public string ConditionAttributeXml { get; set; }- [BsonElement("AttributeControlTypeId")]- public AttributeControlType AttributeControlType { get; set; }+ public AttributeControlType AttributeControlTypeId { get; set; }public IList<ProductAttributeValueDto> ProductAttributeValues { get; set; }@@ -41,7 +39,6 @@ namespace Grand.Api.DTOs.Catalogpublic bool IsPreSelected { get; set; }public int DisplayOrder { get; set; }public string PictureId { get; set; }- [BsonElement("AttributeValueTypeId")]- public AttributeValueType AttributeValueType { get; set; }+ public AttributeValueType AttributeValueTypeId { get; set; }}}diff --git a/src/API/Grand.Api/DTOs/Catalog/ProductDto.cs b/src/API/Grand.Api/DTOs/Catalog/ProductDto.csindex f46ce4abf..790b6aa70 100644--- a/src/API/Grand.Api/DTOs/Catalog/ProductDto.cs+++ b/src/API/Grand.Api/DTOs/Catalog/ProductDto.cs@@ -1,6 +1,5 @@using Grand.Api.Models;using Grand.Domain.Catalog;-using MongoDB.Bson.Serialization.Attributes;using System;using System.Collections.Generic;@@ -10,15 +9,15 @@ namespace Grand.Api.DTOs.Catalog{public ProductDto(){- Categories = new List<ProductCategoryDto>();- Collections = new List<ProductCollectionDto>();- Pictures = new List<ProductPictureDto>();- SpecificationAttribute = new List<ProductSpecificationAttributeDto>();+ ProductCategories = new List<ProductCategoryDto>();+ ProductCollections = new List<ProductCollectionDto>();+ ProductPictures = new List<ProductPictureDto>();+ ProductSpecificationAttributes = new List<ProductSpecificationAttributeDto>();TierPrices = new List<ProductTierPriceDto>();- WarehouseInventory = new List<ProductWarehouseInventoryDto>();- AttributeMappings = new List<ProductAttributeMappingDto>();- AttributeCombinations = new List<ProductAttributeCombinationDto>();- Tags = new List<string>();+ ProductWarehouseInventory = new List<ProductWarehouseInventoryDto>();+ ProductAttributeMappings = new List<ProductAttributeMappingDto>();+ ProductAttributeCombinations = new List<ProductAttributeCombinationDto>();+ ProductTags = new List<string>();AppliedDiscounts = new List<string>();}public ProductType ProductTypeId { get; set; }@@ -133,23 +132,15 @@ namespace Grand.Api.DTOs.Catalogpublic Int64 Viewed { get; set; }public int OnSale { get; set; }public string Flag { get; set; }- [BsonElement("ProductCategories")]- public IList<ProductCategoryDto> Categories { get; set; }- [BsonElement("ProductCollections")]- public IList<ProductCollectionDto> Collections { get; set; }- [BsonElement("ProductPictures")]- public IList<ProductPictureDto> Pictures { get; set; }- [BsonElement("ProductSpecificationAttributes")]- public IList<ProductSpecificationAttributeDto> SpecificationAttribute { get; set; }+ public IList<ProductCategoryDto> ProductCategories { get; set; }+ public IList<ProductCollectionDto> ProductCollections { get; set; }+ public IList<ProductPictureDto> ProductPictures { get; set; }+ public IList<ProductSpecificationAttributeDto> ProductSpecificationAttributes { get; set; }public IList<ProductTierPriceDto> TierPrices { get; set; }- [BsonElement("ProductWarehouseInventory")]- public IList<ProductWarehouseInventoryDto> WarehouseInventory { get; set; }- [BsonElement("ProductAttributeMappings")]- public IList<ProductAttributeMappingDto> AttributeMappings { get; set; }- [BsonElement("ProductAttributeCombinations")]- public IList<ProductAttributeCombinationDto> AttributeCombinations { get; set; }- [BsonElement("ProductTags")]- public IList<string> Tags { get; set; }+ public IList<ProductWarehouseInventoryDto> ProductWarehouseInventory { get; set; }+ public IList<ProductAttributeMappingDto> ProductAttributeMappings { get; set; }+ public IList<ProductAttributeCombinationDto> ProductAttributeCombinations { get; set; }+ public IList<string> ProductTags { get; set; }public IList<string> AppliedDiscounts { get; set; }}}diff --git a/src/API/Grand.Api/Infrastructure/DependencyEdmModel.cs b/src/API/Grand.Api/Infrastructure/DependencyEdmModel.csindex 3fe6fd06d..4c0bf7b3c 100644--- a/src/API/Grand.Api/Infrastructure/DependencyEdmModel.cs+++ b/src/API/Grand.Api/Infrastructure/DependencyEdmModel.cs@@ -181,7 +181,7 @@ namespace Grand.Api.InfrastructureActionConfiguration createProductAttributeMapping = product.Action("CreateProductAttributeMapping");createProductAttributeMapping.Parameter<string>(nameof(ProductAttributeMappingDto.Id));createProductAttributeMapping.Parameter<int>(nameof(ProductAttributeMappingDto.DisplayOrder));- createProductAttributeMapping.Parameter<AttributeControlType>(nameof(ProductAttributeMappingDto.AttributeControlType)).Required();+ createProductAttributeMapping.Parameter<AttributeControlType>(nameof(ProductAttributeMappingDto.AttributeControlTypeId)).Required();createProductAttributeMapping.Parameter<string>(nameof(ProductAttributeMappingDto.DefaultValue));createProductAttributeMapping.Parameter<bool>(nameof(ProductAttributeMappingDto.IsRequired));createProductAttributeMapping.Parameter<string>(nameof(ProductAttributeMappingDto.TextPrompt));@@ -195,7 +195,7 @@ namespace Grand.Api.InfrastructureActionConfiguration updateProductAttributeMapping = product.Action("UpdateProductAttributeMapping");updateProductAttributeMapping.Parameter<string>(nameof(ProductAttributeMappingDto.Id)).Required();updateProductAttributeMapping.Parameter<int>(nameof(ProductAttributeMappingDto.DisplayOrder));- updateProductAttributeMapping.Parameter<AttributeControlType>(nameof(ProductAttributeMappingDto.AttributeControlType)).Required();+ updateProductAttributeMapping.Parameter<AttributeControlType>(nameof(ProductAttributeMappingDto.AttributeControlTypeId)).Required();updateProductAttributeMapping.Parameter<string>(nameof(ProductAttributeMappingDto.DefaultValue));updateProductAttributeMapping.Parameter<bool>(nameof(ProductAttributeMappingDto.IsRequired));updateProductAttributeMapping.Parameter<string>(nameof(ProductAttributeMappingDto.TextPrompt));diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetBrandQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetBrandQueryHandler.csindex 9c4b2f60b..9650494c8 100644--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetBrandQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Catalog/GetBrandQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Common{- public class GetBrandQueryHandler : IRequestHandler<GetQuery<BrandDto>, IMongoQueryable<BrandDto>>+ public class GetBrandQueryHandler : IRequestHandler<GetQuery<BrandDto>, IQueryable<BrandDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -17,19 +16,15 @@ namespace Grand.Api.Queries.Handlers.Common{_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<BrandDto>> Handle(GetQuery<BrandDto> request, CancellationToken cancellationToken)+ public async Task<IQueryable<BrandDto>> Handle(GetQuery<BrandDto> request, CancellationToken cancellationToken){+ var query = _mongoDBContext.Table<BrandDto>(typeof(Domain.Catalog.Brand).Name);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult(- _mongoDBContext.Database()- .GetCollection<BrandDto>- (typeof(Domain.Catalog.Brand).Name)- .AsQueryable());+ return query;else- return Task.FromResult(_mongoDBContext.Database()- .GetCollection<BrandDto>(typeof(Domain.Catalog.Brand).Name)- .AsQueryable()- .Where(x => x.Id == request.Id));+ return await Task.FromResult(query.Where(x => x.Id == request.Id));+}}}diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetCategoryQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetCategoryQueryHandler.csindex 7e5c1e804..334835748 100644--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetCategoryQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Catalog/GetCategoryQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Common{- public class GetCategoryQueryHandler : IRequestHandler<GetQuery<CategoryDto>, IMongoQueryable<CategoryDto>>+ public class GetCategoryQueryHandler : IRequestHandler<GetQuery<CategoryDto>, IQueryable<CategoryDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -17,19 +16,15 @@ namespace Grand.Api.Queries.Handlers.Common{_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<CategoryDto>> Handle(GetQuery<CategoryDto> request, CancellationToken cancellationToken)+ public async Task<IQueryable<CategoryDto>> Handle(GetQuery<CategoryDto> request, CancellationToken cancellationToken){+ var query = _mongoDBContext.Table<CategoryDto>(typeof(Domain.Catalog.Category).Name);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult(- _mongoDBContext.Database()- .GetCollection<CategoryDto>- (typeof(Domain.Catalog.Category).Name)- .AsQueryable());+ return query;else- return Task.FromResult(_mongoDBContext.Database()- .GetCollection<CategoryDto>(typeof(Domain.Catalog.Category).Name)- .AsQueryable()- .Where(x => x.Id == request.Id));+ return await Task.FromResult(query.Where(x => x.Id == request.Id));+}}}diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetCollectionQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetCollectionQueryHandler.csindex 1ad5abd15..2fda566d7 100644--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetCollectionQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Catalog/GetCollectionQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Common{- public class GetCollectionQueryHandler : IRequestHandler<GetQuery<CollectionDto>, IMongoQueryable<CollectionDto>>+ public class GetCollectionQueryHandler : IRequestHandler<GetQuery<CollectionDto>, IQueryable<CollectionDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -18,19 +17,14 @@ namespace Grand.Api.Queries.Handlers.Common_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<CollectionDto>> Handle(GetQuery<CollectionDto> request, CancellationToken cancellationToken)+ public async Task<IQueryable<CollectionDto>> Handle(GetQuery<CollectionDto> request, CancellationToken cancellationToken){+ var query = _mongoDBContext.Table<CollectionDto>(typeof(Domain.Catalog.Collection).Name);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult(- _mongoDBContext.Database()- .GetCollection<CollectionDto>- (typeof(Domain.Catalog.Collection).Name)- .AsQueryable());+ return query;else- return Task.FromResult(_mongoDBContext.Database()- .GetCollection<CollectionDto>(typeof(Domain.Catalog.Collection).Name)- .AsQueryable()- .Where(x => x.Id == request.Id));+ return await Task.FromResult(query.Where(x => x.Id == request.Id));}}}diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductAttributeQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductAttributeQueryHandler.csindex 6695499a1..eedab4047 100644--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductAttributeQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductAttributeQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Common{- public class GetProductAttributeQueryHandler : IRequestHandler<GetQuery<ProductAttributeDto>, IMongoQueryable<ProductAttributeDto>>+ public class GetProductAttributeQueryHandler : IRequestHandler<GetQuery<ProductAttributeDto>, IQueryable<ProductAttributeDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -17,19 +16,15 @@ namespace Grand.Api.Queries.Handlers.Common{_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<ProductAttributeDto>> Handle(GetQuery<ProductAttributeDto> request, CancellationToken cancellationToken)+ public async Task<IQueryable<ProductAttributeDto>> Handle(GetQuery<ProductAttributeDto> request, CancellationToken cancellationToken){+ var query = _mongoDBContext.Table<ProductAttributeDto>(typeof(Domain.Catalog.ProductAttribute).Name);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult(- _mongoDBContext.Database()- .GetCollection<ProductAttributeDto>- (typeof(Domain.Catalog.ProductAttribute).Name)- .AsQueryable());+ return query;else- return Task.FromResult(_mongoDBContext.Database()- .GetCollection<ProductAttributeDto>(typeof(Domain.Catalog.ProductAttribute).Name)- .AsQueryable()- .Where(x => x.Id == request.Id));+ return await Task.FromResult(query.Where(x => x.Id == request.Id));+}}}diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductQueryHandler.csindex 51a221b2a..6ea110a68 100644--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Common{- public class GetProductQueryHandler : IRequestHandler<GetQuery<ProductDto>, IMongoQueryable<ProductDto>>+ public class GetProductQueryHandler : IRequestHandler<GetQuery<ProductDto>, IQueryable<ProductDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -18,19 +17,15 @@ namespace Grand.Api.Queries.Handlers.Common_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<ProductDto>> Handle(GetQuery<ProductDto> request, CancellationToken cancellationToken)+ public async Task<IQueryable<ProductDto>> Handle(GetQuery<ProductDto> request, CancellationToken cancellationToken){+ var query = _mongoDBContext.Table<ProductDto>(typeof(Domain.Catalog.Product).Name);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult(- _mongoDBContext.Database()- .GetCollection<ProductDto>- (typeof(Domain.Catalog.Product).Name)- .AsQueryable());+ return query;else- return Task.FromResult(_mongoDBContext.Database()- .GetCollection<ProductDto>(typeof(Domain.Catalog.Product).Name)- .AsQueryable()- .Where(x => x.Id == request.Id));+ return await Task.FromResult(query.Where(x => x.Id == request.Id));+}}}diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetSpecificationAttributeQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetSpecificationAttributeQueryHandler.csindex ec29a74a4..21b3853ca 100644--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetSpecificationAttributeQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Catalog/GetSpecificationAttributeQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Common{- public class GetSpecificationAttributeQueryHandler : IRequestHandler<GetQuery<SpecificationAttributeDto>, IMongoQueryable<SpecificationAttributeDto>>+ public class GetSpecificationAttributeQueryHandler : IRequestHandler<GetQuery<SpecificationAttributeDto>, IQueryable<SpecificationAttributeDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -17,19 +16,15 @@ namespace Grand.Api.Queries.Handlers.Common{_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<SpecificationAttributeDto>> Handle(GetQuery<SpecificationAttributeDto> request, CancellationToken cancellationToken)+ public async Task<IQueryable<SpecificationAttributeDto>> Handle(GetQuery<SpecificationAttributeDto> request, CancellationToken cancellationToken){+ var query = _mongoDBContext.Table<SpecificationAttributeDto>(typeof(Domain.Catalog.SpecificationAttribute).Name);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult(- _mongoDBContext.Database()- .GetCollection<SpecificationAttributeDto>- (typeof(Domain.Catalog.SpecificationAttribute).Name)- .AsQueryable());+ return query;else- return Task.FromResult(_mongoDBContext.Database()- .GetCollection<SpecificationAttributeDto>(typeof(Domain.Catalog.SpecificationAttribute).Name)- .AsQueryable()- .Where(x => x.Id == request.Id));+ return await Task.FromResult(query.Where(x => x.Id == request.Id));+}}}diff --git a/src/API/Grand.Api/Queries/Handlers/Common/GetCountryQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Common/GetCountryQueryHandler.csindex 14f0ccada..b99c70d0f 100644--- a/src/API/Grand.Api/Queries/Handlers/Common/GetCountryQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Common/GetCountryQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Common{- public class GetCountryQueryHandler : IRequestHandler<GetQuery<CountryDto>, IMongoQueryable<CountryDto>>+ public class GetCountryQueryHandler : IRequestHandler<GetQuery<CountryDto>, IQueryable<CountryDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -17,12 +16,15 @@ namespace Grand.Api.Queries.Handlers.Common{_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<CountryDto>> Handle(GetQuery<CountryDto> request, CancellationToken cancellationToken)+ public async Task<IQueryable<CountryDto>> Handle(GetQuery<CountryDto> request, CancellationToken cancellationToken){+ var query = _mongoDBContext.Table<CountryDto>(typeof(Domain.Directory.Country).Name);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult(_mongoDBContext.Database().GetCollection<CountryDto>(typeof(Domain.Directory.Country).Name).AsQueryable());+ return query;else- return Task.FromResult(_mongoDBContext.Database().GetCollection<CountryDto>(typeof(Domain.Directory.Country).Name).AsQueryable().Where(x => x.Id == request.Id));+ return await Task.FromResult(query.Where(x => x.Id == request.Id));+}}}diff --git a/src/API/Grand.Api/Queries/Handlers/Common/GetCurrencyQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Common/GetCurrencyQueryHandler.csindex 5410d5798..685e162d8 100644--- a/src/API/Grand.Api/Queries/Handlers/Common/GetCurrencyQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Common/GetCurrencyQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Common{- public class GetCurrencyQueryHandler : IRequestHandler<GetQuery<CurrencyDto>, IMongoQueryable<CurrencyDto>>+ public class GetCurrencyQueryHandler : IRequestHandler<GetQuery<CurrencyDto>, IQueryable<CurrencyDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -17,12 +16,14 @@ namespace Grand.Api.Queries.Handlers.Common{_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<CurrencyDto>> Handle(GetQuery<CurrencyDto> request, CancellationToken cancellationToken)+ public async Task<IQueryable<CurrencyDto>> Handle(GetQuery<CurrencyDto> request, CancellationToken cancellationToken){+ var query = _mongoDBContext.Table<CurrencyDto>(typeof(Domain.Directory.Currency).Name);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult(_mongoDBContext.Database().GetCollection<CurrencyDto>(typeof(Domain.Directory.Currency).Name).AsQueryable());+ return query;else- return Task.FromResult(_mongoDBContext.Database().GetCollection<CurrencyDto>(typeof(Domain.Directory.Currency).Name).AsQueryable().Where(x => x.Id == request.Id));+ return await Task.FromResult(query.Where(x => x.Id == request.Id));}}}diff --git a/src/API/Grand.Api/Queries/Handlers/Common/GetLanguageQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Common/GetLanguageQueryHandler.csindex 9a8bc600d..bc11ddbeb 100644--- a/src/API/Grand.Api/Queries/Handlers/Common/GetLanguageQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Common/GetLanguageQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Common{- public class GetLanguageQueryHandler : IRequestHandler<GetQuery<LanguageDto>, IMongoQueryable<LanguageDto>>+ public class GetLanguageQueryHandler : IRequestHandler<GetQuery<LanguageDto>, IQueryable<LanguageDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -17,12 +16,15 @@ namespace Grand.Api.Queries.Handlers.Common{_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<LanguageDto>> Handle(GetQuery<LanguageDto> request, CancellationToken cancellationToken)+ public async Task<IQueryable<LanguageDto>> Handle(GetQuery<LanguageDto> request, CancellationToken cancellationToken){+ var query = _mongoDBContext.Table<LanguageDto>(typeof(Domain.Localization.Language).Name);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult(_mongoDBContext.Database().GetCollection<LanguageDto>(typeof(Domain.Localization.Language).Name).AsQueryable());+ return query;else- return Task.FromResult(_mongoDBContext.Database().GetCollection<LanguageDto>(typeof(Domain.Localization.Language).Name).AsQueryable().Where(x => x.Id == request.Id));+ return await Task.FromResult(query.Where(x => x.Id == request.Id));+}}}diff --git a/src/API/Grand.Api/Queries/Handlers/Common/GetLayoutQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Common/GetLayoutQueryHandler.csindex b2a801c09..f4d51d88e 100644--- a/src/API/Grand.Api/Queries/Handlers/Common/GetLayoutQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Common/GetLayoutQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Common{- public class GetLayoutQueryHandler : IRequestHandler<GetLayoutQuery, IMongoQueryable<LayoutDto>>+ public class GetLayoutQueryHandler : IRequestHandler<GetLayoutQuery, IQueryable<LayoutDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -18,12 +17,15 @@ namespace Grand.Api.Queries.Handlers.Common_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<LayoutDto>> Handle(GetLayoutQuery request, CancellationToken cancellationToken)+ public async Task<IQueryable<LayoutDto>> Handle(GetLayoutQuery request, CancellationToken cancellationToken){+ var query = _mongoDBContext.Table<LayoutDto>(request.LayoutName);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult(_mongoDBContext.Database().GetCollection<LayoutDto>(request.LayoutName).AsQueryable());+ return query;else- return Task.FromResult(_mongoDBContext.Database().GetCollection<LayoutDto>(request.LayoutName).AsQueryable().Where(x => x.Id == request.Id));+ return await Task.FromResult(query.Where(x => x.Id == request.Id));+}}}diff --git a/src/API/Grand.Api/Queries/Handlers/Common/GetPictureByIdQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Common/GetPictureByIdQueryHandler.csindex ecce72100..bc8af818e 100644--- a/src/API/Grand.Api/Queries/Handlers/Common/GetPictureByIdQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Common/GetPictureByIdQueryHandler.cs@@ -2,8 +2,6 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;using System.Linq;using System.Threading;using System.Threading.Tasks;@@ -21,10 +19,8 @@ namespace Grand.Api.Queries.Handlers.Commonpublic async Task<PictureDto> Handle(GetPictureByIdQuery request, CancellationToken cancellationToken){- return await _mongoDBContext.Database()- .GetCollection<PictureDto>(typeof(Domain.Media.Picture).Name)- .AsQueryable()- .FirstOrDefaultAsync(x => x.Id == request.Id);+ var query = _mongoDBContext.Table<PictureDto>(typeof(Domain.Media.Picture).Name);+ return await Task.FromResult(query.Where(x => x.Id == request.Id).FirstOrDefault());}}}diff --git a/src/API/Grand.Api/Queries/Handlers/Common/GetStateProvinceQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Common/GetStateProvinceQueryHandler.csindex 388ab748e..c90e1ccac 100644--- a/src/API/Grand.Api/Queries/Handlers/Common/GetStateProvinceQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Common/GetStateProvinceQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Common{- public class GetStateProvinceQueryHandler : IRequestHandler<GetQuery<StateProvinceDto>, IMongoQueryable<StateProvinceDto>>+ public class GetStateProvinceQueryHandler : IRequestHandler<GetQuery<StateProvinceDto>, IQueryable<StateProvinceDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -17,12 +16,15 @@ namespace Grand.Api.Queries.Handlers.Common{_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<StateProvinceDto>> Handle(GetQuery<StateProvinceDto> request, CancellationToken cancellationToken)+ public async Task<IQueryable<StateProvinceDto>> Handle(GetQuery<StateProvinceDto> request, CancellationToken cancellationToken){+ var query = _mongoDBContext.Table<StateProvinceDto>(typeof(Domain.Directory.StateProvince).Name);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult(_mongoDBContext.Database().GetCollection<StateProvinceDto>(typeof(Domain.Directory.StateProvince).Name).AsQueryable());+ return query;else- return Task.FromResult(_mongoDBContext.Database().GetCollection<StateProvinceDto>(typeof(Domain.Directory.StateProvince).Name).AsQueryable().Where(x => x.Id == request.Id));+ return await Task.FromResult(query.Where(x => x.Id == request.Id));+}}}diff --git a/src/API/Grand.Api/Queries/Handlers/Common/GetStoreQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Common/GetStoreQueryHandler.csindex 3da8343ce..c5deef917 100644--- a/src/API/Grand.Api/Queries/Handlers/Common/GetStoreQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Common/GetStoreQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Common{- public class GetStoreQueryHandler : IRequestHandler<GetQuery<StoreDto>, IMongoQueryable<StoreDto>>+ public class GetStoreQueryHandler : IRequestHandler<GetQuery<StoreDto>, IQueryable<StoreDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -17,12 +16,15 @@ namespace Grand.Api.Queries.Handlers.Common{_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<StoreDto>> Handle(GetQuery<StoreDto> request, CancellationToken cancellationToken)+ public async Task<IQueryable<StoreDto>> Handle(GetQuery<StoreDto> request, CancellationToken cancellationToken){+ var query = _mongoDBContext.Table<StoreDto>(typeof(Domain.Stores.Store).Name);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult(_mongoDBContext.Database().GetCollection<StoreDto>(typeof(Domain.Stores.Store).Name).AsQueryable());+ return query;else- return Task.FromResult(_mongoDBContext.Database().GetCollection<StoreDto>(typeof(Domain.Stores.Store).Name).AsQueryable().Where(x => x.Id == request.Id));+ return await Task.FromResult(query.Where(x => x.Id == request.Id));+}}}diff --git a/src/API/Grand.Api/Queries/Handlers/Customers/GetCustomerGroupQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Customers/GetCustomerGroupQueryHandler.csindex d99b0dc3e..f9393e249 100644--- a/src/API/Grand.Api/Queries/Handlers/Customers/GetCustomerGroupQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Customers/GetCustomerGroupQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Customers{- public class GetCustomerGroupQueryHandler : IRequestHandler<GetQuery<CustomerGroupDto>, IMongoQueryable<CustomerGroupDto>>+ public class GetCustomerGroupQueryHandler : IRequestHandler<GetQuery<CustomerGroupDto>, IQueryable<CustomerGroupDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -17,19 +16,15 @@ namespace Grand.Api.Queries.Handlers.Customers{_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<CustomerGroupDto>> Handle(GetQuery<CustomerGroupDto> request, CancellationToken cancellationToken)+ public async Task<IQueryable<CustomerGroupDto>> Handle(GetQuery<CustomerGroupDto> request, CancellationToken cancellationToken){+ var query = _mongoDBContext.Table<CustomerGroupDto>(typeof(Domain.Customers.CustomerGroup).Name);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult(- _mongoDBContext.Database()- .GetCollection<CustomerGroupDto>- (typeof(Domain.Customers.CustomerGroup).Name)- .AsQueryable());+ return query;else- return Task.FromResult(_mongoDBContext.Database()- .GetCollection<CustomerGroupDto>(typeof(Domain.Customers.CustomerGroup).Name)- .AsQueryable()- .Where(x => x.Id == request.Id));+ return await Task.FromResult(query.Where(x => x.Id == request.Id));+}}}diff --git a/src/API/Grand.Api/Queries/Handlers/Customers/GetVendorQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Customers/GetVendorQueryHandler.csindex bcad38355..26aa51d11 100644--- a/src/API/Grand.Api/Queries/Handlers/Customers/GetVendorQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Customers/GetVendorQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Customers{- public class GetVendorQueryHandler : IRequestHandler<GetQuery<VendorDto>, IMongoQueryable<VendorDto>>+ public class GetVendorQueryHandler : IRequestHandler<GetQuery<VendorDto>, IQueryable<VendorDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -17,19 +16,15 @@ namespace Grand.Api.Queries.Handlers.Customers{_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<VendorDto>> Handle(GetQuery<VendorDto> request, CancellationToken cancellationToken)+ public async Task<IQueryable<VendorDto>> Handle(GetQuery<VendorDto> request, CancellationToken cancellationToken){+ var query = _mongoDBContext.Table<VendorDto>(typeof(Domain.Vendors.Vendor).Name);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult(- _mongoDBContext.Database()- .GetCollection<VendorDto>- (typeof(Domain.Vendors.Vendor).Name)- .AsQueryable());+ return query;else- return Task.FromResult(_mongoDBContext.Database()- .GetCollection<VendorDto>(typeof(Domain.Vendors.Vendor).Name)- .AsQueryable()- .Where(x => x.Id == request.Id));+ return await Task.FromResult(query.Where(x => x.Id == request.Id));+}}}diff --git a/src/API/Grand.Api/Queries/Handlers/Shipping/GetDeliveryDateQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Shipping/GetDeliveryDateQueryHandler.csindex c750a2204..dbd45901c 100644--- a/src/API/Grand.Api/Queries/Handlers/Shipping/GetDeliveryDateQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Shipping/GetDeliveryDateQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Shipping{- public class GetDeliveryDateQueryHandler : IRequestHandler<GetQuery<DeliveryDateDto>, IMongoQueryable<DeliveryDateDto>>+ public class GetDeliveryDateQueryHandler : IRequestHandler<GetQuery<DeliveryDateDto>, IQueryable<DeliveryDateDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -17,21 +16,14 @@ namespace Grand.Api.Queries.Handlers.Shipping{_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<DeliveryDateDto>> Handle(GetQuery<DeliveryDateDto> request, CancellationToken cancellationToken)+ public async Task<IQueryable<DeliveryDateDto>> Handle(GetQuery<DeliveryDateDto> request, CancellationToken cancellationToken){+ var query = _mongoDBContext.Table<DeliveryDateDto>(typeof(Domain.Shipping.DeliveryDate).Name);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult- (_mongoDBContext.Database()- .GetCollection<DeliveryDateDto>- (typeof(Domain.Shipping.DeliveryDate).Name)- .AsQueryable());+ return query;else- return Task.FromResult- (_mongoDBContext.Database()- .GetCollection<DeliveryDateDto>- (typeof(Domain.Shipping.DeliveryDate).Name)- .AsQueryable()- .Where(x => x.Id == request.Id));+ return await Task.FromResult(query.Where(x => x.Id == request.Id));}}}\ No newline at end of filediff --git a/src/API/Grand.Api/Queries/Handlers/Shipping/GetPickupPointQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Shipping/GetPickupPointQueryHandler.csindex 2a893ed52..8d76e8265 100644--- a/src/API/Grand.Api/Queries/Handlers/Shipping/GetPickupPointQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Shipping/GetPickupPointQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Shipping{- public class GetPickupPointQueryHandler : IRequestHandler<GetQuery<PickupPointDto>, IMongoQueryable<PickupPointDto>>+ public class GetPickupPointQueryHandler : IRequestHandler<GetQuery<PickupPointDto>, IQueryable<PickupPointDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -17,21 +16,14 @@ namespace Grand.Api.Queries.Handlers.Shipping{_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<PickupPointDto>> Handle(GetQuery<PickupPointDto> request, CancellationToken cancellationToken)+ public async Task<IQueryable<PickupPointDto>> Handle(GetQuery<PickupPointDto> request, CancellationToken cancellationToken){+ var query = _mongoDBContext.Table<PickupPointDto>(typeof(Domain.Shipping.PickupPoint).Name);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult- (_mongoDBContext.Database()- .GetCollection<PickupPointDto>- (typeof(Domain.Shipping.PickupPoint).Name)- .AsQueryable());+ return query;else- return Task.FromResult- (_mongoDBContext.Database()- .GetCollection<PickupPointDto>- (typeof(Domain.Shipping.PickupPoint).Name)- .AsQueryable()- .Where(x => x.Id == request.Id));+ return await Task.FromResult(query.Where(x => x.Id == request.Id));}}}\ No newline at end of filediff --git a/src/API/Grand.Api/Queries/Handlers/Shipping/GetShippingMethodQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Shipping/GetShippingMethodQueryHandler.csindex ad17943ec..d33acb0a3 100644--- a/src/API/Grand.Api/Queries/Handlers/Shipping/GetShippingMethodQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Shipping/GetShippingMethodQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Shipping{- public class GetShippingMethodQueryHandler : IRequestHandler<GetQuery<ShippingMethodDto>, IMongoQueryable<ShippingMethodDto>>+ public class GetShippingMethodQueryHandler : IRequestHandler<GetQuery<ShippingMethodDto>, IQueryable<ShippingMethodDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -17,21 +16,14 @@ namespace Grand.Api.Queries.Handlers.Shipping{_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<ShippingMethodDto>> Handle(GetQuery<ShippingMethodDto> request, CancellationToken cancellationToken)+ public async Task<IQueryable<ShippingMethodDto>> Handle(GetQuery<ShippingMethodDto> request, CancellationToken cancellationToken){+ var shippingMethod = _mongoDBContext.Table<ShippingMethodDto>(typeof(Domain.Shipping.ShippingMethod).Name);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult- (_mongoDBContext.Database()- .GetCollection<ShippingMethodDto>- (typeof(Domain.Shipping.ShippingMethod).Name)- .AsQueryable());+ return shippingMethod;else- return Task.FromResult- (_mongoDBContext.Database()- .GetCollection<ShippingMethodDto>- (typeof(Domain.Shipping.ShippingMethod).Name)- .AsQueryable()- .Where(x => x.Id == request.Id));+ return await Task.FromResult(shippingMethod.Where(x => x.Id == request.Id));}}}\ No newline at end of filediff --git a/src/API/Grand.Api/Queries/Handlers/Shipping/GetWarehouseQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Shipping/GetWarehouseQueryHandler.csindex 9ae426c10..620b6303d 100644--- a/src/API/Grand.Api/Queries/Handlers/Shipping/GetWarehouseQueryHandler.cs+++ b/src/API/Grand.Api/Queries/Handlers/Shipping/GetWarehouseQueryHandler.cs@@ -2,14 +2,13 @@using Grand.Api.Queries.Models.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;+using System.Linq;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Queries.Handlers.Shipping{- public class GetWarehouseQueryHandler : IRequestHandler<GetQuery<WarehouseDto>, IMongoQueryable<WarehouseDto>>+ public class GetWarehouseQueryHandler : IRequestHandler<GetQuery<WarehouseDto>, IQueryable<WarehouseDto>>{private readonly IMongoDBContext _mongoDBContext;@@ -17,21 +16,14 @@ namespace Grand.Api.Queries.Handlers.Shipping{_mongoDBContext = mongoDBContext;}- public Task<IMongoQueryable<WarehouseDto>> Handle(GetQuery<WarehouseDto> request, CancellationToken cancellationToken)+ public async Task<IQueryable<WarehouseDto>> Handle(GetQuery<WarehouseDto> request, CancellationToken cancellationToken){+ var query = _mongoDBContext.Table<WarehouseDto>(typeof(Domain.Shipping.Warehouse).Name);+if (string.IsNullOrEmpty(request.Id))- return Task.FromResult- (_mongoDBContext.Database()- .GetCollection<WarehouseDto>- (typeof(Domain.Shipping.Warehouse).Name)- .AsQueryable());+ return query;else- return Task.FromResult- (_mongoDBContext.Database()- .GetCollection<WarehouseDto>- (typeof(Domain.Shipping.Warehouse).Name)- .AsQueryable()- .Where(x => x.Id == request.Id));+ return await Task.FromResult(query.Where(x => x.Id == request.Id));}}}\ No newline at end of filediff --git a/src/API/Grand.Api/Queries/Models/Common/GetLayoutQuery.cs b/src/API/Grand.Api/Queries/Models/Common/GetLayoutQuery.csindex 8c54801e7..abce00b9d 100644--- a/src/API/Grand.Api/Queries/Models/Common/GetLayoutQuery.cs+++ b/src/API/Grand.Api/Queries/Models/Common/GetLayoutQuery.cs@@ -1,10 +1,10 @@using Grand.Api.DTOs.Common;using MediatR;-using MongoDB.Driver.Linq;+using System.Linq;namespace Grand.Api.Queries.Models.Common{- public class GetLayoutQuery : IRequest<IMongoQueryable<LayoutDto>>+ public class GetLayoutQuery : IRequest<IQueryable<LayoutDto>>{public string Id { get; set; }public string LayoutName { get; set; }diff --git a/src/API/Grand.Api/Queries/Models/Common/GetQuery.cs b/src/API/Grand.Api/Queries/Models/Common/GetQuery.csindex 92e515ec7..da14b3784 100644--- a/src/API/Grand.Api/Queries/Models/Common/GetQuery.cs+++ b/src/API/Grand.Api/Queries/Models/Common/GetQuery.cs@@ -1,9 +1,9 @@using MediatR;-using MongoDB.Driver.Linq;+using System.Linq;namespace Grand.Api.Queries.Models.Common{- public class GetQuery<T> : IRequest<IMongoQueryable<T>> where T : class+ public class GetQuery<T> : IRequest<IQueryable<T>> where T : class{public string Id { get; set; }}diff --git a/src/API/Grand.Api/Validators/Customers/AddressValidator.cs b/src/API/Grand.Api/Validators/Customers/AddressValidator.csindex 396d11450..262689c8a 100644--- a/src/API/Grand.Api/Validators/Customers/AddressValidator.cs+++ b/src/API/Grand.Api/Validators/Customers/AddressValidator.cs@@ -44,7 +44,7 @@ namespace Grand.Api.Validators.Customers{var countryId = !string.IsNullOrEmpty(x.CountryId) ? x.CountryId : "";var country = await countryService.GetCountryById(countryId);- if (country.StateProvinces.Any())+ if (country != null && country.StateProvinces.Any()){//if yes, then ensure that state is selectedif (String.IsNullOrEmpty(y))diff --git a/src/API/Grand.Api/Validators/Customers/CustomerValidator.cs b/src/API/Grand.Api/Validators/Customers/CustomerValidator.csindex 4f5ccdd70..2786030c8 100644--- a/src/API/Grand.Api/Validators/Customers/CustomerValidator.cs+++ b/src/API/Grand.Api/Validators/Customers/CustomerValidator.cs@@ -77,7 +77,7 @@ namespace Grand.Api.Validators.Customers{var countryId = !string.IsNullOrEmpty(x.CountryId) ? x.CountryId : "";var country = await countryService.GetCountryById(countryId);- if (country.StateProvinces.Any())+ if (country != null && country.StateProvinces.Any()){//if yes, then ensure that state is selectedif (string.IsNullOrEmpty(y))diff --git a/src/Core/Grand.Domain/Data/IMongoDBContext.cs b/src/Core/Grand.Domain/Data/IMongoDBContext.csindex 53af2a18b..5e84b4ef5 100644--- a/src/Core/Grand.Domain/Data/IMongoDBContext.cs+++ b/src/Core/Grand.Domain/Data/IMongoDBContext.cs@@ -1,6 +1,8 @@using MongoDB.Bson;using MongoDB.Driver;+using MongoDB.Driver.Linq;using System.Collections.Generic;+using System.Linq;using System.Threading;using System.Threading.Tasks;@@ -9,6 +11,7 @@ namespace Grand.Domain.Datapublic interface IMongoDBContext{IMongoDatabase Database();+ IQueryable<T> Table<T>(string collectionName);Task<byte[]> GridFSBucketDownload(string id);Task<string> GridFSBucketUploadFromBytesAsync(string filename, byte[] source);Task<bool> DatabaseExist(string connectionString);diff --git a/src/Core/Grand.Domain/Data/MongoDBContext.cs b/src/Core/Grand.Domain/Data/MongoDBContext.csindex 3e7ee3607..aec0efbfe 100644--- a/src/Core/Grand.Domain/Data/MongoDBContext.cs+++ b/src/Core/Grand.Domain/Data/MongoDBContext.cs@@ -2,6 +2,7 @@using MongoDB.Driver;using MongoDB.Driver.Core.Bindings;using MongoDB.Driver.Core.Operations;+using MongoDB.Driver.Linq;using System.Collections.Generic;using System.Linq;using System.Threading;@@ -27,6 +28,11 @@ namespace Grand.Domain.Datareturn _database;}+ public IQueryable<T> Table<T>(string collectionName)+ {+ return _database.GetCollection<T>(collectionName).AsQueryable();+ }+protected IMongoDatabase TryReadMongoDatabase(){var dataSettingsManager = new DataSettingsManager();