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.

Improvements/utilize dotnet9 features (#581)

Guy Taggar0af58ae3a7f4
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs b/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs
index 5963caa5f..d321cd1a7 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs
@@ -890,7 +890,7 @@ public class ProductService : IProductService
foreach (var crossSell in crossSells)
{
//validate that this product is not added to result yet
- if (result.Find(p => p.Id == crossSell) != null ||
+ if (result.FirstOrDefault(p => p.Id == crossSell) != null ||
cartProductIds.Contains(crossSell)) continue;
var productToAdd = await GetProductById(crossSell);
//validate product
diff --git a/src/Business/Grand.Business.Checkout/Services/Orders/MerchandiseReturnService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/MerchandiseReturnService.cs
index e4080eda6..8d16ae9b4 100644
--- a/src/Business/Grand.Business.Checkout/Services/Orders/MerchandiseReturnService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Orders/MerchandiseReturnService.cs
@@ -45,7 +45,7 @@ public class MerchandiseReturnService : IMerchandiseReturnService
#region Fields
- private static readonly object Locker = new();
+ private static readonly Lock Locker = new();
private readonly IRepository<MerchandiseReturn> _merchandiseReturnRepository;
private readonly IRepository<MerchandiseReturnAction> _merchandiseReturnActionRepository;
diff --git a/src/Business/Grand.Business.Checkout/Services/Orders/OrderService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/OrderService.cs
index dcd664828..692bcf68c 100644
--- a/src/Business/Grand.Business.Checkout/Services/Orders/OrderService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Orders/OrderService.cs
@@ -112,7 +112,9 @@ public class OrderService : IOrderService
select o;
var orders = await Task.FromResult(query.ToList());
//sort by passed identifiers
- return orderIds.Select(id => orders.Find(x => x.Id == id)).Where(order => order != null).ToList();
+ return orderIds.Select(id => orders.FirstOrDefault(order => order.Id == id))
+ .Where(order => order != null)
+ .ToList();
}
/// <summary>
diff --git a/src/Business/Grand.Business.Checkout/Services/Shipping/ShippingMethodService.cs b/src/Business/Grand.Business.Checkout/Services/Shipping/ShippingMethodService.cs
index e71fcaf67..b1df7253d 100644
--- a/src/Business/Grand.Business.Checkout/Services/Shipping/ShippingMethodService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Shipping/ShippingMethodService.cs
@@ -88,7 +88,7 @@ public class ShippingMethodService : IShippingMethodService
shippingMethods = shippingMethods.Where(x => !x.CountryRestrictionExists(filterByCountryId)).ToList();
if (customer != null)
shippingMethods = shippingMethods
- .Where(x => !x.CustomerGroupRestrictionExists(customer.Groups.Select(y => y).ToList())).ToList();
+ .Where(x => !x.CustomerGroupRestrictionExists(customer.Groups)).ToList();
return shippingMethods;
}
diff --git a/src/Business/Grand.Business.Cms/Services/BlogService.cs b/src/Business/Grand.Business.Cms/Services/BlogService.cs
index 0419192c3..e89c568b6 100644
--- a/src/Business/Grand.Business.Cms/Services/BlogService.cs
+++ b/src/Business/Grand.Business.Cms/Services/BlogService.cs
@@ -155,7 +155,7 @@ public class BlogService : IBlogService
foreach (var tag in tags)
{
var foundBlogPostTag =
- blogPostTags.Find(bpt => bpt.Name.Equals(tag, StringComparison.OrdinalIgnoreCase));
+ blogPostTags.FirstOrDefault(bpt => bpt.Name.Equals(tag, StringComparison.OrdinalIgnoreCase));
if (foundBlogPostTag == null)
{
foundBlogPostTag = new BlogPostTag {
@@ -267,8 +267,10 @@ public class BlogService : IBlogService
select bc;
var comments = query.ToList();
//sort by passed identifiers
- var sortedComments = commentIds.Select(id => comments.Find(x => x.Id == id)).Where(comment => comment != null)
+ var sortedComments = commentIds.Select(id => comments.FirstOrDefault(comment => comment.Id == id))
+ .Where(comment => comment != null)
.ToList();
+
return await Task.FromResult(sortedComments);
}
diff --git a/src/Business/Grand.Business.Cms/Services/KnowledgebaseService.cs b/src/Business/Grand.Business.Cms/Services/KnowledgebaseService.cs
index 5da0ee58d..77d825dcf 100644
--- a/src/Business/Grand.Business.Cms/Services/KnowledgebaseService.cs
+++ b/src/Business/Grand.Business.Cms/Services/KnowledgebaseService.cs
@@ -512,13 +512,9 @@ public class KnowledgebaseService : IKnowledgebaseService
select bc;
var comments = query.ToList();
//sort by passed identifiers
- var sortedComments = new List<KnowledgebaseArticleComment>();
- foreach (var id in commentIds)
- {
- var comment = comments.Find(x => x.Id == id);
- if (comment != null)
- sortedComments.Add(comment);
- }
+ var sortedComments = commentIds.Select(id => comments.FirstOrDefault(x => x.Id == id))
+ .Where(comment => comment != null)
+ .ToList();
return await Task.FromResult(sortedComments);
}
diff --git a/src/Business/Grand.Business.Common/Services/Directory/CountryService.cs b/src/Business/Grand.Business.Common/Services/Directory/CountryService.cs
index 474d7181c..57d09af8e 100644
--- a/src/Business/Grand.Business.Common/Services/Directory/CountryService.cs
+++ b/src/Business/Grand.Business.Common/Services/Directory/CountryService.cs
@@ -143,7 +143,9 @@ public class CountryService : ICountryService
select c;
var countries = await Task.FromResult(query.ToList());
//sort by passed identifiers
- return countryIds.Select(id => countries.Find(x => x.Id == id)).Where(country => country != null).ToList();
+ return countryIds.Select(id => countries.FirstOrDefault(country => country.Id == id))
+ .Where(country => country != null)
+ .ToList();
}
/// <summary>
diff --git a/src/Business/Grand.Business.Common/Services/Security/EncryptionService.cs b/src/Business/Grand.Business.Common/Services/Security/EncryptionService.cs
index 0036aa4d4..5e4110cff 100644
--- a/src/Business/Grand.Business.Common/Services/Security/EncryptionService.cs
+++ b/src/Business/Grand.Business.Common/Services/Security/EncryptionService.cs
@@ -45,7 +45,7 @@ public class EncryptionService : IEncryptionService
throw new ArgumentException("Unrecognized hash name");
var hashByteArray = algorithm.ComputeHash(Encoding.UTF8.GetBytes(saltAndPassword));
- return BitConverter.ToString(hashByteArray).Replace("-", "");
+ return Convert.ToHexString(hashByteArray);
}
/// <summary>
diff --git a/src/Business/Grand.Business.Core/Extensions/SeoExtensions.cs b/src/Business/Grand.Business.Core/Extensions/SeoExtensions.cs
index 0dfc67cce..b349ccc7d 100644
--- a/src/Business/Grand.Business.Core/Extensions/SeoExtensions.cs
+++ b/src/Business/Grand.Business.Core/Extensions/SeoExtensions.cs
@@ -30,7 +30,7 @@ public static class SeoExtensions
#region Fields
private static Dictionary<string, string> _seoCharacterTable;
- private static readonly object SLock = new();
+ private static readonly Lock SLock = new();
#endregion
diff --git a/src/Business/Grand.Business.Core/Extensions/ShippingExtensions.cs b/src/Business/Grand.Business.Core/Extensions/ShippingExtensions.cs
index da5b9fe8d..1fd1bf7ea 100644
--- a/src/Business/Grand.Business.Core/Extensions/ShippingExtensions.cs
+++ b/src/Business/Grand.Business.Core/Extensions/ShippingExtensions.cs
@@ -19,27 +19,18 @@ public static class ShippingExtensions
public static bool CountryRestrictionExists(this ShippingMethod shippingMethod,
string countryId)
{
- ArgumentNullException.ThrowIfNull(shippingMethod);
-
- var result = shippingMethod.RestrictedCountries.ToList().Find(c => c.Id == countryId) != null;
- return result;
+ return shippingMethod.RestrictedCountries.Any(c => c.Id == countryId);
}
public static bool CustomerGroupRestrictionExists(this ShippingMethod shippingMethod,
string roleId)
{
- ArgumentNullException.ThrowIfNull(shippingMethod);
-
- var result = shippingMethod.RestrictedGroups.ToList().Find(c => c == roleId) != null;
- return result;
+ return shippingMethod.RestrictedGroups.Any(c => c == roleId);
}
public static bool CustomerGroupRestrictionExists(this ShippingMethod shippingMethod,
- List<string> roleIds)
+ IEnumerable<string> roleIds)
{
- ArgumentNullException.ThrowIfNull(shippingMethod);
-
- var result = shippingMethod.RestrictedGroups.ToList().Find(roleIds.Contains) != null;
- return result;
+ return shippingMethod.RestrictedGroups.Any(roleIds.Contains);
}
}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Core/Interfaces/Storage/IFileStore.cs b/src/Business/Grand.Business.Core/Interfaces/Storage/IFileStore.cs
index 35f3a45ce..8c417d12a 100644
--- a/src/Business/Grand.Business.Core/Interfaces/Storage/IFileStore.cs
+++ b/src/Business/Grand.Business.Core/Interfaces/Storage/IFileStore.cs
@@ -158,16 +158,20 @@ public static class IFileStoreExtensions
/// <param name="fileStore">The <see cref="IFileStore" />.</param>
/// <param name="paths">The path parts to combine.</param>
/// <returns>The full combined path.</returns>
- public static string Combine(this IFileStore fileStore, params string[] paths)
+ public static string Combine(this IFileStore fileStore, params ReadOnlySpan<string> paths)
{
if (paths.Length == 0)
return null;
-
- var normalizedParts =
- paths
- .Select(x => fileStore.NormalizePath(x))
- .Where(x => !string.IsNullOrEmpty(x))
- .ToArray();
+
+ List<string> normalizedParts = [];
+ foreach (var path in paths)
+ {
+ var normalizedPath = fileStore.NormalizePath(path);
+ if (!string.IsNullOrEmpty(normalizedPath))
+ {
+ normalizedParts.Add(normalizedPath);
+ }
+ }
var combined = string.Join("/", normalizedParts);
if (!Path.IsPathRooted(combined)) combined = "/" + combined;
diff --git a/src/Business/Grand.Business.Core/Utilities/Messages/DotLiquidDrops/LiquidExtensions.cs b/src/Business/Grand.Business.Core/Utilities/Messages/DotLiquidDrops/LiquidExtensions.cs
index 92894168e..f2254bd61 100644
--- a/src/Business/Grand.Business.Core/Utilities/Messages/DotLiquidDrops/LiquidExtensions.cs
+++ b/src/Business/Grand.Business.Core/Utilities/Messages/DotLiquidDrops/LiquidExtensions.cs
@@ -7,15 +7,15 @@ namespace Grand.Business.Core.Utilities.Messages.DotLiquidDrops;
public static class LiquidExtensions
{
- public static List<string> GetTokens(params Type[] drops)
+ public static List<string> GetTokens(params ReadOnlySpan<Type> drops)
{
- var toReturn = new List<string>();
+ List<string> tokens = [];
foreach (var drop in drops)
- toReturn.AddRange(drop
+ tokens.AddRange(drop
.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
- .Select(x => "{{" + drop.Name[6..] + "." + x.Name + "}}"));
+ .Select(property => "{{" + drop.Name[6..] + "." + property.Name + "}}"));
- return toReturn;
+ return tokens;
}
public static string Render(LiquidObject liquidObject, string source)
diff --git a/src/Business/Grand.Business.Customers/Services/CustomerService.cs b/src/Business/Grand.Business.Customers/Services/CustomerService.cs
index d3c24ed19..0695644ba 100644
--- a/src/Business/Grand.Business.Customers/Services/CustomerService.cs
+++ b/src/Business/Grand.Business.Customers/Services/CustomerService.cs
@@ -202,8 +202,10 @@ public class CustomerService : ICustomerService
select c;
var customers = query.ToList();
//sort by passed identifiers
- var sortedCustomers = customerIds.Select(id => customers.Find(x => x.Id == id))
- .Where(customer => customer != null).ToList();
+ var sortedCustomers = customerIds.Select(id => customers.FirstOrDefault(customer => customer.Id == id))
+ .Where(customer => customer != null)
+ .ToList();
+
return await Task.FromResult(sortedCustomers);
}
diff --git a/src/Business/Grand.Business.Messages/Services/QueuedEmailService.cs b/src/Business/Grand.Business.Messages/Services/QueuedEmailService.cs
index b4c963eb4..7770ebafa 100644
--- a/src/Business/Grand.Business.Messages/Services/QueuedEmailService.cs
+++ b/src/Business/Grand.Business.Messages/Services/QueuedEmailService.cs
@@ -106,8 +106,10 @@ public class QueuedEmailService : IQueuedEmailService
var queuedEmails = query.ToList();
//sort by passed identifiers
var sortedQueuedEmails =
- queuedEmailIds.Select(id => queuedEmails.Find(x => x.Id == id)).Where(queuedEmail => queuedEmail != null)
+ queuedEmailIds.Select(id => queuedEmails.FirstOrDefault(email => email.Id == id))
+ .Where(queuedEmail => queuedEmail != null)
.ToList();
+
return await Task.FromResult(sortedQueuedEmails);
}
diff --git a/src/Core/Grand.Data/DataSettingsManager.cs b/src/Core/Grand.Data/DataSettingsManager.cs
index 91940cfc5..8c998c912 100644
--- a/src/Core/Grand.Data/DataSettingsManager.cs
+++ b/src/Core/Grand.Data/DataSettingsManager.cs
@@ -8,7 +8,7 @@ namespace Grand.Data;
public sealed class DataSettingsManager
{
private static DataSettingsManager _instance;
- private static readonly object _lock = new();
+ private static readonly Lock _lock = new();
public static DataSettingsManager Instance => _instance ?? throw new InvalidOperationException("DataSettingsManager has not been initialized. Call Initialize first.");
diff --git a/src/Core/Grand.Domain/Common/AddressExtensions.cs b/src/Core/Grand.Domain/Common/AddressExtensions.cs
index 0d0093d35..ea19b5b0f 100644
--- a/src/Core/Grand.Domain/Common/AddressExtensions.cs
+++ b/src/Core/Grand.Domain/Common/AddressExtensions.cs
@@ -19,13 +19,13 @@ public static class AddressExtensions
/// <param name="zipPostalCode">Zip postal code</param>
/// <param name="countryId">Country identifier</param>
/// <returns>Address</returns>
- public static Address FindAddress(this List<Address> source,
+ public static Address FindAddress(this IEnumerable<Address> source,
string firstName, string lastName, string phoneNumber,
string email, string faxNumber, string company, string address1,
string address2, string city, string stateProvinceId,
string zipPostalCode, string countryId)
{
- return source.Find(a =>
+ return source.FirstOrDefault(a =>
((string.IsNullOrEmpty(a.FirstName) && string.IsNullOrEmpty(firstName)) || a.FirstName == firstName) &&
((string.IsNullOrEmpty(a.LastName) && string.IsNullOrEmpty(lastName)) || a.LastName == lastName) &&
((string.IsNullOrEmpty(a.PhoneNumber) && string.IsNullOrEmpty(phoneNumber)) ||
diff --git a/src/Core/Grand.Infrastructure/Plugins/PluginExtensions.cs b/src/Core/Grand.Infrastructure/Plugins/PluginExtensions.cs
index a05c475f5..558090061 100644
--- a/src/Core/Grand.Infrastructure/Plugins/PluginExtensions.cs
+++ b/src/Core/Grand.Infrastructure/Plugins/PluginExtensions.cs
@@ -6,7 +6,7 @@ namespace Grand.Infrastructure.Plugins;
public sealed class PluginPaths
{
private static PluginPaths _instance;
- private static readonly object _lock = new();
+ private static readonly Lock _lock = new();
public static PluginPaths Instance => _instance ?? throw new InvalidOperationException("PluginPaths has not been initialized. Call Initialize first.");
private readonly string _pluginPath;
diff --git a/src/Core/Grand.Infrastructure/Plugins/PluginManager.cs b/src/Core/Grand.Infrastructure/Plugins/PluginManager.cs
index 97d110fe2..278806195 100644
--- a/src/Core/Grand.Infrastructure/Plugins/PluginManager.cs
+++ b/src/Core/Grand.Infrastructure/Plugins/PluginManager.cs
@@ -21,7 +21,7 @@ public static class PluginManager
public const string CopyPath = "Plugins/bin";
- private static readonly object _synLock = new();
+ private static readonly Lock _synLock = new();
#endregion
diff --git a/src/Plugins/Shipping.ShippingPoint/ShippingPointRateProvider.cs b/src/Plugins/Shipping.ShippingPoint/ShippingPointRateProvider.cs
index c8158692c..734bc59de 100644
--- a/src/Plugins/Shipping.ShippingPoint/ShippingPointRateProvider.cs
+++ b/src/Plugins/Shipping.ShippingPoint/ShippingPointRateProvider.cs
@@ -111,7 +111,7 @@ public class ShippingPointRateProvider : IShippingRateCalculationProvider
//override price
var offeredShippingOptions = _contextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<List<ShippingOption>>(SystemCustomerFieldNames.OfferedShippingOptions, _contextAccessor.StoreContext.CurrentStore.Id);
- offeredShippingOptions.Find(x => x.Name == shippingMethodName).Rate =
+ offeredShippingOptions.First(x => x.Name == shippingMethodName).Rate =
await _currencyService.ConvertFromPrimaryStoreCurrency(chosenShippingOption.PickupFee,
_contextAccessor.WorkContext.WorkingCurrency);
diff --git a/src/Tests/Grand.Business.Common.Tests/Services/Security/EncryptionServiceTests.cs b/src/Tests/Grand.Business.Common.Tests/Services/Security/EncryptionServiceTests.cs
index 143fce1cd..492fec7ba 100644
--- a/src/Tests/Grand.Business.Common.Tests/Services/Security/EncryptionServiceTests.cs
+++ b/src/Tests/Grand.Business.Common.Tests/Services/Security/EncryptionServiceTests.cs
@@ -27,9 +27,9 @@ public class EncryptionServiceTests
}
[TestMethod]
- public void CreatePasswordHash_InvokeWithTheSameArguemtns_ReturnTheSameValue()
+ public void CreatePasswordHash_InvokeWithTheSameArguments_ReturnTheSameValue()
{
- var password = "password";
+ const string password = "password";
var salt = _encryptionService.CreateSaltKey(32);
var hash1 = _encryptionService.CreatePasswordHash(password, salt);
var hash2 = _encryptionService.CreatePasswordHash(password, salt);
@@ -40,6 +40,21 @@ public class EncryptionServiceTests
Assert.AreEqual(hash3, hash4);
Assert.AreNotEqual(hash4, hash5);
}
+
+ [TestMethod]
+ public void CreatePasswordHash_InvokeWithFixedSalt_ReturnExpectedHash()
+ {
+ // Arrange
+ const string password = "password";
+ const string salt = "tkpYgVYjK3P4hpLpqgY8popeQ26Ax8ZwyJaQ0F340yA=";
+ const string expectedHash = "5FDEFB16C983C42DAF16FA9595EA61BADCA69558";
+
+ // Act
+ var actualHash = _encryptionService.CreatePasswordHash(password, salt);
+
+ // Assert
+ Assert.AreEqual(expectedHash, actualHash);
+ }
[TestMethod]
public void EncryptText_TheSameKeyAndText_ReturnTheSameValues()
diff --git a/src/Tests/Grand.Domain.Tests/Common/AddressExtensionsTests.cs b/src/Tests/Grand.Domain.Tests/Common/AddressExtensionsTests.cs
index d17c68535..762fd705f 100644
--- a/src/Tests/Grand.Domain.Tests/Common/AddressExtensionsTests.cs
+++ b/src/Tests/Grand.Domain.Tests/Common/AddressExtensionsTests.cs
@@ -9,12 +9,12 @@ public class AddressExtensionsTests
[TestMethod]
public void FindAddressTest_NotNull()
{
- var addresses = new List<Address> {
+ Address[] addresses = [
new() { Address1 = "address1", Address2 = "address11", FirstName = "name1", LastName = "namelast1" },
new() { Address1 = "address2", Address2 = "address12", FirstName = "name2", LastName = "namelast2" },
new() { Address1 = "address3", Address2 = "address13", FirstName = "name3", LastName = "namelast3" },
new() { Address1 = "address4", Address2 = "address14", FirstName = "name4", LastName = "namelast4" }
- };
+ ];
var address = addresses.FindAddress("name1", "namelast1", string.Empty, string.Empty, string.Empty,
string.Empty, "address1", "address11", string.Empty, string.Empty, string.Empty, string.Empty);
Assert.IsNotNull(address);
@@ -23,12 +23,12 @@ public class AddressExtensionsTests
[TestMethod]
public void FindAddressTest_IsNull()
{
- var addresses = new List<Address> {
+ Address[] addresses = [
new() { Address1 = "address1", Address2 = "address11", FirstName = "name1", LastName = "namelast1" },
new() { Address1 = "address2", Address2 = "address12", FirstName = "name2", LastName = "namelast2" },
new() { Address1 = "address3", Address2 = "address13", FirstName = "name3", LastName = "namelast3" },
new() { Address1 = "address4", Address2 = "address14", FirstName = "name4", LastName = "namelast4" }
- };
+ ];
var address = addresses.FindAddress("name1", "namelast1", string.Empty, string.Empty, string.Empty,
string.Empty, "address1", "address2", "city", string.Empty, string.Empty, string.Empty);
Assert.IsNull(address);
diff --git a/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs b/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs
index 81f6df1ed..e807975d8 100644
--- a/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs
@@ -1225,7 +1225,7 @@ public class OrderViewModelService : IOrderViewModelService
foreach (var newOrderTag in newOrderTags)
{
OrderTag orderTag;
- var orderTag2 = allOrderTags.ToList().Find(o => o.Name == newOrderTag);
+ var orderTag2 = allOrderTags.FirstOrDefault(o => o.Name == newOrderTag);
if (orderTag2 == null)
{
diff --git a/src/Web/Grand.Web/Controllers/CheckoutController.cs b/src/Web/Grand.Web/Controllers/CheckoutController.cs
index fb2ce939b..0d6281647 100644
--- a/src/Web/Grand.Web/Controllers/CheckoutController.cs
+++ b/src/Web/Grand.Web/Controllers/CheckoutController.cs
@@ -214,7 +214,7 @@ public class CheckoutController : BasePublicController
}
//try to find an address with the same values (don't duplicate records)
- var address = _contextAccessor.WorkContext.CurrentCustomer.Addresses.ToList().FindAddress(
+ var address = _contextAccessor.WorkContext.CurrentCustomer.Addresses.FindAddress(
model.BillingNewAddress.FirstName, model.BillingNewAddress.LastName,
model.BillingNewAddress.PhoneNumber,
model.BillingNewAddress.Email, model.BillingNewAddress.FaxNumber,
@@ -370,7 +370,7 @@ public class CheckoutController : BasePublicController
}
//try to find an address with the same values (don't duplicate records)
- var address = _contextAccessor.WorkContext.CurrentCustomer.Addresses.ToList().FindAddress(
+ var address = _contextAccessor.WorkContext.CurrentCustomer.Addresses.FindAddress(
model.ShippingNewAddress.FirstName, model.ShippingNewAddress.LastName,
model.ShippingNewAddress.PhoneNumber,
model.ShippingNewAddress.Email, model.ShippingNewAddress.FaxNumber,
@@ -493,7 +493,7 @@ public class CheckoutController : BasePublicController
.ToList();
var shippingOption = shippingOptions
- .Find(so => !string.IsNullOrEmpty(so.Name) &&
+ .FirstOrDefault(so => !string.IsNullOrEmpty(so.Name) &&
so.Name.Equals(selectedName, StringComparison.OrdinalIgnoreCase));
if (shippingOption == null)
throw new Exception("Selected shipping method can't be loaded");
diff --git a/src/Web/Grand.Web/Features/Handlers/Checkout/GetPaymentMethodHandler.cs b/src/Web/Grand.Web/Features/Handlers/Checkout/GetPaymentMethodHandler.cs
index 34b8cb532..bb2318da1 100644
--- a/src/Web/Grand.Web/Features/Handlers/Checkout/GetPaymentMethodHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Checkout/GetPaymentMethodHandler.cs
@@ -103,8 +103,8 @@ public class GetPaymentMethodHandler : IRequestHandler<GetPaymentMethod, Checkou
request.Store.Id);
if (!string.IsNullOrEmpty(selectedPaymentMethodSystemName))
{
- var paymentMethodToSelect = model.PaymentMethods.ToList()
- .Find(pm => pm.PaymentMethodSystemName.Equals(selectedPaymentMethodSystemName,
+ var paymentMethodToSelect = model.PaymentMethods
+ .FirstOrDefault(pm => pm.PaymentMethodSystemName.Equals(selectedPaymentMethodSystemName,
StringComparison.OrdinalIgnoreCase));
if (paymentMethodToSelect != null)
paymentMethodToSelect.Selected = true;
diff --git a/src/Web/Grand.Web/Features/Handlers/Checkout/GetShippingMethodHandler.cs b/src/Web/Grand.Web/Features/Handlers/Checkout/GetShippingMethodHandler.cs
index 646e5ef67..e68c40699 100644
--- a/src/Web/Grand.Web/Features/Handlers/Checkout/GetShippingMethodHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Checkout/GetShippingMethodHandler.cs
@@ -76,8 +76,8 @@ public class GetShippingMethodHandler : IRequestHandler<GetShippingMethod, Check
request.Store.Id);
if (selectedShippingOption != null)
{
- var shippingOptionToSelect = model.ShippingMethods.ToList()
- .Find(so =>
+ var shippingOptionToSelect = model.ShippingMethods
+ .FirstOrDefault(so =>
!string.IsNullOrEmpty(so.Name) &&
so.Name.Equals(selectedShippingOption.Name, StringComparison.OrdinalIgnoreCase) &&
!string.IsNullOrEmpty(so.ShippingRateProviderSystemName) &&