Skip to content

Commit 48640c3

Browse files
Improvements/code (#585)
* Make a static methods * Refactor file reading to use async methods * Refactor error handling in ApplicationBuilderExtensions * Refactor SettingController.cs for improved readability * Remove argument from the method call; it hides the caller information. * Remove null-conditional operator from orderBuilder * Simplify URL generation in _AdminLayout.cshtml * Simplify log message in HomeController * Fix potential null reference in currency dropdown * Remove this unnecessary check for null.
1 parent 75d75a6 commit 48640c3

File tree

68 files changed

+239
-246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+239
-246
lines changed

src/Business/Grand.Business.Authentication/Services/TwoFactorAuthenticationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.TwoFac
8787
return model;
8888
}
8989

90-
private string PrepareRandomCode()
90+
private static string PrepareRandomCode()
9191
{
9292
var generator = new Random();
9393
return generator.Next(0, 999999).ToString("D6");

src/Business/Grand.Business.Catalog/Services/ExportImport/BrandImportDataObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private async Task UpdateBrandData(BrandDto brandDto, Brand brand)
8181
await _slugService.SaveSlug(brand, seName, "");
8282
}
8383

84-
private bool ValidBrand(Brand brand)
84+
private static bool ValidBrand(Brand brand)
8585
{
8686
return !string.IsNullOrEmpty(brand.Name);
8787
}

src/Business/Grand.Business.Catalog/Services/ExportImport/CategoryImportDataObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private async Task UpdateCategoryData(CategoryDto categoryDto, Category category
8686
await _slugService.SaveSlug(category, seName, "");
8787
}
8888

89-
private bool ValidCategory(Category category)
89+
private static bool ValidCategory(Category category)
9090
{
9191
return !string.IsNullOrEmpty(category.Name);
9292
}

src/Business/Grand.Business.Catalog/Services/ExportImport/CollectionImportDataObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private async Task UpdateCollectionData(CollectionDto collectionDto, Collection
8383
await _slugService.SaveSlug(collection, sename, "");
8484
}
8585

86-
private bool ValidCollection(Collection collection)
86+
private static bool ValidCollection(Collection collection)
8787
{
8888
return !string.IsNullOrEmpty(collection.Name);
8989
}

src/Business/Grand.Business.Catalog/Services/ExportImport/ProductImportDataObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ private async Task PrepareProductPictures(ProductDto productDto, Product product
265265
}
266266
}
267267

268-
private bool ValidProduct(Product product)
268+
private static bool ValidProduct(Product product)
269269
{
270270
return !string.IsNullOrEmpty(product.Name);
271271
}

src/Business/Grand.Business.Catalog/Services/Products/ProductAttributeService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ public virtual async Task InsertProductAttributeValue(ProductAttributeValue prod
258258
ArgumentNullException.ThrowIfNull(productAttributeValue);
259259

260260
var p = await _productRepository.GetByIdAsync(productId);
261-
ArgumentNullException.ThrowIfNull(p, nameof(p));
261+
ArgumentNullException.ThrowIfNull(p);
262262

263263
var pam = p.ProductAttributeMappings.FirstOrDefault(x => x.Id == productAttributeMappingId);
264-
ArgumentNullException.ThrowIfNull(pam, nameof(pam));
264+
ArgumentNullException.ThrowIfNull(pam);
265265

266266
pam.ProductAttributeValues.Add(productAttributeValue);
267267
await _productRepository.UpdateToSet(productId, x => x.ProductAttributeMappings, z => z.Id,

src/Business/Grand.Business.Catalog/Startup/StartupApplication.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void Configure(WebApplication application, IWebHostEnvironment webHostEnv
4444
public int Priority => 100;
4545
public bool BeforeConfigure => false;
4646

47-
private void RegisterCatalogService(IServiceCollection serviceCollection)
47+
private static void RegisterCatalogService(IServiceCollection serviceCollection)
4848
{
4949
serviceCollection.AddScoped<IOutOfStockSubscriptionService, OutOfStockSubscriptionService>();
5050
serviceCollection.AddScoped<ICategoryService, CategoryService>();
@@ -77,21 +77,21 @@ private void RegisterCatalogService(IServiceCollection serviceCollection)
7777
serviceCollection.AddScoped<IMeasureService, MeasureService>();
7878
}
7979

80-
private void RegisterDiscountsService(IServiceCollection serviceCollection)
80+
private static void RegisterDiscountsService(IServiceCollection serviceCollection)
8181
{
8282
serviceCollection.AddScoped<IDiscountService, DiscountService>();
8383
serviceCollection.AddScoped<IDiscountValidationService, DiscountValidationService>();
8484
serviceCollection.AddScoped<IDiscountProviderLoader, DiscountProviderLoader>();
8585
}
8686

87-
private void RegisterTaxService(IServiceCollection serviceCollection)
87+
private static void RegisterTaxService(IServiceCollection serviceCollection)
8888
{
8989
serviceCollection.AddScoped<ITaxService, TaxService>();
9090
serviceCollection.AddScoped<IVatService, VatService>();
9191
serviceCollection.AddScoped<ITaxCategoryService, TaxCategoryService>();
9292
}
9393

94-
private void RegisterExportImport(IServiceCollection serviceCollection)
94+
private static void RegisterExportImport(IServiceCollection serviceCollection)
9595
{
9696
serviceCollection.AddScoped<ISchemaProperty<Brand>, BrandSchemaProperty>();
9797
serviceCollection.AddScoped<ISchemaProperty<Category>, CategorySchemaProperty>();

src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PrepareOrderCodeCommandHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public async Task<string> Handle(PrepareOrderCodeCommand request, CancellationTo
2424
return await Task.FromResult(code);
2525
}
2626

27-
private string RandomString(int length)
27+
private static string RandomString(int length)
2828
{
2929
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
3030
return new string(Enumerable.Repeat(chars, length)

src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/ValidateMinShoppingCartSubtotalAmountCommandHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ protected virtual async Task<bool> ValidateMinOrderSubtotalAmount(IList<Shopping
3838
return false;
3939

4040
//min order amount sub-total validation
41-
if (!cart.Any() || !(_orderSettings.MinOrderSubtotalAmount > 0)) return true;
41+
if (!(_orderSettings.MinOrderSubtotalAmount > 0)) return true;
42+
4243
//subtotal
4344
var (_, _, subTotalWithoutDiscount, _, _) =
4445
await _orderTotalCalculationService.GetShoppingCartSubTotal(cart, false);

src/Business/Grand.Business.Checkout/Services/Orders/OrderReportService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,8 @@ public virtual async Task<ReportPeriodOrder> GetOrderPeriodReport(int days, stri
489489
group o by 1
490490
into g
491491
select new ReportPeriodOrder { Amount = g.Sum(x => x.OrderTotal / x.CurrencyRate), Count = g.Count() };
492-
var report = query.ToList()?.FirstOrDefault() ?? new ReportPeriodOrder();
492+
493+
var report = query.FirstOrDefault() ?? new ReportPeriodOrder();
493494
report.Date = date;
494495
return await Task.FromResult(report);
495496
}

0 commit comments

Comments
 (0)