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.

API - code improvements and use common practice (#420)

Krzysztof Pajak80073fbd7ca4
diff --git a/src/API/Grand.Api/ApiExplorer/ApiResponseTypeProvider.cs b/src/API/Grand.Api/ApiExplorer/ApiResponseTypeProvider.cs
index 48924d70b..e43d79bdf 100644
--- a/src/API/Grand.Api/ApiExplorer/ApiResponseTypeProvider.cs
+++ b/src/API/Grand.Api/ApiExplorer/ApiResponseTypeProvider.cs
@@ -57,11 +57,6 @@ public class ApiResponseTypeProvider
private static List<IApiResponseMetadataProvider> GetResponseMetadataAttributes(ControllerActionDescriptor action)
{
- if (action.FilterDescriptors == null)
- {
- return new List<IApiResponseMetadataProvider>();
- }
-
// This technique for enumerating filters will intentionally ignore any filter that is an IFilterFactory
// while searching for a filter that implements IApiResponseMetadataProvider.
//
@@ -114,11 +109,7 @@ public class ApiResponseTypeProvider
return responseTypes;
}
-
- private static ApiResponseFormat CreateDefaultApiResponseFormat()
- {
- return new ApiResponseFormat { MediaType = "application/json" };
- }
+
// Shared with EndpointMetadataApiDescriptionProvider
internal static List<ApiResponseType> ReadResponseMetadata(
IReadOnlyList<IApiResponseMetadataProvider> responseMetadataAttributes,
@@ -133,9 +124,7 @@ public class ApiResponseTypeProvider
// Get the content type that the action explicitly set to support.
// Walk through all 'filter' attributes in order, and allow each one to see or override
// the results of the previous ones. This is similar to the execution path for content-negotiation.
- if (responseMetadataAttributes != null)
- {
- foreach (var metadataAttribute in responseMetadataAttributes)
+ foreach (var metadataAttribute in responseMetadataAttributes)
{
// All ProducesXAttributes, except for ProducesResponseTypeAttribute do
// not allow multiple instances on the same method/class/etc. For those
@@ -201,8 +190,7 @@ public class ApiResponseTypeProvider
results[apiResponseType.StatusCode] = apiResponseType;
}
}
- }
-
+
return results.Values.ToList();
}
@@ -266,7 +254,7 @@ public class ApiResponseTypeProvider
}
- if (!isSupportedContentType && contentType != null)
+ if (!isSupportedContentType)
{
// No output formatter was found that supports this content type. Add the user specified content type as-is to the result.
apiResponse.ApiResponseFormats.Add(new ApiResponseFormat {
@@ -325,7 +313,7 @@ public class ApiResponseTypeProvider
{
var provider = providers[i];
- if (provider is ProducesAttribute producesAttribute && producesAttribute.Type is null)
+ if (provider is ProducesAttribute { Type: null })
{
// ProducesAttribute that does not specify type is considered not significant.
continue;
diff --git a/src/API/Grand.Api/ApiExplorer/MetadataApiDescriptionProvider.cs b/src/API/Grand.Api/ApiExplorer/MetadataApiDescriptionProvider.cs
index 9a1e50a06..2541ac53a 100644
--- a/src/API/Grand.Api/ApiExplorer/MetadataApiDescriptionProvider.cs
+++ b/src/API/Grand.Api/ApiExplorer/MetadataApiDescriptionProvider.cs
@@ -65,7 +65,8 @@ public class MetadataApiDescriptionProvider : IApiDescriptionProvider
foreach (var action in context.Actions.OfType<ControllerActionDescriptor>())
{
- if (!action.ControllerTypeInfo.GetCustomAttributes<Grand.SharedKernel.Attributes.ApiControllerAttribute>(true).Any())
+ if (!action.ControllerTypeInfo.GetCustomAttributes<SharedKernel.Attributes.ApiControllerAttribute>(true)
+ .Any())
continue;
if (action.MethodInfo.GetCustomAttributes<IgnoreApiAttribute>(true).Any())
@@ -97,20 +98,20 @@ public class MetadataApiDescriptionProvider : IApiDescriptionProvider
var parsedTemplate = ParseTemplate(action);
var path = GetRelativePath(action, parsedTemplate);
- var apiDescription = new ApiDescription() {
+ var apiDescription = new ApiDescription {
ActionDescriptor = action,
GroupName = groupName,
HttpMethod = httpMethod,
RelativePath = path,
};
- var templateParameters = parsedTemplate?.Parameters?.ToList() ?? new List<TemplatePart>();
+ var templateParameters = parsedTemplate?.Parameters.ToList() ?? new List<TemplatePart>();
var parameterContext = new ApiParameterContext(_modelMetadataProvider, action, templateParameters);
foreach (var parameter in GetParameters(parameterContext,
httpMethod.Equals("GET", StringComparison.CurrentCultureIgnoreCase)))
{
- apiDescription.ParameterDescriptions.Add(parameter);
+ apiDescription.ParameterDescriptions.Add(parameter);
}
var requestMetadataAttributes = GetRequestMetadataAttributes(action);
@@ -158,70 +159,64 @@ public class MetadataApiDescriptionProvider : IApiDescriptionProvider
private IList<ApiParameterDescription> GetParameters(ApiParameterContext context, bool httpGet)
{
// First, get parameters from the model-binding/parameter-binding side of the world.
- if (context.ActionDescriptor.Parameters != null)
+ foreach (var actionParameter in context.ActionDescriptor.Parameters)
{
- foreach (var actionParameter in context.ActionDescriptor.Parameters)
- {
- var visitor = new PseudoModelBindingVisitor(context, actionParameter);
-
- ModelMetadata metadata;
- if (actionParameter is ControllerParameterDescriptor controllerParameterDescriptor &&
- _modelMetadataProvider is ModelMetadataProvider provider)
- {
- // The default model metadata provider derives from ModelMetadataProvider
- // and can therefore supply information about attributes applied to parameters.
- metadata = provider.GetMetadataForParameter(controllerParameterDescriptor.ParameterInfo);
- }
- else
- {
- // For backward compatibility, if there's a custom model metadata provider that
- // only implements the older IModelMetadataProvider interface, access the more
- // limited metadata information it supplies. In this scenario, validation attributes
- // are not supported on parameters.
- metadata = _modelMetadataProvider.GetMetadataForType(actionParameter.ParameterType);
- }
+ var visitor = new PseudoModelBindingVisitor(context, actionParameter);
- if (!httpGet &&
- actionParameter.BindingInfo == null &&
- !CommonHelper.IsSimpleType(actionParameter.ParameterType))
- {
- var bindingContext = new ApiParameterDescriptionContext(
- metadata,
- new BindingInfo {
- BindingSource = new BindingSource("Body", "Body", true, true)
- },
- propertyName: actionParameter.Name);
- visitor.WalkParameter(bindingContext);
- }
- else
- {
- var bindingContext = new ApiParameterDescriptionContext(
- metadata,
- actionParameter.BindingInfo,
- propertyName: actionParameter.Name);
- visitor.WalkParameter(bindingContext);
- }
+ ModelMetadata metadata;
+ if (actionParameter is ControllerParameterDescriptor controllerParameterDescriptor &&
+ _modelMetadataProvider is ModelMetadataProvider provider)
+ {
+ // The default model metadata provider derives from ModelMetadataProvider
+ // and can therefore supply information about attributes applied to parameters.
+ metadata = provider.GetMetadataForParameter(controllerParameterDescriptor.ParameterInfo);
+ }
+ else
+ {
+ // For backward compatibility, if there's a custom model metadata provider that
+ // only implements the older IModelMetadataProvider interface, access the more
+ // limited metadata information it supplies. In this scenario, validation attributes
+ // are not supported on parameters.
+ metadata = _modelMetadataProvider.GetMetadataForType(actionParameter.ParameterType);
}
- }
- if (context.ActionDescriptor.BoundProperties != null)
- {
- foreach (var actionParameter in context.ActionDescriptor.BoundProperties)
+ if (!httpGet &&
+ actionParameter.BindingInfo == null &&
+ !CommonHelper.IsSimpleType(actionParameter.ParameterType))
{
- var visitor = new PseudoModelBindingVisitor(context, actionParameter);
- var modelMetadata = context.MetadataProvider.GetMetadataForProperty(
- containerType: context.ActionDescriptor.ControllerTypeInfo.AsType(),
+ var bindingContext = new ApiParameterDescriptionContext(
+ metadata,
+ new BindingInfo {
+ BindingSource = new BindingSource("Body", "Body", true, true)
+ },
propertyName: actionParameter.Name);
-
+ visitor.WalkParameter(bindingContext);
+ }
+ else
+ {
var bindingContext = new ApiParameterDescriptionContext(
- modelMetadata,
+ metadata,
actionParameter.BindingInfo,
propertyName: actionParameter.Name);
-
visitor.WalkParameter(bindingContext);
}
}
+ foreach (var actionParameter in context.ActionDescriptor.BoundProperties)
+ {
+ var visitor = new PseudoModelBindingVisitor(context, actionParameter);
+ var modelMetadata = context.MetadataProvider.GetMetadataForProperty(
+ containerType: context.ActionDescriptor.ControllerTypeInfo.AsType(),
+ propertyName: actionParameter.Name);
+
+ var bindingContext = new ApiParameterDescriptionContext(
+ modelMetadata,
+ actionParameter.BindingInfo,
+ propertyName: actionParameter.Name);
+
+ visitor.WalkParameter(bindingContext);
+ }
+
for (var i = context.Results.Count - 1; i >= 0; i--)
{
// Remove any 'hidden' parameters. These are things that can't come from user input,
@@ -286,7 +281,7 @@ public class MetadataApiDescriptionProvider : IApiDescriptionProvider
// a partner.
foreach (var routeParameter in routeParameters)
{
- context.Results.Add(new ApiParameterDescription() {
+ context.Results.Add(new ApiParameterDescription {
Name = routeParameter.Key,
RouteInfo = routeParameter.Value,
Source = BindingSource.Path,
@@ -346,15 +341,12 @@ public class MetadataApiDescriptionProvider : IApiDescriptionProvider
private ApiParameterRouteInfo CreateRouteInfo(TemplatePart routeParameter)
{
var constraints = new List<IRouteConstraint>();
- if (routeParameter.InlineConstraints != null)
+ foreach (var constraint in routeParameter.InlineConstraints)
{
- foreach (var constraint in routeParameter.InlineConstraints)
- {
- constraints.Add(_constraintResolver.ResolveConstraint(constraint.Constraint)!);
- }
+ constraints.Add(_constraintResolver.ResolveConstraint(constraint.Constraint)!);
}
- return new ApiParameterRouteInfo() {
+ return new ApiParameterRouteInfo {
Constraints = constraints,
DefaultValue = routeParameter.DefaultValue,
IsOptional = routeParameter.IsOptional || routeParameter.DefaultValue != null,
@@ -363,19 +355,16 @@ public class MetadataApiDescriptionProvider : IApiDescriptionProvider
private static IEnumerable<string> GetHttpMethods(ControllerActionDescriptor action)
{
- return action.ActionConstraints is { Count: > 0 } ? action.ActionConstraints.OfType<HttpMethodActionConstraint>().SelectMany(c => c.HttpMethods) : new [] { string.Empty };
+ return action.ActionConstraints is { Count: > 0 }
+ ? action.ActionConstraints.OfType<HttpMethodActionConstraint>().SelectMany(c => c.HttpMethods)
+ : new[] { string.Empty };
}
private static RouteTemplate? ParseTemplate(ControllerActionDescriptor action)
{
- if (action.AttributeRouteInfo?.Template != null)
- {
- return TemplateParser.Parse(action.AttributeRouteInfo.Template);
- }
-
- var x = action.EndpointMetadata.FirstOrDefault();
-
- return null;
+ return action.AttributeRouteInfo?.Template != null
+ ? TemplateParser.Parse(action.AttributeRouteInfo.Template)
+ : null;
}
private string? GetRelativePath(ControllerActionDescriptor action, RouteTemplate? parsedTemplate)
@@ -430,7 +419,7 @@ public class MetadataApiDescriptionProvider : IApiDescriptionProvider
{
foreach (var supportedType in supportedTypes.Where(x => x == "application/json"))
{
- results.Add(new ApiRequestFormat() {
+ results.Add(new ApiRequestFormat {
Formatter = formatter,
MediaType = supportedType,
});
@@ -462,11 +451,6 @@ public class MetadataApiDescriptionProvider : IApiDescriptionProvider
private static IApiRequestMetadataProvider[]? GetRequestMetadataAttributes(ControllerActionDescriptor action)
{
- if (action.FilterDescriptors == null)
- {
- return null;
- }
-
// This technique for enumerating filters will intentionally ignore any filter that is an IFilterFactory
// while searching for a filter that implements IApiRequestMetadataProvider.
//
@@ -621,7 +605,7 @@ public class MetadataApiDescriptionProvider : IApiDescriptionProvider
BindingSource source,
string containerName)
{
- return new ApiParameterDescription() {
+ return new ApiParameterDescription {
ModelMetadata = bindingContext.ModelMetadata,
Name = GetName(containerName, bindingContext),
Source = source,
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/AddBrandCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/AddBrandCommandHandler.cs
index d3f794333..58b8d9404 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/AddBrandCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/AddBrandCommandHandler.cs
@@ -1,7 +1,8 @@
-using Grand.Api.DTOs.Catalog;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Api.DTOs.Catalog;
using Grand.Api.Extensions;
-using Grand.Business.Core.Interfaces.Catalog.Brands;
using Grand.Business.Core.Extensions;
+using Grand.Business.Core.Interfaces.Catalog.Brands;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Logging;
using Grand.Business.Core.Interfaces.Common.Seo;
@@ -9,7 +10,7 @@ using Grand.Domain.Seo;
using Grand.Infrastructure;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class AddBrandCommandHandler : IRequestHandler<AddBrandCommand, BrandDto>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/AddCategoryCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/AddCategoryCommandHandler.cs
index be012baf9..69b6aebb8 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/AddCategoryCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/AddCategoryCommandHandler.cs
@@ -1,7 +1,8 @@
-using Grand.Api.DTOs.Catalog;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Api.DTOs.Catalog;
using Grand.Api.Extensions;
-using Grand.Business.Core.Interfaces.Catalog.Categories;
using Grand.Business.Core.Extensions;
+using Grand.Business.Core.Interfaces.Catalog.Categories;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Logging;
using Grand.Business.Core.Interfaces.Common.Seo;
@@ -9,7 +10,7 @@ using Grand.Domain.Seo;
using Grand.Infrastructure;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class AddCategoryCommandHandler : IRequestHandler<AddCategoryCommand, CategoryDto>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/AddCollectionCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/AddCollectionCommandHandler.cs
index 5f6fa8514..291f2e6ef 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/AddCollectionCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/AddCollectionCommandHandler.cs
@@ -1,7 +1,8 @@
-using Grand.Api.DTOs.Catalog;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Api.DTOs.Catalog;
using Grand.Api.Extensions;
-using Grand.Business.Core.Interfaces.Catalog.Collections;
using Grand.Business.Core.Extensions;
+using Grand.Business.Core.Interfaces.Catalog.Collections;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Logging;
using Grand.Business.Core.Interfaces.Common.Seo;
@@ -9,7 +10,7 @@ using Grand.Domain.Seo;
using Grand.Infrastructure;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class AddCollectionCommandHandler : IRequestHandler<AddCollectionCommand, CollectionDto>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductAttributeMappingCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductAttributeMappingCommandHandler.cs
index 268828bc1..395ed6444 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductAttributeMappingCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductAttributeMappingCommandHandler.cs
@@ -1,9 +1,10 @@
-using Grand.Api.DTOs.Catalog;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Api.DTOs.Catalog;
using Grand.Api.Extensions;
using Grand.Business.Core.Interfaces.Catalog.Products;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class AddProductAttributeMappingCommandHandler : IRequestHandler<AddProductAttributeMappingCommand, ProductAttributeMappingDto>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductCategoryCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductCategoryCommandHandler.cs
index 3cfdea96d..ec18f37f3 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductCategoryCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductCategoryCommandHandler.cs
@@ -1,8 +1,9 @@
-using Grand.Business.Core.Interfaces.Catalog.Categories;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Categories;
using Grand.Domain.Catalog;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class AddProductCategoryCommandHandler : IRequestHandler<AddProductCategoryCommand, bool>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductCollectionCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductCollectionCommandHandler.cs
index 82336000d..fef4bf3b3 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductCollectionCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductCollectionCommandHandler.cs
@@ -1,8 +1,9 @@
-using Grand.Business.Core.Interfaces.Catalog.Collections;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Collections;
using Grand.Domain.Catalog;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class AddProductCollectionCommandHandler : IRequestHandler<AddProductCollectionCommand, bool>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductCommandHandler.cs
index 7255d4e3d..50bc9c744 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductCommandHandler.cs
@@ -1,15 +1,16 @@
-using Grand.Api.DTOs.Catalog;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Api.DTOs.Catalog;
using Grand.Api.Extensions;
-using Grand.Domain.Seo;
+using Grand.Business.Core.Extensions;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Logging;
using Grand.Business.Core.Interfaces.Common.Seo;
-using MediatR;
-using Grand.Business.Core.Interfaces.Catalog.Products;
-using Grand.Business.Core.Extensions;
+using Grand.Domain.Seo;
using Grand.Infrastructure;
+using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class AddProductCommandHandler : IRequestHandler<AddProductCommand, ProductDto>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductPictureCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductPictureCommandHandler.cs
index 099ab370d..febe4b361 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductPictureCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductPictureCommandHandler.cs
@@ -1,9 +1,10 @@
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Storage;
using Grand.Domain.Catalog;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class AddProductPictureCommandHandler : IRequestHandler<AddProductPictureCommand, bool>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductSpecificationCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductSpecificationCommandHandler.cs
index c8565f919..a7786552d 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductSpecificationCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductSpecificationCommandHandler.cs
@@ -1,8 +1,9 @@
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Domain.Catalog;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class AddProductSpecificationCommandHandler : IRequestHandler<AddProductSpecificationCommand, bool>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductTierPriceCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductTierPriceCommandHandler.cs
index 59ed53f71..4c0d0d9f0 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductTierPriceCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/AddProductTierPriceCommandHandler.cs
@@ -1,8 +1,9 @@
-using Grand.Api.Extensions;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Api.Extensions;
using Grand.Business.Core.Interfaces.Catalog.Products;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class AddProductTierPriceCommandHandler : IRequestHandler<AddProductTierPriceCommand, bool>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteBrandCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteBrandCommandHandler.cs
index 9251a1327..5fa29a2a9 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteBrandCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteBrandCommandHandler.cs
@@ -1,10 +1,11 @@
-using Grand.Business.Core.Interfaces.Catalog.Brands;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Brands;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Logging;
using Grand.Infrastructure;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class DeleteBrandCommandHandler : IRequestHandler<DeleteBrandCommand, bool>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteCategoryCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteCategoryCommandHandler.cs
index 256fb849b..a14235b20 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteCategoryCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteCategoryCommandHandler.cs
@@ -1,10 +1,11 @@
-using Grand.Business.Core.Interfaces.Catalog.Categories;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Categories;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Logging;
using Grand.Infrastructure;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class DeleteCategoryCommandHandler : IRequestHandler<DeleteCategoryCommand, bool>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteCollectionCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteCollectionCommandHandler.cs
index 83b13eb23..aaf58a2f0 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteCollectionCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteCollectionCommandHandler.cs
@@ -1,10 +1,11 @@
-using Grand.Business.Core.Interfaces.Catalog.Collections;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Collections;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Logging;
using Grand.Infrastructure;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class DeleteCollectionCommandHandler : IRequestHandler<DeleteCollectionCommand, bool>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductAttributeMappingCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductAttributeMappingCommandHandler.cs
index ac9efcd9d..fcad83e51 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductAttributeMappingCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductAttributeMappingCommandHandler.cs
@@ -1,8 +1,9 @@
-using Grand.Api.Extensions;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Api.Extensions;
using Grand.Business.Core.Interfaces.Catalog.Products;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class DeleteProductAttributeMappingCommandHandler : IRequestHandler<DeleteProductAttributeMappingCommand, bool>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductCategoryCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductCategoryCommandHandler.cs
index ff51cc14b..971e3c705 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductCategoryCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductCategoryCommandHandler.cs
@@ -1,8 +1,9 @@
-using Grand.Business.Core.Interfaces.Catalog.Categories;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Categories;
using Grand.Business.Core.Interfaces.Catalog.Products;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class DeleteProductCategoryCommandHandler : IRequestHandler<DeleteProductCategoryCommand, bool>
{
@@ -20,7 +21,7 @@ namespace Grand.Api.Commands.Models.Catalog
public async Task<bool> Handle(DeleteProductCategoryCommand request, CancellationToken cancellationToken)
{
var product = await _productService.GetProductById(request.Product.Id, true);
- var productCategory = product.ProductCategories.Where(x => x.CategoryId == request.CategoryId).FirstOrDefault();
+ var productCategory = product.ProductCategories.FirstOrDefault(x => x.CategoryId == request.CategoryId);
if (productCategory == null)
throw new ArgumentException("No product category mapping found with the specified id");
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductCollectionCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductCollectionCommandHandler.cs
index b18f9b853..1e1e3d455 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductCollectionCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductCollectionCommandHandler.cs
@@ -1,8 +1,9 @@
-using Grand.Business.Core.Interfaces.Catalog.Collections;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Collections;
using Grand.Business.Core.Interfaces.Catalog.Products;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class DeleteProductCollectionCommandHandler : IRequestHandler<DeleteProductCollectionCommand, bool>
{
@@ -18,7 +19,7 @@ namespace Grand.Api.Commands.Models.Catalog
public async Task<bool> Handle(DeleteProductCollectionCommand request, CancellationToken cancellationToken)
{
var product = await _productService.GetProductById(request.Product.Id, true);
- var productCollection = product.ProductCollections.Where(x => x.CollectionId == request.CollectionId).FirstOrDefault();
+ var productCollection = product.ProductCollections.FirstOrDefault(x => x.CollectionId == request.CollectionId);
if (productCollection == null)
throw new ArgumentException("No product collection mapping found with the specified id");
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductCommandHandler.cs
index 1cb1c7d3c..7bee2faf2 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductCommandHandler.cs
@@ -1,10 +1,11 @@
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Logging;
using Grand.Infrastructure;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class DeleteProductCommandHandler : IRequestHandler<DeleteProductCommand, bool>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductPictureCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductPictureCommandHandler.cs
index 21c5a045c..b2376dc46 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductPictureCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductPictureCommandHandler.cs
@@ -1,7 +1,8 @@
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class DeleteProductPictureCommandHandler : IRequestHandler<DeleteProductPictureCommand, bool>
{
@@ -17,7 +18,7 @@ namespace Grand.Api.Commands.Models.Catalog
{
var product = await _productService.GetProductById(request.Product.Id);
- var productPicture = product.ProductPictures.Where(x => x.PictureId == request.PictureId).FirstOrDefault();
+ var productPicture = product.ProductPictures.FirstOrDefault(x => x.PictureId == request.PictureId);
if (productPicture == null)
throw new ArgumentException("No product picture found with the specified pictureid");
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductSpecificationCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductSpecificationCommandHandler.cs
index 6412beaf3..72e5a601c 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductSpecificationCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductSpecificationCommandHandler.cs
@@ -1,7 +1,8 @@
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class DeleteProductSpecificationCommandHandler : IRequestHandler<DeleteProductSpecificationCommand, bool>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductTierPriceCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductTierPriceCommandHandler.cs
index 54ce701d5..005a99617 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductTierPriceCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/DeleteProductTierPriceCommandHandler.cs
@@ -1,7 +1,8 @@
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class DeleteProductTierPriceCommandHandler : IRequestHandler<DeleteProductTierPriceCommand, bool>
{
@@ -15,7 +16,7 @@ namespace Grand.Api.Commands.Models.Catalog
public async Task<bool> Handle(DeleteProductTierPriceCommand request, CancellationToken cancellationToken)
{
var product = await _productService.GetProductById(request.Product.Id, true);
- var tierPrice = product.TierPrices.Where(x => x.Id == request.Id).FirstOrDefault();
+ var tierPrice = product.TierPrices.FirstOrDefault(x => x.Id == request.Id);
await _productService.DeleteTierPrice(tierPrice, product.Id);
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateBrandCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateBrandCommandHandler.cs
index ca4dbf7de..31020240d 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateBrandCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateBrandCommandHandler.cs
@@ -1,7 +1,8 @@
-using Grand.Api.DTOs.Catalog;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Api.DTOs.Catalog;
using Grand.Api.Extensions;
-using Grand.Business.Core.Interfaces.Catalog.Brands;
using Grand.Business.Core.Extensions;
+using Grand.Business.Core.Interfaces.Catalog.Brands;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Logging;
using Grand.Business.Core.Interfaces.Common.Seo;
@@ -10,7 +11,7 @@ using Grand.Domain.Seo;
using Grand.Infrastructure;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class UpdateBrandCommandHandler : IRequestHandler<UpdateBrandCommand, BrandDto>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateCategoryCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateCategoryCommandHandler.cs
index 76c82267f..db6054d41 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateCategoryCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateCategoryCommandHandler.cs
@@ -1,7 +1,8 @@
-using Grand.Api.DTOs.Catalog;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Api.DTOs.Catalog;
using Grand.Api.Extensions;
-using Grand.Business.Core.Interfaces.Catalog.Categories;
using Grand.Business.Core.Extensions;
+using Grand.Business.Core.Interfaces.Catalog.Categories;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Logging;
using Grand.Business.Core.Interfaces.Common.Seo;
@@ -10,7 +11,7 @@ using Grand.Domain.Seo;
using Grand.Infrastructure;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class UpdateCategoryCommandHandler : IRequestHandler<UpdateCategoryCommand, CategoryDto>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateCollectionCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateCollectionCommandHandler.cs
index a758b311a..1a185c3ec 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateCollectionCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateCollectionCommandHandler.cs
@@ -1,7 +1,8 @@
-using Grand.Api.DTOs.Catalog;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Api.DTOs.Catalog;
using Grand.Api.Extensions;
-using Grand.Business.Core.Interfaces.Catalog.Collections;
using Grand.Business.Core.Extensions;
+using Grand.Business.Core.Interfaces.Catalog.Collections;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Logging;
using Grand.Business.Core.Interfaces.Common.Seo;
@@ -10,7 +11,7 @@ using Grand.Domain.Seo;
using Grand.Infrastructure;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class UpdateCollectionCommandHandler : IRequestHandler<UpdateCollectionCommand, CollectionDto>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductAttributeMappingCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductAttributeMappingCommandHandler.cs
index d4d806d3b..58365fb9b 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductAttributeMappingCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductAttributeMappingCommandHandler.cs
@@ -1,9 +1,10 @@
-using Grand.Api.DTOs.Catalog;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Api.DTOs.Catalog;
using Grand.Api.Extensions;
using Grand.Business.Core.Interfaces.Catalog.Products;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class UpdateProductAttributeMappingCommandHandler : IRequestHandler<UpdateProductAttributeMappingCommand, ProductAttributeMappingDto>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductCategoryCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductCategoryCommandHandler.cs
index 0d1a25830..f7bd2c12e 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductCategoryCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductCategoryCommandHandler.cs
@@ -1,8 +1,9 @@
-using Grand.Business.Core.Interfaces.Catalog.Categories;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Categories;
using Grand.Business.Core.Interfaces.Catalog.Products;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class UpdateProductCategoryCommandHandler : IRequestHandler<UpdateProductCategoryCommand, bool>
{
@@ -20,7 +21,7 @@ namespace Grand.Api.Commands.Models.Catalog
public async Task<bool> Handle(UpdateProductCategoryCommand request, CancellationToken cancellationToken)
{
var product = await _productService.GetProductById(request.Product.Id, true);
- var productCategory = product.ProductCategories.Where(x => x.CategoryId == request.Model.CategoryId).FirstOrDefault();
+ var productCategory = product.ProductCategories.FirstOrDefault(x => x.CategoryId == request.Model.CategoryId);
if (productCategory == null)
throw new ArgumentException("No product category mapping found with the specified id");
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductCollectionCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductCollectionCommandHandler.cs
index 06d23c4ec..39809037d 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductCollectionCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductCollectionCommandHandler.cs
@@ -1,31 +1,32 @@
-using Grand.Business.Core.Interfaces.Catalog.Collections;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Collections;
using Grand.Business.Core.Interfaces.Catalog.Products;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class UpdateProductCollectionCommandHandler : IRequestHandler<UpdateProductCollectionCommand, bool>
{
- private readonly IProductCollectionService _productcollectionService;
+ private readonly IProductCollectionService _productCollectionService;
private readonly IProductService _productService;
- public UpdateProductCollectionCommandHandler(IProductCollectionService productcollectionService, IProductService productService)
+ public UpdateProductCollectionCommandHandler(IProductCollectionService productCollectionService, IProductService productService)
{
- _productcollectionService = productcollectionService;
+ _productCollectionService = productCollectionService;
_productService = productService;
}
public async Task<bool> Handle(UpdateProductCollectionCommand request, CancellationToken cancellationToken)
{
var product = await _productService.GetProductById(request.Product.Id, true);
- var productCollection = product.ProductCollections.Where(x => x.CollectionId == request.Model.CollectionId).FirstOrDefault();
+ var productCollection = product.ProductCollections.FirstOrDefault(x => x.CollectionId == request.Model.CollectionId);
if (productCollection == null)
throw new ArgumentException("No product collection mapping found with the specified id");
productCollection.CollectionId = request.Model.CollectionId;
productCollection.IsFeaturedProduct = request.Model.IsFeaturedProduct;
- await _productcollectionService.UpdateProductCollection(productCollection, product.Id);
+ await _productCollectionService.UpdateProductCollection(productCollection, product.Id);
return true;
}
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductCommandHandler.cs
index 93c02fc36..5f41c6852 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductCommandHandler.cs
@@ -1,8 +1,9 @@
-using Grand.Api.DTOs.Catalog;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Api.DTOs.Catalog;
using Grand.Api.Extensions;
using Grand.Business.Core.Events.Catalog;
-using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Extensions;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Logging;
using Grand.Business.Core.Interfaces.Common.Seo;
@@ -11,7 +12,7 @@ using Grand.Domain.Seo;
using Grand.Infrastructure;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class UpdateProductCommandHandler : IRequestHandler<UpdateProductCommand, ProductDto>
{
@@ -81,10 +82,10 @@ namespace Grand.Api.Commands.Models.Catalog
//raise event
if (!prevPublished && product.Published)
- await _mediator.Publish(new ProductPublishEvent(product));
+ await _mediator.Publish(new ProductPublishEvent(product), cancellationToken);
if (prevPublished && !product.Published)
- await _mediator.Publish(new ProductUnPublishEvent(product));
+ await _mediator.Publish(new ProductUnPublishEvent(product), cancellationToken);
return product.ToModel();
}
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductPictureCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductPictureCommandHandler.cs
index f3dd8c584..b2668c84e 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductPictureCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductPictureCommandHandler.cs
@@ -1,7 +1,8 @@
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class UpdateProductPictureCommandHandler : IRequestHandler<UpdateProductPictureCommand, bool>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductSpecificationCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductSpecificationCommandHandler.cs
index c54728433..5684be009 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductSpecificationCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductSpecificationCommandHandler.cs
@@ -1,8 +1,9 @@
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Domain.Catalog;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class UpdateProductSpecificationCommandHandler : IRequestHandler<UpdateProductSpecificationCommand, bool>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductStockCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductStockCommandHandler.cs
index c8cc4b0aa..58214ea8f 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductStockCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductStockCommandHandler.cs
@@ -1,11 +1,12 @@
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Logging;
using Grand.Domain.Catalog;
using Grand.Infrastructure;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class UpdateProductStockCommandHandler : IRequestHandler<UpdateProductStockCommand, bool>
{
@@ -41,7 +42,7 @@ namespace Grand.Api.Commands.Models.Catalog
if (product != null)
{
var prevStockQuantity = _stockQuantityService.GetTotalStockQuantity(product);
- var prevMultiWarehouseStock = product.ProductWarehouseInventory.Select(i => new ProductWarehouseInventory() { WarehouseId = i.WarehouseId, StockQuantity = i.StockQuantity, ReservedQuantity = i.ReservedQuantity }).ToList();
+ var prevMultiWarehouseStock = product.ProductWarehouseInventory.Select(i => new ProductWarehouseInventory { WarehouseId = i.WarehouseId, StockQuantity = i.StockQuantity, ReservedQuantity = i.ReservedQuantity }).ToList();
if (string.IsNullOrEmpty(request.WarehouseId))
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductTierPriceCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductTierPriceCommandHandler.cs
index 2aec83fcb..fd49c10ae 100644
--- a/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductTierPriceCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Catalog/UpdateProductTierPriceCommandHandler.cs
@@ -1,8 +1,9 @@
-using Grand.Api.Extensions;
+using Grand.Api.Commands.Models.Catalog;
+using Grand.Api.Extensions;
using Grand.Business.Core.Interfaces.Catalog.Products;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Catalog
{
public class UpdateProductTierPriceCommandHandler : IRequestHandler<UpdateProductTierPriceCommand, bool>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Common/UpdatePictureCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Common/UpdatePictureCommandHandler.cs
index 8744233ab..7dddf5ea3 100644
--- a/src/API/Grand.Api/Commands/Handlers/Common/UpdatePictureCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Common/UpdatePictureCommandHandler.cs
@@ -1,7 +1,8 @@
-using Grand.Business.Core.Interfaces.Storage;
+using Grand.Api.Commands.Models.Common;
+using Grand.Business.Core.Interfaces.Storage;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Handlers.Common
{
public class UpdatePictureCommandHandler : IRequestHandler<UpdatePictureCommand, bool>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Customers/AddCustomerGroupCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Customers/AddCustomerGroupCommandHandler.cs
index c9a3ad29d..035edf6fa 100644
--- a/src/API/Grand.Api/Commands/Handlers/Customers/AddCustomerGroupCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Customers/AddCustomerGroupCommandHandler.cs
@@ -1,4 +1,5 @@
-using Grand.Api.DTOs.Customers;
+using Grand.Api.Commands.Models.Customers;
+using Grand.Api.DTOs.Customers;
using Grand.Api.Extensions;
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
@@ -6,7 +7,7 @@ using Grand.Business.Core.Interfaces.Common.Logging;
using Grand.Infrastructure;
using MediatR;
-namespace Grand.Api.Commands.Models.Customers
+namespace Grand.Api.Commands.Handlers.Customers
{
public class AddCustomerGroupCommandHandler : IRequestHandler<AddCustomerGroupCommand, CustomerGroupDto>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Customers/DeleteCustomerGroupCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Customers/DeleteCustomerGroupCommandHandler.cs
index 4b2a908ed..2c45b57ec 100644
--- a/src/API/Grand.Api/Commands/Handlers/Customers/DeleteCustomerGroupCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Customers/DeleteCustomerGroupCommandHandler.cs
@@ -1,10 +1,11 @@
-using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Api.Commands.Models.Customers;
+using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Logging;
using Grand.Infrastructure;
using MediatR;
-namespace Grand.Api.Commands.Models.Customers
+namespace Grand.Api.Commands.Handlers.Customers
{
public class DeleteCustomerGroupCommandHandler : IRequestHandler<DeleteCustomerGroupCommand, bool>
{
diff --git a/src/API/Grand.Api/Commands/Handlers/Customers/UpdateCustomerGroupCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Customers/UpdateCustomerGroupCommandHandler.cs
index 9c4e381de..8385395af 100644
--- a/src/API/Grand.Api/Commands/Handlers/Customers/UpdateCustomerGroupCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Customers/UpdateCustomerGroupCommandHandler.cs
@@ -1,4 +1,5 @@
-using Grand.Api.DTOs.Customers;
+using Grand.Api.Commands.Models.Customers;
+using Grand.Api.DTOs.Customers;
using Grand.Api.Extensions;
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
@@ -6,7 +7,7 @@ using Grand.Business.Core.Interfaces.Common.Logging;
using Grand.Infrastructure;
using MediatR;
-namespace Grand.Api.Commands.Models.Customers
+namespace Grand.Api.Commands.Handlers.Customers
{
public class UpdateCustomerGroupCommandHandler : IRequestHandler<UpdateCustomerGroupCommand, CustomerGroupDto>
{
diff --git a/src/API/Grand.Api/Commands/Models/Common/UpdatePictureCommand.cs b/src/API/Grand.Api/Commands/Models/Common/UpdatePictureCommand.cs
index 5699c9e97..5be820c7d 100644
--- a/src/API/Grand.Api/Commands/Models/Common/UpdatePictureCommand.cs
+++ b/src/API/Grand.Api/Commands/Models/Common/UpdatePictureCommand.cs
@@ -1,7 +1,7 @@
using Grand.Api.DTOs.Common;
using MediatR;
-namespace Grand.Api.Commands.Models.Catalog
+namespace Grand.Api.Commands.Models.Common
{
public class UpdatePictureCommand : IRequest<bool>
{
diff --git a/src/API/Grand.Api/Controllers/OData/BrandController.cs b/src/API/Grand.Api/Controllers/OData/BrandController.cs
index f1d63279b..494d0731d 100644
--- a/src/API/Grand.Api/Controllers/OData/BrandController.cs
+++ b/src/API/Grand.Api/Controllers/OData/BrandController.cs
@@ -59,7 +59,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Brands)) return Forbid();
- model = await _mediator.Send(new AddBrandCommand() { Model = model });
+ model = await _mediator.Send(new AddBrandCommand { Model = model });
return Ok(model);
}
@@ -76,7 +76,7 @@ namespace Grand.Api.Controllers.OData
var brand = await _mediator.Send(new GetGenericQuery<BrandDto, Domain.Catalog.Brand>(model.Id));
if (!brand.Any()) return NotFound();
- model = await _mediator.Send(new UpdateBrandCommand() { Model = model });
+ model = await _mediator.Send(new UpdateBrandCommand { Model = model });
return Ok(model);
}
@@ -95,7 +95,7 @@ namespace Grand.Api.Controllers.OData
var man = brand.FirstOrDefault();
model.ApplyTo(man);
- await _mediator.Send(new UpdateBrandCommand() { Model = man });
+ await _mediator.Send(new UpdateBrandCommand { Model = man });
return Ok();
}
@@ -111,7 +111,7 @@ namespace Grand.Api.Controllers.OData
var brand = await _mediator.Send(new GetGenericQuery<BrandDto, Domain.Catalog.Brand>(key));
if (!brand.Any()) return NotFound();
- await _mediator.Send(new DeleteBrandCommand() { Model = brand.FirstOrDefault() });
+ await _mediator.Send(new DeleteBrandCommand { Model = brand.FirstOrDefault() });
return Ok();
}
}
diff --git a/src/API/Grand.Api/Controllers/OData/BrandLayoutController.cs b/src/API/Grand.Api/Controllers/OData/BrandLayoutController.cs
index 1d519f1cb..254a40795 100644
--- a/src/API/Grand.Api/Controllers/OData/BrandLayoutController.cs
+++ b/src/API/Grand.Api/Controllers/OData/BrandLayoutController.cs
@@ -29,7 +29,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Maintenance)) return Forbid();
- var layout = await _mediator.Send(new GetLayoutQuery() { Id = key, LayoutName = typeof(Domain.Catalog.BrandLayout).Name });
+ var layout = await _mediator.Send(new GetLayoutQuery { Id = key, LayoutName = typeof(Domain.Catalog.BrandLayout).Name });
if (!layout.Any()) return NotFound();
return Ok(layout.FirstOrDefault());
@@ -44,7 +44,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Maintenance)) return Forbid();
- return Ok(await _mediator.Send(new GetLayoutQuery() { LayoutName = typeof(Domain.Catalog.BrandLayout).Name }));
+ return Ok(await _mediator.Send(new GetLayoutQuery { LayoutName = typeof(Domain.Catalog.BrandLayout).Name }));
}
}
}
diff --git a/src/API/Grand.Api/Controllers/OData/CategoryController.cs b/src/API/Grand.Api/Controllers/OData/CategoryController.cs
index 4c80bb237..469131e25 100644
--- a/src/API/Grand.Api/Controllers/OData/CategoryController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CategoryController.cs
@@ -61,7 +61,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Categories)) return Forbid();
- model = await _mediator.Send(new AddCategoryCommand() { Model = model });
+ model = await _mediator.Send(new AddCategoryCommand { Model = model });
return Ok(model);
}
@@ -78,7 +78,7 @@ namespace Grand.Api.Controllers.OData
var category = await _mediator.Send(new GetGenericQuery<CategoryDto, Domain.Catalog.Category>(model.Id));
if (!category.Any()) return NotFound();
- model = await _mediator.Send(new UpdateCategoryCommand() { Model = model });
+ model = await _mediator.Send(new UpdateCategoryCommand { Model = model });
return Ok(model);
}
[SwaggerOperation(summary: "Update entity in Category (delta)", OperationId = "UpdateCategoryPatch")]
@@ -96,7 +96,7 @@ namespace Grand.Api.Controllers.OData
var cat = category.FirstOrDefault();
model.ApplyTo(cat);
- await _mediator.Send(new UpdateCategoryCommand() { Model = cat });
+ await _mediator.Send(new UpdateCategoryCommand { Model = cat });
return Ok();
}
[SwaggerOperation(summary: "Delete entity from Category", OperationId = "DeleteCategory")]
@@ -111,7 +111,7 @@ namespace Grand.Api.Controllers.OData
var category = await _mediator.Send(new GetGenericQuery<CategoryDto, Domain.Catalog.Category>(key));
if (!category.Any()) return NotFound();
- await _mediator.Send(new DeleteCategoryCommand() { Model = category.FirstOrDefault() });
+ await _mediator.Send(new DeleteCategoryCommand { Model = category.FirstOrDefault() });
return Ok();
}
}
diff --git a/src/API/Grand.Api/Controllers/OData/CategoryLayoutController.cs b/src/API/Grand.Api/Controllers/OData/CategoryLayoutController.cs
index 005ee7eba..de6a30006 100644
--- a/src/API/Grand.Api/Controllers/OData/CategoryLayoutController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CategoryLayoutController.cs
@@ -31,7 +31,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Maintenance)) return Forbid();
- var layout = await _mediator.Send(new GetLayoutQuery() { Id = key, LayoutName = typeof(Domain.Catalog.CategoryLayout).Name });
+ var layout = await _mediator.Send(new GetLayoutQuery { Id = key, LayoutName = typeof(Domain.Catalog.CategoryLayout).Name });
if (!layout.Any()) return NotFound();
return Ok(layout.FirstOrDefault());
@@ -46,7 +46,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Maintenance)) return Forbid();
- return Ok(await _mediator.Send(new GetLayoutQuery() { LayoutName = typeof(Domain.Catalog.CategoryLayout).Name }));
+ return Ok(await _mediator.Send(new GetLayoutQuery { LayoutName = typeof(Domain.Catalog.CategoryLayout).Name }));
}
}
}
diff --git a/src/API/Grand.Api/Controllers/OData/CollectionController.cs b/src/API/Grand.Api/Controllers/OData/CollectionController.cs
index a9da9b8ee..b107ede3f 100644
--- a/src/API/Grand.Api/Controllers/OData/CollectionController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CollectionController.cs
@@ -59,7 +59,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Collections)) return Forbid();
- model = await _mediator.Send(new AddCollectionCommand() { Model = model });
+ model = await _mediator.Send(new AddCollectionCommand { Model = model });
return Ok(model);
}
@@ -76,7 +76,7 @@ namespace Grand.Api.Controllers.OData
var collection = await _mediator.Send(new GetGenericQuery<CollectionDto, Domain.Catalog.Collection>(model.Id));
if (!collection.Any()) return NotFound();
- model = await _mediator.Send(new UpdateCollectionCommand() { Model = model });
+ model = await _mediator.Send(new UpdateCollectionCommand { Model = model });
return Ok(model);
}
@@ -95,7 +95,7 @@ namespace Grand.Api.Controllers.OData
var man = collection.FirstOrDefault();
model.ApplyTo(man);
- await _mediator.Send(new UpdateCollectionCommand() { Model = man });
+ await _mediator.Send(new UpdateCollectionCommand { Model = man });
return Ok();
}
@@ -111,7 +111,7 @@ namespace Grand.Api.Controllers.OData
var collection = await _mediator.Send(new GetGenericQuery<CollectionDto, Domain.Catalog.Collection>(key));
if (!collection.Any()) return NotFound();
- await _mediator.Send(new DeleteCollectionCommand() { Model = collection.FirstOrDefault() });
+ await _mediator.Send(new DeleteCollectionCommand { Model = collection.FirstOrDefault() });
return Ok();
}
diff --git a/src/API/Grand.Api/Controllers/OData/CollectionLayoutController.cs b/src/API/Grand.Api/Controllers/OData/CollectionLayoutController.cs
index 07b90ae2e..8eef0f45e 100644
--- a/src/API/Grand.Api/Controllers/OData/CollectionLayoutController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CollectionLayoutController.cs
@@ -29,7 +29,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Maintenance)) return Forbid();
- var layout = await _mediator.Send(new GetLayoutQuery() { Id = key, LayoutName = typeof(Domain.Catalog.CollectionLayout).Name });
+ var layout = await _mediator.Send(new GetLayoutQuery { Id = key, LayoutName = typeof(Domain.Catalog.CollectionLayout).Name });
if (!layout.Any()) return NotFound();
return Ok(layout.FirstOrDefault());
@@ -44,7 +44,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Maintenance)) return Forbid();
- return Ok(await _mediator.Send(new GetLayoutQuery() { LayoutName = typeof(Domain.Catalog.CollectionLayout).Name }));
+ return Ok(await _mediator.Send(new GetLayoutQuery { LayoutName = typeof(Domain.Catalog.CollectionLayout).Name }));
}
}
}
diff --git a/src/API/Grand.Api/Controllers/OData/CustomerController.cs b/src/API/Grand.Api/Controllers/OData/CustomerController.cs
index 7479d9755..346437cbc 100644
--- a/src/API/Grand.Api/Controllers/OData/CustomerController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CustomerController.cs
@@ -42,7 +42,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid();
- var customer = await _mediator.Send(new GetCustomerQuery() { Email = key });
+ var customer = await _mediator.Send(new GetCustomerQuery { Email = key });
if (customer == null) return NotFound();
return Ok(customer);
@@ -57,7 +57,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid();
- model = await _mediator.Send(new AddCustomerCommand() { Model = model });
+ model = await _mediator.Send(new AddCustomerCommand { Model = model });
return Ok(model);
}
@@ -70,7 +70,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid();
- model = await _mediator.Send(new UpdateCustomerCommand() { Model = model });
+ model = await _mediator.Send(new UpdateCustomerCommand { Model = model });
return Ok(model);
}
@@ -83,10 +83,10 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid();
- var customer = await _mediator.Send(new GetCustomerQuery() { Email = key });
+ var customer = await _mediator.Send(new GetCustomerQuery { Email = key });
if (customer == null) return NotFound();
- await _mediator.Send(new DeleteCustomerCommand() { Email = key });
+ await _mediator.Send(new DeleteCustomerCommand { Email = key });
return Ok();
}
@@ -103,10 +103,10 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid();
- var customer = await _mediator.Send(new GetCustomerQuery() { Email = key });
+ var customer = await _mediator.Send(new GetCustomerQuery { Email = key });
if (customer == null) return NotFound();
- address = await _mediator.Send(new AddCustomerAddressCommand() { Customer = customer, Address = address });
+ address = await _mediator.Send(new AddCustomerAddressCommand { Customer = customer, Address = address });
return Ok(address);
}
@@ -122,10 +122,10 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid();
- var customer = await _mediator.Send(new GetCustomerQuery() { Email = key });
+ var customer = await _mediator.Send(new GetCustomerQuery { Email = key });
if (customer == null) return NotFound();
- address = await _mediator.Send(new UpdateCustomerAddressCommand() { Customer = customer, Address = address });
+ address = await _mediator.Send(new UpdateCustomerAddressCommand { Customer = customer, Address = address });
return Ok(address);
}
@@ -144,13 +144,13 @@ namespace Grand.Api.Controllers.OData
if (model == null || string.IsNullOrEmpty(model.AddressId)) return NotFound();
- var customer = await _mediator.Send(new GetCustomerQuery() { Email = key });
+ var customer = await _mediator.Send(new GetCustomerQuery { Email = key });
if (customer == null) return NotFound();
- var address = customer.Addresses.FirstOrDefault(x => x.Id == model.AddressId.ToString());
+ var address = customer.Addresses.FirstOrDefault(x => x.Id == model.AddressId);
if (address == null) return NotFound();
- await _mediator.Send(new DeleteCustomerAddressCommand() { Customer = customer, Address = address });
+ await _mediator.Send(new DeleteCustomerAddressCommand { Customer = customer, Address = address });
return Ok(true);
}
diff --git a/src/API/Grand.Api/Controllers/OData/CustomerGroupController.cs b/src/API/Grand.Api/Controllers/OData/CustomerGroupController.cs
index d7159e94e..1d25f55f1 100644
--- a/src/API/Grand.Api/Controllers/OData/CustomerGroupController.cs
+++ b/src/API/Grand.Api/Controllers/OData/CustomerGroupController.cs
@@ -60,7 +60,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid();
- model = await _mediator.Send(new AddCustomerGroupCommand() { Model = model });
+ model = await _mediator.Send(new AddCustomerGroupCommand { Model = model });
return Ok(model);
}
@@ -79,7 +79,7 @@ namespace Grand.Api.Controllers.OData
if (!model.IsSystem)
{
- model = await _mediator.Send(new UpdateCustomerGroupCommand() { Model = model });
+ model = await _mediator.Send(new UpdateCustomerGroupCommand { Model = model });
return Ok(model);
}
return BadRequest(ModelState);
@@ -102,7 +102,7 @@ namespace Grand.Api.Controllers.OData
model.ApplyTo(cr);
if (!cr.IsSystem)
{
- await _mediator.Send(new UpdateCustomerGroupCommand() { Model = cr });
+ await _mediator.Send(new UpdateCustomerGroupCommand { Model = cr });
return Ok();
}
return BadRequest(ModelState);
@@ -120,9 +120,9 @@ namespace Grand.Api.Controllers.OData
var customerGroup = await _mediator.Send(new GetGenericQuery<CustomerGroupDto, Domain.Customers.CustomerGroup>(key));
if (!customerGroup.Any()) return NotFound();
- if (customerGroup.FirstOrDefault().IsSystem) return Forbid();
+ if (customerGroup.FirstOrDefault()!.IsSystem) return Forbid();
- await _mediator.Send(new DeleteCustomerGroupCommand() { Model = customerGroup.FirstOrDefault() });
+ await _mediator.Send(new DeleteCustomerGroupCommand { Model = customerGroup.FirstOrDefault() });
return Ok();
}
diff --git a/src/API/Grand.Api/Controllers/OData/PictureController.cs b/src/API/Grand.Api/Controllers/OData/PictureController.cs
index ff54c0938..bcf389096 100644
--- a/src/API/Grand.Api/Controllers/OData/PictureController.cs
+++ b/src/API/Grand.Api/Controllers/OData/PictureController.cs
@@ -1,5 +1,4 @@
-using Grand.Api.Commands.Models.Catalog;
-using Grand.Api.Commands.Models.Common;
+using Grand.Api.Commands.Models.Common;
using Grand.Api.DTOs.Common;
using Grand.Api.Queries.Models.Common;
using Grand.Business.Core.Interfaces.Common.Security;
@@ -46,7 +45,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Pictures)) return Forbid();
- model = await _mediator.Send(new AddPictureCommand() { PictureDto = model });
+ model = await _mediator.Send(new AddPictureCommand { PictureDto = model });
return Ok(model);
}
@@ -63,7 +62,7 @@ namespace Grand.Api.Controllers.OData
var picture = await _mediator.Send(new GetGenericQuery<PictureDto, Domain.Media.Picture>(model.Id));
if (picture == null || !picture.Any()) return NotFound();
- var result = await _mediator.Send(new UpdatePictureCommand() { Model = model });
+ var result = await _mediator.Send(new UpdatePictureCommand { Model = model });
return Ok(result);
}
@@ -79,7 +78,7 @@ namespace Grand.Api.Controllers.OData
var picture = await _mediator.Send(new GetGenericQuery<PictureDto, Domain.Media.Picture>(key));
if (picture == null || !picture.Any()) return NotFound();
- await _mediator.Send(new DeletePictureCommand() { PictureDto = picture.FirstOrDefault() });
+ await _mediator.Send(new DeletePictureCommand { PictureDto = picture.FirstOrDefault() });
return Ok();
}
}
diff --git a/src/API/Grand.Api/Controllers/OData/ProductAttributeController.cs b/src/API/Grand.Api/Controllers/OData/ProductAttributeController.cs
index 4992fc81c..589c07343 100644
--- a/src/API/Grand.Api/Controllers/OData/ProductAttributeController.cs
+++ b/src/API/Grand.Api/Controllers/OData/ProductAttributeController.cs
@@ -62,7 +62,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.ProductAttributes)) return Forbid();
- model = await _mediator.Send(new AddProductAttributeCommand() { Model = model });
+ model = await _mediator.Send(new AddProductAttributeCommand { Model = model });
return Ok(model);
}
@@ -75,7 +75,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.ProductAttributes)) return Forbid();
- model = await _mediator.Send(new UpdateProductAttributeCommand() { Model = model });
+ model = await _mediator.Send(new UpdateProductAttributeCommand { Model = model });
return Ok(model);
}
@@ -94,7 +94,7 @@ namespace Grand.Api.Controllers.OData
var pa = productAttribute.FirstOrDefault();
model.ApplyTo(pa);
- pa = await _mediator.Send(new UpdateProductAttributeCommand() { Model = pa });
+ pa = await _mediator.Send(new UpdateProductAttributeCommand { Model = pa });
return Ok(pa);
}
@@ -110,7 +110,7 @@ namespace Grand.Api.Controllers.OData
var productAttribute = await _mediator.Send(new GetGenericQuery<ProductAttributeDto, Domain.Catalog.ProductAttribute>(key));
if (!productAttribute.Any()) return NotFound();
- await _mediator.Send(new DeleteProductAttributeCommand() { Model = productAttribute.FirstOrDefault() });
+ await _mediator.Send(new DeleteProductAttributeCommand { Model = productAttribute.FirstOrDefault() });
return Ok();
}
}
diff --git a/src/API/Grand.Api/Controllers/OData/ProductController.cs b/src/API/Grand.Api/Controllers/OData/ProductController.cs
index 01b67ad52..790228848 100644
--- a/src/API/Grand.Api/Controllers/OData/ProductController.cs
+++ b/src/API/Grand.Api/Controllers/OData/ProductController.cs
@@ -62,7 +62,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid();
- model = await _mediator.Send(new AddProductCommand() { Model = model });
+ model = await _mediator.Send(new AddProductCommand { Model = model });
return Ok(model);
}
@@ -75,7 +75,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid();
- await _mediator.Send(new UpdateProductCommand() { Model = model });
+ await _mediator.Send(new UpdateProductCommand { Model = model });
return Ok();
}
@@ -94,7 +94,7 @@ namespace Grand.Api.Controllers.OData
var pr = product.FirstOrDefault();
model.ApplyTo(pr!, ModelState);
- await _mediator.Send(new UpdateProductCommand() { Model = pr });
+ await _mediator.Send(new UpdateProductCommand { Model = pr });
return Ok();
}
@@ -110,7 +110,7 @@ namespace Grand.Api.Controllers.OData
var product = await _mediator.Send(new GetGenericQuery<ProductDto, Domain.Catalog.Product>(key));
if (!product.Any()) return NotFound();
- await _mediator.Send(new DeleteProductCommand() { Model = product.FirstOrDefault() });
+ await _mediator.Send(new DeleteProductCommand { Model = product.FirstOrDefault() });
return Ok();
}
@@ -133,7 +133,7 @@ namespace Grand.Api.Controllers.OData
if (model == null) return BadRequest();
- await _mediator.Send(new UpdateProductStockCommand() { Product = product.FirstOrDefault(), WarehouseId = model.WarehouseId, Stock = model.Stock });
+ await _mediator.Send(new UpdateProductStockCommand { Product = product.FirstOrDefault(), WarehouseId = model.WarehouseId, Stock = model.Stock });
return Ok(true);
}
@@ -161,7 +161,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- var result = await _mediator.Send(new AddProductCategoryCommand() { Product = product.FirstOrDefault(), Model = productCategory });
+ var result = await _mediator.Send(new AddProductCategoryCommand { Product = product.FirstOrDefault(), Model = productCategory });
return Ok(result);
}
return BadRequest(ModelState);
@@ -188,7 +188,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- var result = await _mediator.Send(new UpdateProductCategoryCommand() { Product = product.FirstOrDefault(), Model = productCategory });
+ var result = await _mediator.Send(new UpdateProductCategoryCommand { Product = product.FirstOrDefault(), Model = productCategory });
return Ok(result);
}
return BadRequest(ModelState);
@@ -218,7 +218,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- _ = await _mediator.Send(new DeleteProductCategoryCommand() { Product = product.FirstOrDefault(), CategoryId = categoryId });
+ _ = await _mediator.Send(new DeleteProductCategoryCommand { Product = product.FirstOrDefault(), CategoryId = categoryId });
return Ok(true);
}
return BadRequest(ModelState);
@@ -251,7 +251,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- var result = await _mediator.Send(new AddProductCollectionCommand() { Product = product.FirstOrDefault(), Model = productCollection });
+ var result = await _mediator.Send(new AddProductCollectionCommand { Product = product.FirstOrDefault(), Model = productCollection });
return Ok(result);
}
return BadRequest(ModelState);
@@ -278,7 +278,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- var result = await _mediator.Send(new UpdateProductCollectionCommand() { Product = product.FirstOrDefault(), Model = productCollection });
+ var result = await _mediator.Send(new UpdateProductCollectionCommand { Product = product.FirstOrDefault(), Model = productCollection });
return Ok(result);
}
return BadRequest(ModelState);
@@ -308,7 +308,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- var result = await _mediator.Send(new DeleteProductCollectionCommand() { Product = product.FirstOrDefault(), CollectionId = collectionId });
+ await _mediator.Send(new DeleteProductCollectionCommand { Product = product.FirstOrDefault(), CollectionId = collectionId });
return Ok(true);
}
return BadRequest(ModelState);
@@ -341,7 +341,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- var result = await _mediator.Send(new AddProductPictureCommand() { Product = product.FirstOrDefault(), Model = productPicture });
+ var result = await _mediator.Send(new AddProductPictureCommand { Product = product.FirstOrDefault(), Model = productPicture });
return Ok(result);
}
return BadRequest(ModelState);
@@ -368,7 +368,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- var result = await _mediator.Send(new UpdateProductPictureCommand() { Product = product.FirstOrDefault(), Model = productPicture });
+ var result = await _mediator.Send(new UpdateProductPictureCommand { Product = product.FirstOrDefault(), Model = productPicture });
return Ok(result);
}
return BadRequest(ModelState);
@@ -398,7 +398,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- var result = await _mediator.Send(new DeleteProductPictureCommand() { Product = product.FirstOrDefault(), PictureId = pictureId });
+ var result = await _mediator.Send(new DeleteProductPictureCommand { Product = product.FirstOrDefault(), PictureId = pictureId });
return Ok(result);
}
return BadRequest(ModelState);
@@ -431,7 +431,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- var result = await _mediator.Send(new AddProductSpecificationCommand() { Product = product.FirstOrDefault(), Model = productSpecification });
+ var result = await _mediator.Send(new AddProductSpecificationCommand { Product = product.FirstOrDefault(), Model = productSpecification });
return Ok(result);
}
return BadRequest(ModelState);
@@ -458,7 +458,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- var result = await _mediator.Send(new UpdateProductSpecificationCommand() { Product = product.FirstOrDefault(), Model = productSpecification });
+ var result = await _mediator.Send(new UpdateProductSpecificationCommand { Product = product.FirstOrDefault(), Model = productSpecification });
return Ok(result);
}
return BadRequest(ModelState);
@@ -488,7 +488,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- var result = await _mediator.Send(new DeleteProductSpecificationCommand() { Product = product.FirstOrDefault(), Id = specificationId });
+ var result = await _mediator.Send(new DeleteProductSpecificationCommand { Product = product.FirstOrDefault(), Id = specificationId });
return Ok(result);
}
return BadRequest(ModelState);
@@ -521,7 +521,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- var result = await _mediator.Send(new AddProductTierPriceCommand() { Product = product.FirstOrDefault(), Model = productTierPrice });
+ var result = await _mediator.Send(new AddProductTierPriceCommand { Product = product.FirstOrDefault(), Model = productTierPrice });
return Ok(result);
}
return BadRequest(ModelState);
@@ -548,7 +548,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- var result = await _mediator.Send(new UpdateProductTierPriceCommand() { Product = product.FirstOrDefault(), Model = productTierPrice });
+ var result = await _mediator.Send(new UpdateProductTierPriceCommand { Product = product.FirstOrDefault(), Model = productTierPrice });
return Ok(result);
}
return BadRequest(ModelState);
@@ -578,7 +578,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- var result = await _mediator.Send(new DeleteProductTierPriceCommand() { Product = product.FirstOrDefault(), Id = tierPriceId });
+ var result = await _mediator.Send(new DeleteProductTierPriceCommand { Product = product.FirstOrDefault(), Id = tierPriceId });
return Ok(result);
}
return BadRequest(ModelState);
@@ -611,7 +611,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- var result = await _mediator.Send(new AddProductAttributeMappingCommand() { Product = product.FirstOrDefault(), Model = productAttributeMapping });
+ var result = await _mediator.Send(new AddProductAttributeMappingCommand { Product = product.FirstOrDefault(), Model = productAttributeMapping });
return Ok(result);
}
return BadRequest(ModelState);
@@ -638,7 +638,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- var result = await _mediator.Send(new UpdateProductAttributeMappingCommand() { Product = product.FirstOrDefault(), Model = productAttributeMapping });
+ var result = await _mediator.Send(new UpdateProductAttributeMappingCommand { Product = product.FirstOrDefault(), Model = productAttributeMapping });
return Ok(result);
}
return BadRequest(ModelState);
@@ -668,7 +668,7 @@ namespace Grand.Api.Controllers.OData
if (ModelState.IsValid)
{
- var result = await _mediator.Send(new DeleteProductAttributeMappingCommand() { Product = product.FirstOrDefault(), Model = pam });
+ var result = await _mediator.Send(new DeleteProductAttributeMappingCommand { Product = product.FirstOrDefault(), Model = pam });
return Ok(result);
}
return BadRequest(ModelState);
diff --git a/src/API/Grand.Api/Controllers/OData/ProductLayoutController.cs b/src/API/Grand.Api/Controllers/OData/ProductLayoutController.cs
index 030751c4e..3452010af 100644
--- a/src/API/Grand.Api/Controllers/OData/ProductLayoutController.cs
+++ b/src/API/Grand.Api/Controllers/OData/ProductLayoutController.cs
@@ -29,7 +29,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Maintenance)) return Forbid();
- var layout = await _mediator.Send(new GetLayoutQuery() { Id = key, LayoutName = typeof(Domain.Catalog.ProductLayout).Name });
+ var layout = await _mediator.Send(new GetLayoutQuery { Id = key, LayoutName = typeof(Domain.Catalog.ProductLayout).Name });
if (!layout.Any()) return NotFound();
return Ok(layout.FirstOrDefault());
@@ -45,7 +45,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.Maintenance)) return Forbid();
- return Ok(await _mediator.Send(new GetLayoutQuery() { LayoutName = typeof(Domain.Catalog.ProductLayout).Name }));
+ return Ok(await _mediator.Send(new GetLayoutQuery { LayoutName = typeof(Domain.Catalog.ProductLayout).Name }));
}
}
}
diff --git a/src/API/Grand.Api/Controllers/OData/SpecificationAttributeController.cs b/src/API/Grand.Api/Controllers/OData/SpecificationAttributeController.cs
index 6d61d53e4..3ea848122 100644
--- a/src/API/Grand.Api/Controllers/OData/SpecificationAttributeController.cs
+++ b/src/API/Grand.Api/Controllers/OData/SpecificationAttributeController.cs
@@ -59,7 +59,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.SpecificationAttributes)) return Forbid();
- model = await _mediator.Send(new AddSpecificationAttributeCommand() { Model = model });
+ model = await _mediator.Send(new AddSpecificationAttributeCommand { Model = model });
return Ok(model);
}
@@ -72,7 +72,7 @@ namespace Grand.Api.Controllers.OData
{
if (!await _permissionService.Authorize(PermissionSystemName.SpecificationAttributes)) return Forbid();
- model = await _mediator.Send(new UpdateSpecificationAttributeCommand() { Model = model });
+ model = await _mediator.Send(new UpdateSpecificationAttributeCommand { Model = model });
return Ok(model);
}
@@ -91,7 +91,7 @@ namespace Grand.Api.Controllers.OData
var spec = specification.FirstOrDefault();
model.ApplyTo(spec);
- await _mediator.Send(new UpdateSpecificationAttributeCommand() { Model = spec });
+ await _mediator.Send(new UpdateSpecificationAttributeCommand { Model = spec });
return Ok();
}
@@ -107,7 +107,7 @@ namespace Grand.Api.Controllers.OData
var specification = await _mediator.Send(new GetGenericQuery<SpecificationAttributeDto, Domain.Catalog.SpecificationAttribute>(key));
if (!specification.Any()) return NotFound();
- await _mediator.Send(new DeleteSpecificationAttributeCommand() { Model = specification.FirstOrDefault() });
+ await _mediator.Send(new DeleteSpecificationAttributeCommand { Model = specification.FirstOrDefault() });
return Ok();
}
diff --git a/src/API/Grand.Api/Controllers/TokenController.cs b/src/API/Grand.Api/Controllers/TokenController.cs
index 7d3d30902..0294b93e4 100644
--- a/src/API/Grand.Api/Controllers/TokenController.cs
+++ b/src/API/Grand.Api/Controllers/TokenController.cs
@@ -39,7 +39,7 @@ namespace Grand.Api.Controllers
if (user != null)
claims.Add("Token", user.Token);
- var token = await _mediator.Send(new GenerateTokenCommand() { Claims = claims });
+ var token = await _mediator.Send(new GenerateTokenCommand { Claims = claims });
return Content(token);
}
}
diff --git a/src/API/Grand.Api/Controllers/TokenWebController.cs b/src/API/Grand.Api/Controllers/TokenWebController.cs
index aa42e23f1..c7b7d9e55 100644
--- a/src/API/Grand.Api/Controllers/TokenWebController.cs
+++ b/src/API/Grand.Api/Controllers/TokenWebController.cs
@@ -97,10 +97,10 @@ namespace Grand.Api.Controllers
if (!_apiConfig.Enabled)
return BadRequest("API is disabled");
- string email = null, guid = null;
+ string email;
Customer customer = null;
var claims = new Dictionary<string, string>();
- ClaimsPrincipal principal = null;
+ ClaimsPrincipal principal;
try
{
principal = _refreshTokenService.GetPrincipalFromToken(tokenDto.AccessToken);
@@ -118,9 +118,12 @@ namespace Grand.Api.Controllers
}
else
{
- guid = principal.Claims.ToList().FirstOrDefault(x => x.Type == "Guid")?.Value;
- customer = await _customerService.GetCustomerByGuid(Guid.Parse(guid));
- claims.Add("Guid", guid);
+ var guid = principal.Claims.ToList().FirstOrDefault(x => x.Type == "Guid")?.Value;
+ if (guid != null)
+ {
+ customer = await _customerService.GetCustomerByGuid(Guid.Parse(guid));
+ claims.Add("Guid", guid);
+ }
}
var customerRefreshToken = await _refreshTokenService.GetCustomerRefreshToken(customer);
@@ -133,7 +136,7 @@ namespace Grand.Api.Controllers
{
return BadRequest("Token expired");
}
- var token = await GetToken(claims, customer); ;
+ var token = await GetToken(claims, customer);
return Ok(token);
}
@@ -153,8 +156,8 @@ namespace Grand.Api.Controllers
var refreshTokenValue = _refreshTokenService.GenerateRefreshToken();
var refreshToken = await _refreshTokenService.SaveRefreshTokenToCustomer(customer, refreshTokenValue);
claims.Add("RefreshId", refreshToken.RefreshId);
- var token = await _mediator.Send(new GenerateTokenWebCommand() { Claims = claims });
- return new TokenDto() {
+ var token = await _mediator.Send(new GenerateTokenWebCommand { Claims = claims });
+ return new TokenDto {
AccessToken = token,
RefreshToken = refreshTokenValue
};
diff --git a/src/API/Grand.Api/Extensions/AddParamOperationFilter.cs b/src/API/Grand.Api/Extensions/AddParamOperationFilter.cs
index 54b65a666..807d9f78f 100644
--- a/src/API/Grand.Api/Extensions/AddParamOperationFilter.cs
+++ b/src/API/Grand.Api/Extensions/AddParamOperationFilter.cs
@@ -11,7 +11,7 @@ namespace Grand.Api.Extensions
if (context.ApiDescription.GroupName == "v1" && context.ApiDescription.HttpMethod == "GET" &&
context.ApiDescription.ParameterDescriptions.Count == 0)
{
- ApplyV1(operation, context);
+ ApplyV1(operation);
}
if (context.ApiDescription.GroupName == "v2" && context.ApiDescription.HttpMethod == "POST")
@@ -20,57 +20,57 @@ namespace Grand.Api.Extensions
}
}
- private void ApplyV1(OpenApiOperation operation, OperationFilterContext context)
+ private void ApplyV1(OpenApiOperation operation)
{
- operation.Parameters.Add(new OpenApiParameter() {
+ operation.Parameters.Add(new OpenApiParameter {
Name = "$top",
AllowReserved = true,
In = ParameterLocation.Query,
Description = "Show only the first n items.",
Required = false,
- Schema = new OpenApiSchema() {
+ Schema = new OpenApiSchema {
Minimum = 0,
Type = "integer"
}
});
- operation.Parameters.Add(new OpenApiParameter() {
+ operation.Parameters.Add(new OpenApiParameter {
Name = "$skip",
AllowReserved = true,
In = ParameterLocation.Query,
Description = "Skip the first n items",
Required = false,
- Schema = new OpenApiSchema() {
+ Schema = new OpenApiSchema {
Minimum = 0,
Type = "integer"
}
});
- operation.Parameters.Add(new OpenApiParameter() {
+ operation.Parameters.Add(new OpenApiParameter {
Name = "$count",
AllowReserved = true,
In = ParameterLocation.Query,
Description = "Include count of items",
Required = false,
- Schema = new OpenApiSchema() {
+ Schema = new OpenApiSchema {
Type = "boolean"
}
});
- operation.Parameters.Add(new OpenApiParameter() {
+ operation.Parameters.Add(new OpenApiParameter {
Name = "$orderby",
AllowReserved = true,
In = ParameterLocation.Query,
Description = "Order items by property values",
Required = false,
- Schema = new OpenApiSchema() {
+ Schema = new OpenApiSchema {
Type = "string"
}
});
- operation.Parameters.Add(new OpenApiParameter() {
+ operation.Parameters.Add(new OpenApiParameter {
Name = "$filter",
AllowReserved = true,
In = ParameterLocation.Query,
Description = "Filter items by property values",
Required = false,
- Schema = new OpenApiSchema() {
+ Schema = new OpenApiSchema {
Type = "string"
}
});
diff --git a/src/API/Grand.Api/Infrastructure/DependencyManagement/IDependencyEdmModel.cs b/src/API/Grand.Api/Infrastructure/DependencyManagement/IDependencyEdmModel.cs
index 259e23805..0ddff2334 100644
--- a/src/API/Grand.Api/Infrastructure/DependencyManagement/IDependencyEdmModel.cs
+++ b/src/API/Grand.Api/Infrastructure/DependencyManagement/IDependencyEdmModel.cs
@@ -9,6 +9,7 @@ namespace Grand.Api.Infrastructure.DependencyManagement
/// Register edmmodel
/// </summary>
/// <param name="builder">OData Convention Model Builder</param>
+ /// <param name="apiConfig">ApiConfig</param>
void Register(ODataConventionModelBuilder builder, BackendAPIConfig apiConfig);
/// <summary>
diff --git a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/AddressProfile.cs b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/AddressProfile.cs
index c573102ed..53cfd1012 100644
--- a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/AddressProfile.cs
+++ b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/AddressProfile.cs
@@ -3,7 +3,7 @@ using Grand.Api.DTOs.Customers;
using Grand.Domain.Common;
using Grand.Infrastructure.Mapper;
-namespace Grand.Api.Infrastructure.Mapper
+namespace Grand.Api.Infrastructure.Mapper.Profiles
{
public class AddressProfile : Profile, IAutoMapperProfile
{
diff --git a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/BrandProfile.cs b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/BrandProfile.cs
index b65dbe582..09df385ab 100644
--- a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/BrandProfile.cs
+++ b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/BrandProfile.cs
@@ -3,7 +3,7 @@ using Grand.Api.DTOs.Catalog;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Mapper;
-namespace Grand.Api.Infrastructure.Mapper
+namespace Grand.Api.Infrastructure.Mapper.Profiles
{
public class BrandProfile : Profile, IAutoMapperProfile
{
diff --git a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/CategoryProfile.cs b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/CategoryProfile.cs
index debc1739a..d7db097ae 100644
--- a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/CategoryProfile.cs
+++ b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/CategoryProfile.cs
@@ -3,7 +3,7 @@ using Grand.Api.DTOs.Catalog;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Mapper;
-namespace Grand.Api.Infrastructure.Mapper
+namespace Grand.Api.Infrastructure.Mapper.Profiles
{
public class CategoryProfile : Profile, IAutoMapperProfile
{
diff --git a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/CollectionProfile.cs b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/CollectionProfile.cs
index 4bed6faee..752891adc 100644
--- a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/CollectionProfile.cs
+++ b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/CollectionProfile.cs
@@ -3,7 +3,7 @@ using Grand.Api.DTOs.Catalog;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Mapper;
-namespace Grand.Api.Infrastructure.Mapper
+namespace Grand.Api.Infrastructure.Mapper.Profiles
{
public class CollectionProfile : Profile, IAutoMapperProfile
{
diff --git a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/CustomerGroupProfile.cs b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/CustomerGroupProfile.cs
index 2e3bf6287..5fe37921d 100644
--- a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/CustomerGroupProfile.cs
+++ b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/CustomerGroupProfile.cs
@@ -3,7 +3,7 @@ using Grand.Api.DTOs.Customers;
using Grand.Domain.Customers;
using Grand.Infrastructure.Mapper;
-namespace Grand.Api.Infrastructure.Mapper
+namespace Grand.Api.Infrastructure.Mapper.Profiles
{
public class CustomerGroupProfile : Profile, IAutoMapperProfile
{
diff --git a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/CustomerProfile.cs b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/CustomerProfile.cs
index fea158616..50c6d5573 100644
--- a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/CustomerProfile.cs
+++ b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/CustomerProfile.cs
@@ -4,7 +4,7 @@ using Grand.Domain.Common;
using Grand.Domain.Customers;
using Grand.Infrastructure.Mapper;
-namespace Grand.Api.Infrastructure.Mapper
+namespace Grand.Api.Infrastructure.Mapper.Profiles
{
public class CustomerProfile : Profile, IAutoMapperProfile
{
diff --git a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/PictureProfile.cs b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/PictureProfile.cs
index a673c6aaa..db14a6ce1 100644
--- a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/PictureProfile.cs
+++ b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/PictureProfile.cs
@@ -3,7 +3,7 @@ using Grand.Api.DTOs.Common;
using Grand.Domain.Media;
using Grand.Infrastructure.Mapper;
-namespace Grand.Api.Infrastructure.Mapper
+namespace Grand.Api.Infrastructure.Mapper.Profiles
{
public class PictureProfile : Profile, IAutoMapperProfile
{
diff --git a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/ProductAttributeMappingProfile.cs b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/ProductAttributeMappingProfile.cs
index 357409d5f..dab84d08e 100644
--- a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/ProductAttributeMappingProfile.cs
+++ b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/ProductAttributeMappingProfile.cs
@@ -3,7 +3,7 @@ using Grand.Api.DTOs.Catalog;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Mapper;
-namespace Grand.Api.Infrastructure.Mapper
+namespace Grand.Api.Infrastructure.Mapper.Profiles
{
public class ProductAttributeMappingProfile : Profile, IAutoMapperProfile
{
diff --git a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/ProductAttributeProfile.cs b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/ProductAttributeProfile.cs
index b536b131e..461f9fdbb 100644
--- a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/ProductAttributeProfile.cs
+++ b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/ProductAttributeProfile.cs
@@ -3,7 +3,7 @@ using Grand.Api.DTOs.Catalog;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Mapper;
-namespace Grand.Api.Infrastructure.Mapper
+namespace Grand.Api.Infrastructure.Mapper.Profiles
{
public class ProductAttributeProfile : Profile, IAutoMapperProfile
{
diff --git a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/ProductProfile.cs b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/ProductProfile.cs
index 44b21f843..f575b572e 100644
--- a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/ProductProfile.cs
+++ b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/ProductProfile.cs
@@ -3,7 +3,7 @@ using Grand.Api.DTOs.Catalog;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Mapper;
-namespace Grand.Api.Infrastructure.Mapper
+namespace Grand.Api.Infrastructure.Mapper.Profiles
{
public class ProductProfile : Profile, IAutoMapperProfile
{
diff --git a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/SpecificationAttributeProfile.cs b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/SpecificationAttributeProfile.cs
index fc75e8908..6b0a8efe7 100644
--- a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/SpecificationAttributeProfile.cs
+++ b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/SpecificationAttributeProfile.cs
@@ -3,7 +3,7 @@ using Grand.Api.DTOs.Catalog;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Mapper;
-namespace Grand.Api.Infrastructure.Mapper
+namespace Grand.Api.Infrastructure.Mapper.Profiles
{
public class SpecificationAttributeProfile : Profile, IAutoMapperProfile
{
diff --git a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/TierPriceProfile.cs b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/TierPriceProfile.cs
index eca5e4b9f..fed5c4925 100644
--- a/src/API/Grand.Api/Infrastructure/Mapper/Profiles/TierPriceProfile.cs
+++ b/src/API/Grand.Api/Infrastructure/Mapper/Profiles/TierPriceProfile.cs
@@ -3,7 +3,7 @@ using Grand.Api.DTOs.Catalog;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Mapper;
-namespace Grand.Api.Infrastructure.Mapper
+namespace Grand.Api.Infrastructure.Mapper.Profiles
{
public class TierPriceProfile : Profile, IAutoMapperProfile
{
diff --git a/src/API/Grand.Api/Infrastructure/ODataStartup.cs b/src/API/Grand.Api/Infrastructure/ODataStartup.cs
index 1d679995f..109a1fa39 100644
--- a/src/API/Grand.Api/Infrastructure/ODataStartup.cs
+++ b/src/API/Grand.Api/Infrastructure/ODataStartup.cs
@@ -81,11 +81,11 @@ namespace Grand.Api.Infrastructure
//create and sort instances of dependency inject
var instances = dependencyInject
.Select(di => (IDependencyEdmModel)Activator.CreateInstance(di))
- .OrderBy(di => di.Order);
+ .OrderBy(di => di!.Order);
//register all provided dependencies
foreach (var dependencyRegistrar in instances)
- dependencyRegistrar.Register(builder, apiConfig);
+ dependencyRegistrar!.Register(builder, apiConfig);
}
diff --git a/src/API/Grand.Api/Jwt/JwtTokenBuilder.cs b/src/API/Grand.Api/Jwt/JwtTokenBuilder.cs
index 857bc5178..ca708fc3d 100644
--- a/src/API/Grand.Api/Jwt/JwtTokenBuilder.cs
+++ b/src/API/Grand.Api/Jwt/JwtTokenBuilder.cs
@@ -6,7 +6,7 @@ namespace Grand.Api.Jwt
{
public sealed class JwtTokenBuilder
{
- private SecurityKey securityKey = null;
+ private SecurityKey securityKey;
private bool useissuer;
private string issuer = "";
private bool useaudience;
@@ -17,13 +17,13 @@ namespace Grand.Api.Jwt
private void EnsureArguments()
{
if (this.securityKey == null)
- throw new ArgumentNullException("Security Key");
+ throw new ArgumentNullException(nameof(securityKey));
if (this.useissuer && string.IsNullOrEmpty(this.issuer))
- throw new ArgumentNullException("Issuer");
+ throw new ArgumentNullException(nameof(issuer));
if (this.useaudience && string.IsNullOrEmpty(this.audience))
- throw new ArgumentNullException("Audience");
+ throw new ArgumentNullException(nameof(audience));
}
public JwtTokenBuilder AddSecurityKey(SecurityKey securityKey)
diff --git a/src/API/Grand.Api/Queries/Handlers/Common/GetLayoutQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Common/GetLayoutQueryHandler.cs
index af82926eb..7202c54d8 100644
--- a/src/API/Grand.Api/Queries/Handlers/Common/GetLayoutQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Common/GetLayoutQueryHandler.cs
@@ -20,8 +20,7 @@ namespace Grand.Api.Queries.Handlers.Common
if (string.IsNullOrEmpty(request.Id))
return query;
- else
- return await Task.FromResult(query.Where(x => x.Id == request.Id));
+ return await Task.FromResult(query.Where(x => x.Id == request.Id));
}
}
diff --git a/src/API/Grand.Api/Validators/Catalog/BrandValidator.cs b/src/API/Grand.Api/Validators/Catalog/BrandValidator.cs
index 268c7bee8..03ab33519 100644
--- a/src/API/Grand.Api/Validators/Catalog/BrandValidator.cs
+++ b/src/API/Grand.Api/Validators/Catalog/BrandValidator.cs
@@ -14,7 +14,7 @@ namespace Grand.Api.Validators.Catalog
: base(validators)
{
RuleFor(x => x.Name).NotEmpty().WithMessage(translationService.GetResource("Api.Catalog.Brand.Fields.Name.Required"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.PictureId))
{
@@ -25,7 +25,7 @@ namespace Grand.Api.Validators.Catalog
return true;
}).WithMessage(translationService.GetResource("Api.Catalog.Brand.Fields.PictureId.NotExists"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.BrandLayoutId))
{
@@ -36,7 +36,7 @@ namespace Grand.Api.Validators.Catalog
return true;
}).WithMessage(translationService.GetResource("Api.Catalog.Brand.Fields.BrandLayoutId.NotExists"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.Id))
{
diff --git a/src/API/Grand.Api/Validators/Catalog/CategoryValidator.cs b/src/API/Grand.Api/Validators/Catalog/CategoryValidator.cs
index 6573e8aaf..985bff596 100644
--- a/src/API/Grand.Api/Validators/Catalog/CategoryValidator.cs
+++ b/src/API/Grand.Api/Validators/Catalog/CategoryValidator.cs
@@ -15,7 +15,7 @@ namespace Grand.Api.Validators.Catalog
{
RuleFor(x => x.Name).NotEmpty().WithMessage(translationService.GetResource("Api.Catalog.Category.Fields.Name.Required"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.PictureId))
{
@@ -26,7 +26,7 @@ namespace Grand.Api.Validators.Catalog
return true;
}).WithMessage(translationService.GetResource("Api.Catalog.Category.Fields.PictureId.NotExists"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.ParentCategoryId))
{
@@ -37,7 +37,7 @@ namespace Grand.Api.Validators.Catalog
return true;
}).WithMessage(translationService.GetResource("Api.Catalog.Category.Fields.ParentCategoryId.NotExists"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.CategoryLayoutId))
{
@@ -48,7 +48,7 @@ namespace Grand.Api.Validators.Catalog
return true;
}).WithMessage(translationService.GetResource("Api.Catalog.Category.Fields.CategoryLayoutId.NotExists"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.Id))
{
diff --git a/src/API/Grand.Api/Validators/Catalog/CollectionValidator.cs b/src/API/Grand.Api/Validators/Catalog/CollectionValidator.cs
index 891d1df74..1aae9211b 100644
--- a/src/API/Grand.Api/Validators/Catalog/CollectionValidator.cs
+++ b/src/API/Grand.Api/Validators/Catalog/CollectionValidator.cs
@@ -14,7 +14,7 @@ namespace Grand.Api.Validators.Catalog
: base(validators)
{
RuleFor(x => x.Name).NotEmpty().WithMessage(translationService.GetResource("Api.Catalog.Collection.Fields.Name.Required"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.PictureId))
{
@@ -25,7 +25,7 @@ namespace Grand.Api.Validators.Catalog
return true;
}).WithMessage(translationService.GetResource("Api.Catalog.Collection.Fields.PictureId.NotExists"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.CollectionLayoutId))
{
@@ -36,7 +36,7 @@ namespace Grand.Api.Validators.Catalog
return true;
}).WithMessage(translationService.GetResource("Api.Catalog.Collection.Fields.CollectionLayoutId.NotExists"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.Id))
{
diff --git a/src/API/Grand.Api/Validators/Catalog/ProductAttributeMappingValidator.cs b/src/API/Grand.Api/Validators/Catalog/ProductAttributeMappingValidator.cs
index 6f1ff1c19..4740fd37d 100644
--- a/src/API/Grand.Api/Validators/Catalog/ProductAttributeMappingValidator.cs
+++ b/src/API/Grand.Api/Validators/Catalog/ProductAttributeMappingValidator.cs
@@ -13,12 +13,10 @@ namespace Grand.Api.Validators.Catalog
ITranslationService translationService, IProductAttributeService productAttributeService)
: base(validators)
{
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
- var productattribute = await productAttributeService.GetProductAttributeById(x.ProductAttributeId);
- if (productattribute == null)
- return false;
- return true;
+ var productAttribute = await productAttributeService.GetProductAttributeById(x.ProductAttributeId);
+ return productAttribute != null;
}).WithMessage(translationService.GetResource("Api.Catalog.ProductAttributeMapping.Fields.ProductAttributeId.NotExists"));
}
}
diff --git a/src/API/Grand.Api/Validators/Catalog/ProductAttributeValidator.cs b/src/API/Grand.Api/Validators/Catalog/ProductAttributeValidator.cs
index 07d3abebd..b52587b85 100644
--- a/src/API/Grand.Api/Validators/Catalog/ProductAttributeValidator.cs
+++ b/src/API/Grand.Api/Validators/Catalog/ProductAttributeValidator.cs
@@ -13,7 +13,7 @@ namespace Grand.Api.Validators.Catalog
: base(validators)
{
RuleFor(x => x.Name).NotEmpty().WithMessage(translationService.GetResource("Api.Catalog.ProductAttribute.Fields.Name.Required"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.Id))
{
@@ -23,7 +23,7 @@ namespace Grand.Api.Validators.Catalog
}
return true;
}).WithMessage(translationService.GetResource("Api.Catalog.ProductAttribute.Fields.Id.NotExists"));
- RuleFor(x => x).Must((x, context) =>
+ RuleFor(x => x).Must((x, _) =>
{
foreach (var item in x.PredefinedProductAttributeValues)
{
diff --git a/src/API/Grand.Api/Validators/Catalog/ProductCategoryValidator.cs b/src/API/Grand.Api/Validators/Catalog/ProductCategoryValidator.cs
index ad210ac25..a4de9b37b 100644
--- a/src/API/Grand.Api/Validators/Catalog/ProductCategoryValidator.cs
+++ b/src/API/Grand.Api/Validators/Catalog/ProductCategoryValidator.cs
@@ -11,12 +11,10 @@ namespace Grand.Api.Validators.Catalog
public ProductCategoryValidator(IEnumerable<IValidatorConsumer<ProductCategoryDto>> validators, ITranslationService translationService, ICategoryService categoryService)
: base(validators)
{
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
var category = await categoryService.GetCategoryById(x.CategoryId);
- if (category == null)
- return false;
- return true;
+ return category != null;
}).WithMessage(translationService.GetResource("Api.Catalog.ProductCategory.Fields.CategoryId.NotExists"));
}
}
diff --git a/src/API/Grand.Api/Validators/Catalog/ProductCollectionValidator.cs b/src/API/Grand.Api/Validators/Catalog/ProductCollectionValidator.cs
index 24f98b005..cfc99ace7 100644
--- a/src/API/Grand.Api/Validators/Catalog/ProductCollectionValidator.cs
+++ b/src/API/Grand.Api/Validators/Catalog/ProductCollectionValidator.cs
@@ -12,12 +12,10 @@ namespace Grand.Api.Validators.Catalog
ITranslationService translationService, ICollectionService collectionService)
: base(validators)
{
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
var collection = await collectionService.GetCollectionById(x.CollectionId);
- if (collection == null)
- return false;
- return true;
+ return collection != null;
}).WithMessage(translationService.GetResource("Api.Catalog.ProductCollection.Fields.CollectionId.NotExists"));
}
}
diff --git a/src/API/Grand.Api/Validators/Catalog/ProductPictureValidator.cs b/src/API/Grand.Api/Validators/Catalog/ProductPictureValidator.cs
index 113ad6ef3..7e3fa812c 100644
--- a/src/API/Grand.Api/Validators/Catalog/ProductPictureValidator.cs
+++ b/src/API/Grand.Api/Validators/Catalog/ProductPictureValidator.cs
@@ -12,12 +12,10 @@ namespace Grand.Api.Validators.Catalog
ITranslationService translationService, IPictureService pictureService)
: base(validators)
{
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
var picture = await pictureService.GetPictureById(x.PictureId);
- if (picture == null)
- return false;
- return true;
+ return picture != null;
}).WithMessage(translationService.GetResource("Api.Catalog.ProductPicture.Fields.PictureId.NotExists"));
}
}
diff --git a/src/API/Grand.Api/Validators/Catalog/ProductSpecificationAttributeValidator.cs b/src/API/Grand.Api/Validators/Catalog/ProductSpecificationAttributeValidator.cs
index d4837b366..ab9ae8c0a 100644
--- a/src/API/Grand.Api/Validators/Catalog/ProductSpecificationAttributeValidator.cs
+++ b/src/API/Grand.Api/Validators/Catalog/ProductSpecificationAttributeValidator.cs
@@ -13,15 +13,13 @@ namespace Grand.Api.Validators.Catalog
ITranslationService translationService, ISpecificationAttributeService specificationAttributeService)
: base(validators)
{
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
var specification = await specificationAttributeService.GetSpecificationAttributeById(x.SpecificationAttributeId);
- if (specification == null)
- return false;
- return true;
+ return specification != null;
}).WithMessage(translationService.GetResource("Api.Catalog.ProductSpecificationAttribute.Fields.SpecificationAttributeId.NotExists"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.SpecificationAttributeOptionId))
{
diff --git a/src/API/Grand.Api/Validators/Catalog/ProductTierPriceValidator.cs b/src/API/Grand.Api/Validators/Catalog/ProductTierPriceValidator.cs
index cd1f6f4d9..da3a383b8 100644
--- a/src/API/Grand.Api/Validators/Catalog/ProductTierPriceValidator.cs
+++ b/src/API/Grand.Api/Validators/Catalog/ProductTierPriceValidator.cs
@@ -17,7 +17,7 @@ namespace Grand.Api.Validators.Catalog
RuleFor(x => x.Quantity).GreaterThan(0).WithMessage(translationService.GetResource("Api.Catalog.ProductTierPrice.Fields.Quantity.GreaterThan0"));
RuleFor(x => x.Price).GreaterThan(0).WithMessage(translationService.GetResource("Api.Catalog.ProductTierPrice.Fields.Price.GreaterThan0"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.StoreId))
{
@@ -27,7 +27,7 @@ namespace Grand.Api.Validators.Catalog
}
return true;
}).WithMessage(translationService.GetResource("Api.Catalog.ProductTierPrice.Fields.StoreId.NotExists"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.CustomerGroupId))
{
diff --git a/src/API/Grand.Api/Validators/Catalog/ProductValidator.cs b/src/API/Grand.Api/Validators/Catalog/ProductValidator.cs
index 833a8d171..5f3e3c9dc 100644
--- a/src/API/Grand.Api/Validators/Catalog/ProductValidator.cs
+++ b/src/API/Grand.Api/Validators/Catalog/ProductValidator.cs
@@ -34,7 +34,7 @@ namespace Grand.Api.Validators.Catalog
RuleFor(x => x.ProductTypeId == ProductType.Auction && !x.AvailableEndDateTimeUtc.HasValue).Equal(false).WithMessage(translationService.GetResource("Api.Catalog.Products.Fields.AvailableEndDateTime.Required"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.ParentGroupedProductId))
{
@@ -45,7 +45,7 @@ namespace Grand.Api.Validators.Catalog
return true;
}).WithMessage(translationService.GetResource("Api.Catalog.Product.Fields.ParentGroupedProductId.NotExists"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.ProductLayoutId))
{
@@ -56,7 +56,7 @@ namespace Grand.Api.Validators.Catalog
return true;
}).WithMessage(translationService.GetResource("Api.Catalog.Product.Fields.ProductLayoutId.NotExists"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.VendorId))
{
@@ -67,7 +67,7 @@ namespace Grand.Api.Validators.Catalog
return true;
}).WithMessage(translationService.GetResource("Api.Catalog.Product.Fields.VendorId.NotExists"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.BrandId))
{
@@ -78,7 +78,7 @@ namespace Grand.Api.Validators.Catalog
return true;
}).WithMessage(translationService.GetResource("Api.Catalog.Product.Fields.BrandId.NotExists"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.Id))
{
diff --git a/src/API/Grand.Api/Validators/Catalog/SpecificationAttributeValidator.cs b/src/API/Grand.Api/Validators/Catalog/SpecificationAttributeValidator.cs
index 67f3026cf..8d5720808 100644
--- a/src/API/Grand.Api/Validators/Catalog/SpecificationAttributeValidator.cs
+++ b/src/API/Grand.Api/Validators/Catalog/SpecificationAttributeValidator.cs
@@ -14,7 +14,7 @@ namespace Grand.Api.Validators.Catalog
: base(validators)
{
RuleFor(x => x.Name).NotEmpty().WithMessage(translationService.GetResource("Api.Catalog.SpecificationAttribute.Fields.Name.Required"));
- RuleFor(x => x).MustAsync(async (x, y, context) =>
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (!string.IsNullOrEmpty(x.Id))
{
@@ -24,7 +24,7 @@ namespace Grand.Api.Validators.Catalog
}
return true;
}).WithMessage(translationService.GetResource("Api.Catalog.SpecificationAttribute.Fields.Id.NotExists"));
- RuleFor(x => x).Must((x, context) =>
+ RuleFor(x => x).Must((x, _) =>
{
foreach (var item in x.SpecificationAttributeOptions)
{
diff --git a/src/API/Grand.Api/Validators/Common/LoginValidator.cs b/src/API/Grand.Api/Validators/Common/LoginValidator.cs
index bb146e2c1..f64588ca6 100644
--- a/src/API/Grand.Api/Validators/Common/LoginValidator.cs
+++ b/src/API/Grand.Api/Validators/Common/LoginValidator.cs
@@ -16,31 +16,31 @@ namespace Grand.Api.Validators.Common
: base(validators)
{
if (!apiConfig.Enabled)
- RuleFor(x => x).Must((x) => false).WithMessage("API is disabled");
+ RuleFor(x => x).Must(_ => false).WithMessage("API is disabled");
RuleFor(x => x.Email).NotEmpty().WithMessage("Email is required");
RuleFor(x => x.Password).NotEmpty().WithMessage("Password is required");
- RuleFor(x => x).MustAsync(async (x, context) =>
+ RuleFor(x => x).MustAsync(async (x, _) =>
{
if (!string.IsNullOrEmpty(x.Email))
{
var userapi = await userApiService.GetUserByEmail(x.Email.ToLowerInvariant());
- if (userapi != null && userapi.IsActive)
+ if (userapi is { IsActive: true })
{
- var base64EncodedBytes = System.Convert.FromBase64String(x.Password);
- var password = System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
+ var base64EncodedBytes = Convert.FromBase64String(x.Password);
+ var password = Encoding.UTF8.GetString(base64EncodedBytes);
if (userapi.Password == encryptionService.EncryptText(password, userapi.PrivateKey))
return true;
}
}
return false;
}).WithMessage(("User not exists or password is wrong"));
- RuleFor(x => x).MustAsync(async (x, context) =>
+ RuleFor(x => x).MustAsync(async (x, _) =>
{
if (!string.IsNullOrEmpty(x.Email))
{
var customer = await customerService.GetCustomerByEmail(x.Email.ToLowerInvariant());
- if (customer != null && customer.Active && !customer.IsSystemAccount())
+ if (customer is { Active: true } && !customer.IsSystemAccount())
return true;
}
return false;
diff --git a/src/API/Grand.Api/Validators/Common/LoginWebValidator.cs b/src/API/Grand.Api/Validators/Common/LoginWebValidator.cs
index 0b99bcaf2..c96e4b45c 100644
--- a/src/API/Grand.Api/Validators/Common/LoginWebValidator.cs
+++ b/src/API/Grand.Api/Validators/Common/LoginWebValidator.cs
@@ -17,25 +17,22 @@ namespace Grand.Api.Validators.Common
: base(validators)
{
if (!apiConfig.Enabled)
- RuleFor(x => x).Must((x) => false).WithMessage("API is disabled");
+ RuleFor(x => x).Must(_ => false).WithMessage("API is disabled");
else
{
RuleFor(x => x.Email).NotEmpty().WithMessage("Email is required");
RuleFor(x => x.Password).NotEmpty().WithMessage("Password is required");
- RuleFor(x => x).MustAsync(async (x, context) =>
+ RuleFor(x => x).MustAsync(async (x, _) =>
{
if (!string.IsNullOrEmpty(x.Email))
{
var customer = await customerService.GetCustomerByEmail(x.Email.ToLowerInvariant());
- if (customer != null && customer.Active && !customer.IsSystemAccount())
+ if (customer is { Active: true } && !customer.IsSystemAccount())
{
- var base64EncodedBytes = System.Convert.FromBase64String(x.Password);
- var password = System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
+ var base64EncodedBytes = Convert.FromBase64String(x.Password);
+ var password = Encoding.UTF8.GetString(base64EncodedBytes);
var result = await customerManagerService.LoginCustomer(x.Email, password);
- if (result == CustomerLoginResults.Successful)
- return true;
-
- return false;
+ return result == CustomerLoginResults.Successful;
}
}
return false;
diff --git a/src/API/Grand.Api/Validators/Common/PictureValidator.cs b/src/API/Grand.Api/Validators/Common/PictureValidator.cs
index bbc103c57..8660ac366 100644
--- a/src/API/Grand.Api/Validators/Common/PictureValidator.cs
+++ b/src/API/Grand.Api/Validators/Common/PictureValidator.cs
@@ -13,17 +13,13 @@ namespace Grand.Api.Validators.Common
: base(validators)
{
RuleFor(x => x.MimeType).NotEmpty().WithMessage(translationService.GetResource("Api.Common.Picture.Fields.MimeType.Required"));
- RuleFor(x => x.PictureBinary).Must((x, context) =>
+ RuleFor(x => x.PictureBinary).Must((x, _) =>
{
if (!string.IsNullOrEmpty(x.Id) && (x.PictureBinary==null || x.PictureBinary.Length == 0))
{
return true;
}
- if (string.IsNullOrEmpty(x.Id) && (x.PictureBinary == null || x.PictureBinary.Length == 0))
- {
- return false;
- }
- return true;
+ return !string.IsNullOrEmpty(x.Id) || (x.PictureBinary != null && x.PictureBinary.Length != 0);
}).WithMessage(translationService.GetResource("Api.Common.Picture.Fields.PictureBinary.Required"));
}
}
diff --git a/src/API/Grand.Api/Validators/Customers/AddressValidator.cs b/src/API/Grand.Api/Validators/Customers/AddressValidator.cs
index a39fdf1d3..45e84d95f 100644
--- a/src/API/Grand.Api/Validators/Customers/AddressValidator.cs
+++ b/src/API/Grand.Api/Validators/Customers/AddressValidator.cs
@@ -37,7 +37,7 @@ namespace Grand.Api.Validators.Customers
}
if (addressSettings.CountryEnabled && addressSettings.StateProvinceEnabled)
{
- RuleFor(x => x.StateProvinceId).MustAsync(async (x, y, context) =>
+ RuleFor(x => x.StateProvinceId).MustAsync(async (x, y, _) =>
{
var countryId = !string.IsNullOrEmpty(x.CountryId) ? x.CountryId : "";
var country = await countryService.GetCountryById(countryId);
@@ -48,7 +48,7 @@ namespace Grand.Api.Validators.Customers
{
return false;
}
- if (country.StateProvinces.FirstOrDefault(x => x.Id == y) != null)
+ if (country.StateProvinces.FirstOrDefault(stateProvince => stateProvince.Id == y) != null)
return true;
}
return false;
diff --git a/src/API/Grand.Api/Validators/Customers/CustomerGroupValidator.cs b/src/API/Grand.Api/Validators/Customers/CustomerGroupValidator.cs
index af1549fae..1b93979ad 100644
--- a/src/API/Grand.Api/Validators/Customers/CustomerGroupValidator.cs
+++ b/src/API/Grand.Api/Validators/Customers/CustomerGroupValidator.cs
@@ -15,7 +15,7 @@ namespace Grand.Api.Validators.Customers
{
RuleFor(x => x.Name).NotEmpty().WithMessage(translationService.GetResource("Api.Customers.CustomerGroup.Fields.Name.Required"));
- RuleFor(x => x).MustAsync(async (x, context) =>
+ RuleFor(x => x).MustAsync(async (x, _) =>
{
if (!string.IsNullOrEmpty(x.Id))
{
@@ -25,7 +25,7 @@ namespace Grand.Api.Validators.Customers
}
return true;
}).WithMessage(translationService.GetResource("Api.Customers.CustomerGroup.Fields.Id.NotExists"));
- RuleFor(x => x).MustAsync(async (x, context) =>
+ RuleFor(x => x).MustAsync(async (x, _) =>
{
if (!string.IsNullOrEmpty(x.Id))
{
@@ -37,7 +37,7 @@ namespace Grand.Api.Validators.Customers
}
return true;
}).WithMessage(translationService.GetResource("Api.Customers.CustomerGroup.Fields.Active.CantEditSystem"));
- RuleFor(x => x).MustAsync(async (x, context) =>
+ RuleFor(x => x).MustAsync(async (x, _) =>
{
if (!string.IsNullOrEmpty(x.Id))
{
diff --git a/src/API/Grand.Api/Validators/Customers/CustomerValidator.cs b/src/API/Grand.Api/Validators/Customers/CustomerValidator.cs
index 345395909..ce94ec02d 100644
--- a/src/API/Grand.Api/Validators/Customers/CustomerValidator.cs
+++ b/src/API/Grand.Api/Validators/Customers/CustomerValidator.cs
@@ -18,44 +18,28 @@ namespace Grand.Api.Validators.Customers
: base(validators)
{
- RuleFor(x => x).MustAsync(async (x, context) =>
+ RuleFor(x => x).MustAsync(async (x, _) =>
{
var customer = await customerService.GetCustomerByEmail(x.Email);
- if (customer != null && customer.Id != x.Id)
- {
- return false;
- }
- return true;
+ return customer == null || customer.Id == x.Id;
}).WithMessage(translationService.GetResource("Api.Customers.Customer.Fields.Email.Registered"));
- RuleFor(x => x).MustAsync(async (x, context) =>
+ RuleFor(x => x).MustAsync(async (x, _) =>
{
var username = await customerService.GetCustomerByUsername(x.Username);
- if (username != null && username.Id != x.Id && customerSettings.UsernamesEnabled)
- {
- return false;
- }
- return true;
+ return username == null || username.Id == x.Id || !customerSettings.UsernamesEnabled;
}).WithMessage(translationService.GetResource("Api.Customers.Customer.Fields.Username.Registered"));
- RuleFor(x => x).MustAsync(async (x, context) =>
+ RuleFor(x => x).MustAsync(async (x, _) =>
{
var customer = await customerService.GetCustomerByGuid(x.CustomerGuid);
- if (customer != null && customer.Id != x.Id)
- {
- return false;
- }
- return true;
+ return customer == null || customer.Id == x.Id;
}).WithMessage(translationService.GetResource("Api.Customers.Customer.Fields.Guid.Exists"));
- RuleFor(x => x).MustAsync(async (x, context) =>
+ RuleFor(x => x).MustAsync(async (x, _) =>
{
var store = await storeService.GetStoreById(x.StoreId);
- if (store != null)
- {
- return true;
- }
- return false;
+ return store != null;
}).WithMessage(translationService.GetResource("Api.Customers.Customer.Fields.StoreId.NotExists"));
@@ -71,7 +55,7 @@ namespace Grand.Api.Validators.Customers
customerSettings.StateProvinceRequired)
{
- RuleFor(x => x.StateProvinceId).MustAsync(async (x, y, context) =>
+ RuleFor(x => x.StateProvinceId).MustAsync(async (x, y, _) =>
{
var countryId = !string.IsNullOrEmpty(x.CountryId) ? x.CountryId : "";
var country = await countryService.GetCountryById(countryId);
@@ -82,7 +66,7 @@ namespace Grand.Api.Validators.Customers
{
return false;
}
- if (country.StateProvinces.FirstOrDefault(x => x.Id == y) != null)
+ if (country.StateProvinces.FirstOrDefault(stateProvince => stateProvince.Id == y) != null)
return true;
}
return false;