Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code refactoring (No functional changes) #7513

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static async Task<StringValues> GetFormValueAsync(this HttpRequest reques

return form[formKey];
}

/// <summary>
/// Checks if the provided key is exists on the form
/// </summary>
Expand Down Expand Up @@ -78,7 +78,7 @@ public static async Task<bool> IsFormAnyAsync(this HttpRequest request, Func<str

var form = await request.ReadFormAsync();

return predicate == null ? form.Any() : form.Keys.Any(predicate);
return predicate == null ? form.Any() : form.Keys.Any(predicate);
}

/// <summary>
Expand Down
5 changes: 2 additions & 3 deletions src/Libraries/Nop.Core/Infrastructure/NopEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Nop.Core.Configuration;
using Nop.Core.Infrastructure.Mapper;

namespace Nop.Core.Infrastructure;
Expand Down Expand Up @@ -71,7 +70,7 @@ protected virtual void AddAutoMapper()
//create AutoMapper configuration
var config = new MapperConfiguration(cfg =>
{
foreach (var instance in instances)
foreach (var instance in instances)
cfg.AddProfile(instance.GetType());
});

Expand Down Expand Up @@ -141,7 +140,7 @@ public virtual void ConfigureServices(IServiceCollection services, IConfiguratio
public virtual void ConfigureRequestPipeline(IApplicationBuilder application)
{
ServiceProvider = application.ApplicationServices;

//find startup configurations provided by other assemblies
var typeFinder = Singleton<ITypeFinder>.Instance;
var startupConfigurations = typeFinder.FindClassesOfType<INopStartup>();
Expand Down
8 changes: 4 additions & 4 deletions src/Libraries/Nop.Core/Infrastructure/WebAppTypeFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public partial class WebAppTypeFinder : ITypeFinder
#region Fields

protected static readonly Dictionary<string, Assembly> _assemblies = new(StringComparer.InvariantCultureIgnoreCase);

protected static bool _loaded;
protected static readonly object _locker = new();

Expand Down Expand Up @@ -145,7 +145,7 @@ protected virtual IEnumerable<Type> FindClassesOfType(Type assignTypeFrom, IEnum
{
var msg = string.Empty;

if (ex.LoaderExceptions.Any())
if (ex.LoaderExceptions.Any())
msg = ex.LoaderExceptions.Where(e => e != null)
.Aggregate(msg, (current, e) => $"{current}{e.Message + Environment.NewLine}");

Expand Down Expand Up @@ -233,7 +233,7 @@ public virtual IList<Assembly> GetAssemblies()
{
if (!_loaded)
InitData();

return _assemblies.Values.ToList();
}

Expand Down Expand Up @@ -290,7 +290,7 @@ public virtual Assembly GetAssemblyByName(string assemblyFullName)
/// <remarks>
/// For example, the web application's bin folder should be specifically checked for being loaded on the application load. This is needed in situations where plugins need to be loaded in the AppDomain after the application has been reloaded
/// </remarks>
public virtual List<string> DirectoriesToLoadAssemblies { get; set; } = new ()
public virtual List<string> DirectoriesToLoadAssemblies { get; set; } = new()
{
AppContext.BaseDirectory
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ public override void Up()
.OnColumn(nameof(ProductReview.CustomerId)).Ascending()
.WithOptions().NonClustered();

if(!Schema.Table(nameof(Product)).Index("IX_Product_Name").Exists())
if (!Schema.Table(nameof(Product)).Index("IX_Product_Name").Exists())
Create.Index("IX_Product_Name")
.OnTable(nameof(Product))
.OnColumn(nameof(Product.Name)).Ascending()
.OnColumn(nameof(Product.Name)).Ascending()
.WithOptions().NonClustered();

if (!Schema.Table(NameCompatibilityManager.GetTableName(typeof(ForumTopic))).Index("IX_Forums_Topic_Subject").Exists())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ join p in _dataProvider.GetTable<Picture>() on c.PictureId equals p.Id
if (Schema.Table(newsLetterSubscriptionTableName).Column(languageIdColumnName).Exists())
{
var defaultLanguageId = _dataProvider.GetTable<Language>().FirstOrDefault()?.Id ?? 0;

_dataProvider.GetTable<NewsLetterSubscription>()
.Set(p=>p.LanguageId, defaultLanguageId)
.Set(p => p.LanguageId, defaultLanguageId)
.Update();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Libraries/Nop.Services/ExportImport/ExportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ protected virtual async Task<int> ExportSpecificationAttributesAsync(Product ite
protected virtual async Task<int> ExportTierPricesAsync(Product item, PropertyManager<ExportTierPrice, Language> tierPriceManager,
IXLWorksheet worksheet, IList<(Language Language, IXLWorksheet Worksheet)> localizedWorksheets, int row, IXLWorksheet faWorksheet)
{
var tierPrices = (await _productService.GetTierPricesByProductAsync(item.Id)).Select(p=>new ExportTierPrice
var tierPrices = (await _productService.GetTierPricesByProductAsync(item.Id)).Select(p => new ExportTierPrice
{
Id = p.Id,
CustomerRoleId = p.CustomerRoleId,
Expand Down Expand Up @@ -1741,7 +1741,7 @@ public virtual async Task<byte[]> ExportProductsToXlsxAsync(IEnumerable<Product>
};

var productList = products.ToList();

if (!_catalogSettings.ExportImportProductAttributes && !_catalogSettings.ExportImportProductSpecificationAttributes)
return await new PropertyManager<Product, Language>(properties, _catalogSettings).ExportToXlsxAsync(productList);

Expand Down
21 changes: 11 additions & 10 deletions src/Libraries/Nop.Services/ExportImport/ImportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ protected virtual ExportedAdditionalProductInfoType GetTypeOfExportedAdditionalP

tierPriceManager.ReadDefaultFromXlsx(defaultWorksheet, iRow, ExportImportDefaults.ProductAdditionalInfoCellOffset);

if (tierPriceManager.IsCaption)
if (tierPriceManager.IsCaption)
return ExportedAdditionalProductInfoType.TierPrices;

return ExportedAdditionalProductInfoType.NotSpecified;
Expand Down Expand Up @@ -1038,7 +1038,7 @@ protected virtual async Task ImportSpecificationAttributeAsync(ImportProductMeta
protected virtual async Task ImportTierPriceAsync(ImportProductMetadata metadata, Product lastLoadedProduct, IList<Language> languages, int iRow)
{
var tierPriceManager = metadata.TierPriceManager;

if (!_catalogSettings.ExportImportTierPrices || lastLoadedProduct == null || tierPriceManager.IsCaption)
return;

Expand Down Expand Up @@ -1316,14 +1316,14 @@ protected virtual async Task<ImportProductMetadata> PrepareImportProductDataAsyn
case ExportedAdditionalProductInfoType.ProductAttribute:
productAttributeManager.ReadDefaultFromXlsx(defaultWorksheet, endRow,
ExportImportDefaults.ProductAdditionalInfoCellOffset);
if (int.TryParse(defaultWorksheet.Row(endRow).Cell(attributeIdCellNum).Value.ToString(), out var aid))
if (int.TryParse(defaultWorksheet.Row(endRow).Cell(attributeIdCellNum).Value.ToString(), out var aid))
allAttributeIds.Add(aid);

break;
case ExportedAdditionalProductInfoType.SpecificationAttribute:
specificationAttributeManager.ReadDefaultFromXlsx(defaultWorksheet, endRow, ExportImportDefaults.ProductAdditionalInfoCellOffset);

if (int.TryParse(defaultWorksheet.Row(endRow).Cell(specificationAttributeOptionIdCellNum).Value.ToString(), out var saoid))
if (int.TryParse(defaultWorksheet.Row(endRow).Cell(specificationAttributeOptionIdCellNum).Value.ToString(), out var saoid))
allSpecificationAttributeOptionIds.Add(saoid);

break;
Expand Down Expand Up @@ -1405,7 +1405,7 @@ protected virtual async Task<ImportProductMetadata> PrepareImportProductDataAsyn

//performance optimization, the check for the existence of the stores in one SQL request
var notExistingStores = await _storeService.GetNotExistingStoresAsync(allStores.ToArray());
if (notExistingStores.Any())
if (notExistingStores.Any())
throw new ArgumentException(string.Format(await _localizationService.GetResourceAsync("Admin.Catalog.Products.Import.StoresDontExist"), string.Join(", ", notExistingStores)));

return new ImportProductMetadata
Expand Down Expand Up @@ -1991,7 +1991,7 @@ await _customerService.AddCustomerRoleMappingAsync(
}

if (!isNew && rolesToSave.Any())
foreach (var customerRole in customerRoles.Where(cr=>!rolesToSave.Contains(cr.Id)).ToList())
foreach (var customerRole in customerRoles.Where(cr => !rolesToSave.Contains(cr.Id)).ToList())
await _customerService.RemoveCustomerRoleMappingAsync(customer, customerRole);

if (avatarPictureId.HasValue)
Expand All @@ -2006,7 +2006,7 @@ await _genericAttributeService.SaveAttributeAsync(customer, NopCustomerDefaults.
!string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(passwordSalt))
{
var lastPassword = isNew ? null : await _customerService.GetCurrentPasswordAsync(customer.Id);

if (lastPassword == null || !(lastPassword.Password.Equals(password) && lastPassword.PasswordSalt.Equals(passwordSalt)))
await _customerService.InsertCustomerPasswordAsync(new CustomerPassword
{
Expand Down Expand Up @@ -2071,7 +2071,8 @@ public virtual async Task ImportProductsFromXlsxAsync(Stream stream)

allCategories = await allCategoryList
.WhereAwait(async c => await _categoryService.CanVendorAddProductsAsync(c, allCategoryList))
.ToDictionaryAwaitAsync(async c => {
.ToDictionaryAwaitAsync(async c =>
{
var keyName = await _categoryService.GetFormattedBreadCrumbAsync(c, allCategoryList);
return new CategoryKey(keyName, c, c.LimitedToStores ? (await _storeMappingService.GetStoresIdsWithAccessAsync(c)).ToList() : new List<int>());
});
Expand Down Expand Up @@ -3110,7 +3111,7 @@ public virtual async Task ImportOrdersFromXlsxAsync(Stream stream)
metadata.OrderItemManager.ReadDefaultFromXlsx(worksheet, iRow, 2);

//skip caption row
if (!metadata.OrderItemManager.IsCaption)
if (!metadata.OrderItemManager.IsCaption)
await ImportOrderItemAsync(metadata.OrderItemManager, lastLoadedOrder);

continue;
Expand Down Expand Up @@ -3268,7 +3269,7 @@ public virtual async Task ImportOrdersFromXlsxAsync(Stream stream)
break;
case "BillingStateProvinceAbbreviation":
billingStateProvinceAbbreviation = property.StringValue;

break;
case "BillingZipPostalCode":
orderBillingAddress.ZipPostalCode = property.StringValue;
Expand Down
10 changes: 5 additions & 5 deletions src/Libraries/Nop.Services/Installation/InstallRequiredData.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
using System.Globalization;
using Microsoft.Extensions.DependencyInjection;
using Nop.Core;
using Nop.Core.Domain;
using Nop.Core.Domain.Blogs;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain;
using Nop.Core;
using Nop.Core.Domain.Common;
using Nop.Core.Domain.Customers;
using Nop.Core.Domain.Directory;
using Nop.Core.Domain.Forums;
using Nop.Core.Domain.Gdpr;
using Nop.Core.Domain.Localization;
using Nop.Core.Domain.Logging;
using Nop.Core.Domain.Media;
using Nop.Core.Domain.Messages;
using Nop.Core.Domain.News;
using Nop.Core.Domain.Orders;
using Nop.Core.Domain.Payments;
using Nop.Core.Domain.ScheduleTasks;
using Nop.Core.Domain.Security;
using Nop.Core.Domain.Seo;
using Nop.Core.Domain.Shipping;
Expand All @@ -33,8 +35,6 @@
using Nop.Services.Helpers;
using Nop.Services.Localization;
using Nop.Services.Seo;
using Nop.Core.Domain.Logging;
using Nop.Core.Domain.ScheduleTasks;

namespace Nop.Services.Installation;

Expand Down Expand Up @@ -246,7 +246,7 @@ await _dataProvider.InsertEntityAsync(new GenericAttribute
// ignored
}
}

/// <summary>
/// Installs a default currencies
/// </summary>
Expand Down
20 changes: 10 additions & 10 deletions src/Libraries/Nop.Services/Installation/InstallSampleData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected virtual async Task<int> GetDefaultCustomerIdAsync()
/// <param name="getName">Function to getting the name fore creating the slug</param>
/// <param name="languageId">The language identifier</param>
/// <returns>A task that represents the asynchronous operation</returns>
protected async Task InsertSearchEngineNamesAsync<TEntity>(IEnumerable<TEntity> entities, Func<TEntity, string> getName, int languageId=0) where TEntity : BaseEntity
protected async Task InsertSearchEngineNamesAsync<TEntity>(IEnumerable<TEntity> entities, Func<TEntity, string> getName, int languageId = 0) where TEntity : BaseEntity
{
await _dataProvider.BulkInsertEntitiesAsync(await entities.SelectAwait(async entity => new UrlRecord
{
Expand Down Expand Up @@ -480,7 +480,7 @@ await _dataProvider.BulkInsertEntitiesAsync(new[]
new ProductAttribute { Name = "Software" }
});
}

/// <summary>
/// Installs a sample categories
/// </summary>
Expand Down Expand Up @@ -723,7 +723,7 @@ protected virtual async Task InstallBlogPostsAsync()

await _dataProvider.BulkInsertEntitiesAsync(blogPosts);
await InsertSearchEngineNamesAsync(blogPosts, blogPost => blogPost.Title, await GetDefaultLanguageIdAsync());

await _dataProvider.BulkInsertEntitiesAsync(await blogPosts.SelectAwait(async blogPost => new BlogComment
{
BlogPostId = blogPost.Id,
Expand Down Expand Up @@ -805,7 +805,7 @@ protected virtual async Task InstallPollsAsync()
ShowOnHomepage = true,
DisplayOrder = 1
});

await _dataProvider.BulkInsertEntitiesAsync(new[]
{
new PollAnswer { Name = "Excellent", DisplayOrder = 1, PollId = poll.Id },
Expand Down Expand Up @@ -842,7 +842,7 @@ protected virtual async Task InstallWarehousesAsync()
};

await _dataProvider.BulkInsertEntitiesAsync(new[] { address1, address2 });

await _dataProvider.BulkInsertEntitiesAsync(new[]
{
new Warehouse { Name = "Warehouse 1 (New York)", AddressId = address1.Id },
Expand Down Expand Up @@ -914,7 +914,7 @@ protected virtual async Task InstallAffiliatesAsync()
CountryId = await GetFirstEntityIdAsync<Country>(c => c.ThreeLetterIsoCode == "USA"),
CreatedOnUtc = DateTime.UtcNow
});

await _dataProvider.InsertEntityAsync(new Affiliate
{
Active = true,
Expand Down Expand Up @@ -989,7 +989,7 @@ await _dataProvider.BulkInsertEntitiesAsync(new[]
#endregion

#region Orders

var firstOrder = new Order
{
StoreId = defaultStoreId,
Expand Down Expand Up @@ -1044,7 +1044,7 @@ await _dataProvider.BulkInsertEntitiesAsync(new[]
CreatedOnUtc = DateTime.UtcNow,
CustomOrderNumber = string.Empty
};

var secondOrder = new Order
{
StoreId = defaultStoreId,
Expand Down Expand Up @@ -1269,7 +1269,7 @@ await _dataProvider.BulkInsertEntitiesAsync(new[]

await _dataProvider.BulkInsertEntitiesAsync(allOrders);

foreach (var order in allOrders)
foreach (var order in allOrders)
order.CustomOrderNumber = order.Id.ToString();

await _dataProvider.UpdateEntitiesAsync(allOrders);
Expand Down Expand Up @@ -1573,7 +1573,7 @@ await _dataProvider.BulkInsertEntitiesAsync(new[]
});

#endregion

#region Shipments

var fourthOrderShipment1 = new Shipment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using Nop.Web.Framework.Mvc.Filters;
using Nop.Services.Security;
using Nop.Web.Framework;
using Nop.Web.Framework.Controllers;
using Nop.Services.Security;
using Nop.Web.Framework.Mvc.Filters;

namespace Nop.Plugin.Misc.NopMobileApp.Controllers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Microsoft.AspNetCore.Routing;
using Nop.Core;
using Nop.Core;
using Nop.Services.Common;
using Nop.Services.Plugins;
using Nop.Services.Security;
using Nop.Web.Framework;
using Nop.Web.Framework.Menu;

namespace Nop.Plugin.Misc.OmnibusDirective;

Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/Nop.Plugin.Misc.Omnisend/DTO/DtoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class DtoExtensions
{
public static string ToDtoString(this DateTime date)
{
return date.ToString("s")+"Z";
return date.ToString("s") + "Z";
}

public static int ToCents(this decimal price)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Nop.Core.Infrastructure;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Nop.Web.Framework.Mvc.Routing;
using Nop.Web.Framework;
using Nop.Web.Framework.Mvc.Routing;

namespace Nop.Plugin.Misc.Omnisend.Infrastructure;

Expand Down
Loading