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.

Remove IUserFieldService

supportf0d8d32acf98
diff --git a/src/API/Grand.Api/Commands/Handlers/Customers/AddCustomerCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Customers/AddCustomerCommandHandler.cs
index 656fdf871..4c8b93cc8 100644
--- a/src/API/Grand.Api/Commands/Handlers/Customers/AddCustomerCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Customers/AddCustomerCommandHandler.cs
@@ -2,10 +2,8 @@
using Grand.Api.DTOs.Customers;
using Grand.Api.Extensions;
using Grand.Business.Core.Interfaces.Common.Directory;
-using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Customers;
using Grand.Domain.Customers;
-using Grand.Infrastructure;
using MediatR;
namespace Grand.Api.Commands.Handlers.Customers;
@@ -14,22 +12,13 @@ public class AddCustomerCommandHandler : IRequestHandler<AddCustomerCommand, Cus
{
private readonly ICustomerService _customerService;
private readonly IGroupService _groupService;
- private readonly ITranslationService _translationService;
- private readonly IUserFieldService _userFieldsService;
- private readonly IWorkContext _workContext;
public AddCustomerCommandHandler(
ICustomerService customerService,
- IGroupService groupService,
- ITranslationService translationService,
- IUserFieldService userFieldsService,
- IWorkContext workContext)
+ IGroupService groupService)
{
_customerService = customerService;
_groupService = groupService;
- _translationService = translationService;
- _userFieldsService = userFieldsService;
- _workContext = workContext;
}
public async Task<CustomerDto> Handle(AddCustomerCommand request, CancellationToken cancellationToken)
@@ -46,24 +35,23 @@ public class AddCustomerCommandHandler : IRequestHandler<AddCustomerCommand, Cus
return customer.ToModel();
}
- protected async Task SaveCustomerAttributes(CustomerDto model, Customer customer)
+ private async Task SaveCustomerAttributes(CustomerDto model, Customer customer)
{
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.VatNumber, model.VatNumber);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.VatNumberStatusId,
- model.VatNumberStatusId);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.Gender, model.Gender);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.FirstName, model.FirstName);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.LastName, model.LastName);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.DateOfBirth, model.DateOfBirth);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.Company, model.Company);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.StreetAddress, model.StreetAddress);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.StreetAddress2, model.StreetAddress2);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.ZipPostalCode, model.ZipPostalCode);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.City, model.City);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.CountryId, model.CountryId);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.StateProvinceId, model.StateProvinceId);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.Phone, model.Phone);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.Fax, model.Fax);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.VatNumber, model.VatNumber);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.VatNumberStatusId, model.VatNumberStatusId);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.Gender, model.Gender);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.FirstName, model.FirstName);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.LastName, model.LastName);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.DateOfBirth, model.DateOfBirth);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.Company, model.Company);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.StreetAddress, model.StreetAddress);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.StreetAddress2, model.StreetAddress2);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.ZipPostalCode, model.ZipPostalCode);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.City, model.City);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.CountryId, model.CountryId);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.StateProvinceId, model.StateProvinceId);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.Phone, model.Phone);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.Fax, model.Fax);
}
protected async Task SaveCustomerGroups(CustomerDto model, Customer customer)
diff --git a/src/API/Grand.Api/Commands/Handlers/Customers/UpdateCustomerCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Customers/UpdateCustomerCommandHandler.cs
index 5ba565073..97f482de3 100644
--- a/src/API/Grand.Api/Commands/Handlers/Customers/UpdateCustomerCommandHandler.cs
+++ b/src/API/Grand.Api/Commands/Handlers/Customers/UpdateCustomerCommandHandler.cs
@@ -2,10 +2,8 @@
using Grand.Api.DTOs.Customers;
using Grand.Api.Extensions;
using Grand.Business.Core.Interfaces.Common.Directory;
-using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Customers;
using Grand.Domain.Customers;
-using Grand.Infrastructure;
using MediatR;
namespace Grand.Api.Commands.Handlers.Customers;
@@ -14,22 +12,13 @@ public class UpdateCustomerCommandHandler : IRequestHandler<UpdateCustomerComman
{
private readonly ICustomerService _customerService;
private readonly IGroupService _groupService;
- private readonly ITranslationService _translationService;
- private readonly IUserFieldService _userFieldsService;
- private readonly IWorkContext _workContext;
public UpdateCustomerCommandHandler(
ICustomerService customerService,
- IGroupService groupService,
- ITranslationService translationService,
- IUserFieldService userFieldsService,
- IWorkContext workContext)
+ IGroupService groupService)
{
_customerService = customerService;
_groupService = groupService;
- _translationService = translationService;
- _userFieldsService = userFieldsService;
- _workContext = workContext;
}
public async Task<CustomerDto> Handle(UpdateCustomerCommand request, CancellationToken cancellationToken)
@@ -42,24 +31,23 @@ public class UpdateCustomerCommandHandler : IRequestHandler<UpdateCustomerComman
return customer.ToModel();
}
- protected async Task SaveCustomerAttributes(CustomerDto model, Customer customer)
+ private async Task SaveCustomerAttributes(CustomerDto model, Customer customer)
{
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.VatNumber, model.VatNumber);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.VatNumberStatusId,
- model.VatNumberStatusId);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.Gender, model.Gender);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.FirstName, model.FirstName);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.LastName, model.LastName);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.DateOfBirth, model.DateOfBirth);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.Company, model.Company);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.StreetAddress, model.StreetAddress);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.StreetAddress2, model.StreetAddress2);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.ZipPostalCode, model.ZipPostalCode);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.City, model.City);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.CountryId, model.CountryId);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.StateProvinceId, model.StateProvinceId);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.Phone, model.Phone);
- await _userFieldsService.SaveField(customer, SystemCustomerFieldNames.Fax, model.Fax);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.VatNumber, model.VatNumber);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.VatNumberStatusId, model.VatNumberStatusId);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.Gender, model.Gender);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.FirstName, model.FirstName);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.LastName, model.LastName);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.DateOfBirth, model.DateOfBirth);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.Company, model.Company);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.StreetAddress, model.StreetAddress);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.StreetAddress2, model.StreetAddress2);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.ZipPostalCode, model.ZipPostalCode);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.City, model.City);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.CountryId, model.CountryId);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.StateProvinceId, model.StateProvinceId);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.Phone, model.Phone);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.Fax, model.Fax);
}
protected async Task SaveCustomerGroups(CustomerDto model, Customer customer)
diff --git a/src/API/Grand.Api/Controllers/TokenWebController.cs b/src/API/Grand.Api/Controllers/TokenWebController.cs
index fd0cd1de9..56400e1f6 100644
--- a/src/API/Grand.Api/Controllers/TokenWebController.cs
+++ b/src/API/Grand.Api/Controllers/TokenWebController.cs
@@ -2,8 +2,8 @@
using Grand.Api.DTOs;
using Grand.Api.Models.Common;
using Grand.Business.Core.Interfaces.Authentication;
-using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Customers;
+using Grand.Domain.Common;
using Grand.Domain.Customers;
using Grand.Infrastructure;
using Grand.Infrastructure.Configuration;
@@ -28,14 +28,12 @@ public class TokenWebController : ControllerBase
private readonly IMediator _mediator;
private readonly IRefreshTokenService _refreshTokenService;
private readonly IStoreHelper _storeHelper;
- private readonly IUserFieldService _userFieldService;
public TokenWebController(
ICustomerService customerService,
IMediator mediator,
IStoreHelper storeHelper,
IRefreshTokenService refreshTokenService,
- IUserFieldService userFieldService,
IAntiforgery antiforgery,
FrontendAPIConfig apiConfig)
{
@@ -43,7 +41,6 @@ public class TokenWebController : ControllerBase
_mediator = mediator;
_storeHelper = storeHelper;
_refreshTokenService = refreshTokenService;
- _userFieldService = userFieldService;
_antiforgery = antiforgery;
_apiConfig = apiConfig;
}
@@ -85,10 +82,8 @@ public class TokenWebController : ControllerBase
{
var customer = await _customerService.GetCustomerByEmail(model.Email);
var claims = new Dictionary<string, string> {
- { "Email", model.Email }, {
- "Token",
- await _userFieldService.GetFieldsForEntity<string>(customer, SystemCustomerFieldNames.PasswordToken)
- }
+ { "Email", model.Email },
+ { "Token", customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.PasswordToken) }
};
var tokenDto = await GetToken(claims, customer);
return Ok(tokenDto);
@@ -125,8 +120,7 @@ public class TokenWebController : ControllerBase
{
customer = await _customerService.GetCustomerByEmail(email);
claims.Add("Email", email);
- claims.Add("Token",
- await _userFieldService.GetFieldsForEntity<string>(customer, SystemCustomerFieldNames.PasswordToken));
+ claims.Add("Token", customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.PasswordToken));
}
else
{
diff --git a/src/Business/Grand.Business.Authentication/Services/CookieAuthenticationService.cs b/src/Business/Grand.Business.Authentication/Services/CookieAuthenticationService.cs
index 8882b0e04..94bfde893 100644
--- a/src/Business/Grand.Business.Authentication/Services/CookieAuthenticationService.cs
+++ b/src/Business/Grand.Business.Authentication/Services/CookieAuthenticationService.cs
@@ -1,5 +1,4 @@
-using Grand.Business.Core.Extensions;
-using Grand.Business.Core.Interfaces.Authentication;
+using Grand.Business.Core.Interfaces.Authentication;
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Utilities.Authentication;
@@ -25,21 +24,18 @@ public class CookieAuthenticationService : IGrandAuthenticationService
/// <param name="customerSettings">Customer settings</param>
/// <param name="customerService">Customer service</param>
/// <param name="groupService">Group service</param>
- /// <param name="userFieldService">Generic attribute service</param>
/// <param name="httpContextAccessor">HTTP context accessor</param>
/// <param name="securityConfig">SecurityConfig</param>
public CookieAuthenticationService(
CustomerSettings customerSettings,
ICustomerService customerService,
IGroupService groupService,
- IUserFieldService userFieldService,
IHttpContextAccessor httpContextAccessor,
SecurityConfig securityConfig)
{
_customerSettings = customerSettings;
_customerService = customerService;
_groupService = groupService;
- _userFieldService = userFieldService;
_httpContextAccessor = httpContextAccessor;
_securityConfig = securityConfig;
}
@@ -57,7 +53,6 @@ public class CookieAuthenticationService : IGrandAuthenticationService
private readonly CustomerSettings _customerSettings;
private readonly ICustomerService _customerService;
private readonly IGroupService _groupService;
- private readonly IUserFieldService _userFieldService;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly SecurityConfig _securityConfig;
private Customer _cachedCustomer;
@@ -87,12 +82,11 @@ public class CookieAuthenticationService : IGrandAuthenticationService
_securityConfig.CookieClaimsIssuer));
//add token
- var passwordToken =
- await customer.GetUserField<string>(_userFieldService, SystemCustomerFieldNames.PasswordToken);
+ var passwordToken = customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.PasswordToken);
if (string.IsNullOrEmpty(passwordToken))
{
var passwordGuid = Guid.NewGuid().ToString();
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.PasswordToken, passwordGuid);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.PasswordToken, passwordGuid);
claims.Add(new Claim(ClaimTypes.UserData, passwordGuid, ClaimValueTypes.String,
_securityConfig.CookieClaimsIssuer));
}
diff --git a/src/Business/Grand.Business.Authentication/Services/RefreshTokenService.cs b/src/Business/Grand.Business.Authentication/Services/RefreshTokenService.cs
index 0a2e781f6..269ee82b3 100644
--- a/src/Business/Grand.Business.Authentication/Services/RefreshTokenService.cs
+++ b/src/Business/Grand.Business.Authentication/Services/RefreshTokenService.cs
@@ -1,5 +1,6 @@
using Grand.Business.Core.Interfaces.Authentication;
-using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Customers;
+using Grand.Domain.Common;
using Grand.Domain.Customers;
using Grand.Domain.Security;
using Grand.Infrastructure.Configuration;
@@ -13,11 +14,11 @@ namespace Grand.Business.Authentication.Services;
public class RefreshTokenService : IRefreshTokenService
{
private readonly FrontendAPIConfig _apiConfig;
- private readonly IUserFieldService _userFieldService;
+ private readonly ICustomerService _customerService;
- public RefreshTokenService(IUserFieldService userFieldService, FrontendAPIConfig apiConfig)
+ public RefreshTokenService(ICustomerService customerService, FrontendAPIConfig apiConfig)
{
- _userFieldService = userFieldService;
+ _customerService = customerService;
_apiConfig = apiConfig;
}
@@ -37,14 +38,13 @@ public class RefreshTokenService : IRefreshTokenService
IsActive = true,
ValidTo = DateTime.UtcNow.AddMinutes(_apiConfig.RefreshTokenExpiryInMinutes)
};
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.RefreshToken, token);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.RefreshToken, token);
return token;
}
- public async Task<RefreshToken> GetCustomerRefreshToken(Customer customer)
+ public Task<RefreshToken> GetCustomerRefreshToken(Customer customer)
{
- return await _userFieldService.GetFieldsForEntity<RefreshToken>(customer,
- SystemCustomerFieldNames.RefreshToken);
+ return Task.FromResult(customer.GetUserFieldFromEntity<RefreshToken>(SystemCustomerFieldNames.RefreshToken));
}
public ClaimsPrincipal GetPrincipalFromToken(string token)
diff --git a/src/Business/Grand.Business.Authentication/Services/TwoFactorAuthenticationService.cs b/src/Business/Grand.Business.Authentication/Services/TwoFactorAuthenticationService.cs
index e561a35d7..e719858c7 100644
--- a/src/Business/Grand.Business.Authentication/Services/TwoFactorAuthenticationService.cs
+++ b/src/Business/Grand.Business.Authentication/Services/TwoFactorAuthenticationService.cs
@@ -1,6 +1,6 @@
using Google.Authenticator;
using Grand.Business.Core.Interfaces.Authentication;
-using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Utilities.Authentication;
using Grand.Domain.Common;
using Grand.Domain.Customers;
@@ -13,16 +13,16 @@ public class TwoFactorAuthenticationService : ITwoFactorAuthenticationService
{
private readonly IEnumerable<ISMSVerificationService> _smsVerificationService;
private readonly TwoFactorAuthenticator _twoFactorAuthentication;
- private readonly IUserFieldService _userFieldService;
+ private readonly ICustomerService _customerService;
private readonly IWorkContext _workContext;
public TwoFactorAuthenticationService(
IWorkContext workContext,
- IUserFieldService userFieldService,
+ ICustomerService customerService,
IEnumerable<ISMSVerificationService> smsVerificationService)
{
_workContext = workContext;
- _userFieldService = userFieldService;
+ _customerService = customerService;
_smsVerificationService = smsVerificationService;
_twoFactorAuthentication = new TwoFactorAuthenticator();
}
@@ -70,8 +70,8 @@ public class TwoFactorAuthenticationService : ITwoFactorAuthenticationService
case TwoFactorAuthenticationType.EmailVerification:
var token = PrepareRandomCode();
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.TwoFactorValidCode, token);
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.TwoFactorCodeValidUntil,
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.TwoFactorValidCode, token);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.TwoFactorCodeValidUntil,
DateTime.UtcNow.AddMinutes(30));
model.CustomValues.Add("Token", token);
break;
diff --git a/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartService.cs
index c4169ffbb..fa4e632ac 100644
--- a/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartService.cs
@@ -1,9 +1,7 @@
using Grand.Business.Core.Commands.Checkout.Orders;
using Grand.Business.Core.Events.Checkout.ShoppingCart;
-using Grand.Business.Core.Extensions;
using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Checkout.Orders;
-using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Utilities.Checkout;
using Grand.Domain.Catalog;
@@ -28,7 +26,6 @@ public class ShoppingCartService : IShoppingCartService
IProductService productService,
ICustomerService customerService,
IMediator mediator,
- IUserFieldService userFieldService,
IShoppingCartValidator shoppingCartValidator,
ShoppingCartSettings shoppingCartSettings)
{
@@ -36,7 +33,6 @@ public class ShoppingCartService : IShoppingCartService
_productService = productService;
_customerService = customerService;
_mediator = mediator;
- _userFieldService = userFieldService;
_shoppingCartValidator = shoppingCartValidator;
_shoppingCartSettings = shoppingCartSettings;
}
@@ -49,7 +45,6 @@ public class ShoppingCartService : IShoppingCartService
private readonly IProductService _productService;
private readonly ICustomerService _customerService;
private readonly IMediator _mediator;
- private readonly IUserFieldService _userFieldService;
private readonly IShoppingCartValidator _shoppingCartValidator;
private readonly ShoppingCartSettings _shoppingCartSettings;
@@ -427,18 +422,17 @@ public class ShoppingCartService : IShoppingCartService
//discount
var coupons = fromCustomer.ParseAppliedCouponCodes(SystemCustomerFieldNames.DiscountCoupons);
var resultCoupons = toCustomer.ApplyCouponCode(SystemCustomerFieldNames.DiscountCoupons, coupons);
- await _userFieldService.SaveField(toCustomer, SystemCustomerFieldNames.DiscountCoupons, resultCoupons);
+ await _customerService.UpdateUserField(toCustomer, SystemCustomerFieldNames.DiscountCoupons, resultCoupons);
//gift voucher
var giftVoucher = fromCustomer.ParseAppliedCouponCodes(SystemCustomerFieldNames.GiftVoucherCoupons);
var resultGift = toCustomer.ApplyCouponCode(SystemCustomerFieldNames.GiftVoucherCoupons, giftVoucher);
- await _userFieldService.SaveField(toCustomer, SystemCustomerFieldNames.GiftVoucherCoupons, resultGift);
+ await _customerService.UpdateUserField(toCustomer, SystemCustomerFieldNames.GiftVoucherCoupons, resultGift);
}
//move selected checkout attributes
- var checkoutAttributes = await fromCustomer.GetUserField<List<CustomAttribute>>(_userFieldService,
- SystemCustomerFieldNames.CheckoutAttributes, _workContext.CurrentStore.Id);
- await _userFieldService.SaveField(toCustomer, SystemCustomerFieldNames.CheckoutAttributes, checkoutAttributes,
+ var checkoutAttributes = fromCustomer.GetUserFieldFromEntity<List<CustomAttribute>>(SystemCustomerFieldNames.CheckoutAttributes, _workContext.CurrentStore.Id);
+ await _customerService.UpdateUserField(toCustomer, SystemCustomerFieldNames.CheckoutAttributes, checkoutAttributes,
_workContext.CurrentStore.Id);
}
diff --git a/src/Business/Grand.Business.Cms/Services/CookiePreference.cs b/src/Business/Grand.Business.Cms/Services/CookiePreference.cs
index a25d5810f..6fd57ee7e 100644
--- a/src/Business/Grand.Business.Cms/Services/CookiePreference.cs
+++ b/src/Business/Grand.Business.Cms/Services/CookiePreference.cs
@@ -1,5 +1,5 @@
using Grand.Business.Core.Interfaces.Cms;
-using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Domain.Common;
using Grand.Domain.Customers;
using Grand.Domain.Stores;
@@ -8,12 +8,10 @@ namespace Grand.Business.Cms.Services;
public class CookiePreference : ICookiePreference
{
private readonly IEnumerable<IConsentCookie> _consentCookies;
- private readonly IUserFieldService _userFieldService;
- public CookiePreference(IUserFieldService userFieldService,
+ public CookiePreference(
IEnumerable<IConsentCookie> consentCookies)
{
- _userFieldService = userFieldService;
_consentCookies = consentCookies;
}
@@ -23,16 +21,14 @@ public class CookiePreference : ICookiePreference
}
- public virtual async Task<bool?> IsEnable(Customer customer, Store store, string cookieSystemName)
+ public virtual Task<bool?> IsEnable(Customer customer, Store store, string cookieSystemName)
{
var result = default(bool?);
- var savedCookiesConsent =
- await _userFieldService.GetFieldsForEntity<Dictionary<string, bool>>(customer,
- SystemCustomerFieldNames.ConsentCookies, store.Id);
+ var savedCookiesConsent = customer.GetUserFieldFromEntity<Dictionary<string, bool>>(SystemCustomerFieldNames.ConsentCookies, store.Id);
if (savedCookiesConsent == null) return null;
- if (savedCookiesConsent.ContainsKey(cookieSystemName))
- result = savedCookiesConsent[cookieSystemName];
+ if (savedCookiesConsent.TryGetValue(cookieSystemName, out var value))
+ result = value;
- return result;
+ return Task.FromResult(result);
}
}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Common/Services/Directory/UserFieldService.cs b/src/Business/Grand.Business.Common/Services/Directory/UserFieldService.cs
deleted file mode 100644
index 2fd147475..000000000
--- a/src/Business/Grand.Business.Common/Services/Directory/UserFieldService.cs
+++ /dev/null
@@ -1,124 +0,0 @@
-using Grand.Business.Core.Interfaces.Common.Directory;
-using Grand.Data;
-using Grand.Domain;
-using Grand.Domain.Common;
-using Grand.SharedKernel.Extensions;
-
-namespace Grand.Business.Common.Services.Directory;
-
-/// <summary>
-/// User field service
-/// </summary>
-public class UserFieldService : IUserFieldService
-{
- #region Fields
-
- private readonly IRepository<UserFieldBaseEntity> _userFieldBaseEntityRepository;
-
- #endregion
-
- #region Ctor
-
- public UserFieldService(
- IRepository<UserFieldBaseEntity> userFieldBaseEntityRepository)
- {
- _userFieldBaseEntityRepository = userFieldBaseEntityRepository;
- }
-
- #endregion
-
- #region Methods
-
- /// <summary>
- /// Save attribute value
- /// </summary>
- /// <typeparam name="TPropType">Property type</typeparam>
- /// <param name="entity">Entity</param>
- /// <param name="key">Key</param>
- /// <param name="value">Value</param>
- /// <param name="storeId">Store identifier; pass "" if this attribute will be available for all stores</param>
- public virtual async Task SaveField<TPropType>(BaseEntity entity, string key, TPropType value, string storeId = "")
- {
- ArgumentNullException.ThrowIfNull(entity);
- ArgumentNullException.ThrowIfNull(key);
-
- var collectionName = entity.GetType().Name;
-
- _ = _userFieldBaseEntityRepository.SetCollection(collectionName);
-
- var baseFields = await _userFieldBaseEntityRepository.GetByIdAsync(entity.Id);
-
- var props = baseFields.UserFields.Where(x => string.IsNullOrEmpty(storeId) || x.StoreId == storeId);
-
- var prop = props.FirstOrDefault(ga =>
- ga.Key.Equals(key, StringComparison.OrdinalIgnoreCase)); //should be culture invariant
-
- var valueStr = CommonHelper.To<string>(value);
-
- if (prop != null)
- {
- if (string.IsNullOrWhiteSpace(valueStr))
- {
- //delete
- await _userFieldBaseEntityRepository.PullFilter(entity.Id, x => x.UserFields,
- y => y.Key == prop.Key && y.StoreId == storeId);
-
- var entityProp = entity.UserFields.FirstOrDefault(x => x.Key == prop.Key && x.StoreId == storeId);
- if (entityProp != null)
- entity.UserFields.Remove(entityProp);
- }
- else
- {
- //update
- prop.Value = valueStr;
- await _userFieldBaseEntityRepository.UpdateToSet(entity.Id, x => x.UserFields,
- y => y.Key == prop.Key && y.StoreId == storeId, prop);
-
- var entityProp = entity.UserFields.FirstOrDefault(x => x.Key == prop.Key && x.StoreId == storeId);
- if (entityProp != null)
- entityProp.Value = valueStr;
- }
- }
- else
- {
- if (!string.IsNullOrWhiteSpace(valueStr))
- {
- prop = new UserField {
- Key = key,
- Value = valueStr,
- StoreId = storeId
- };
- await _userFieldBaseEntityRepository.AddToSet(entity.Id, x => x.UserFields, prop);
-
- entity.UserFields.Add(prop);
- }
- }
- }
-
- public virtual async Task<TPropType> GetFieldsForEntity<TPropType>(BaseEntity entity, string key,
- string storeId = "")
- {
- ArgumentNullException.ThrowIfNull(entity);
-
- var collectionName = entity.GetType().Name;
- _ = _userFieldBaseEntityRepository.SetCollection(collectionName);
-
- var baseFields = await _userFieldBaseEntityRepository.GetByIdAsync(entity.Id);
- var props = baseFields?.UserFields;
- if (props == null)
- return default;
- props = props.Where(x => x.StoreId == storeId).ToList();
- if (!props.Any())
- return default;
-
- var prop = props.FirstOrDefault(ga =>
- ga.Key.Equals(key, StringComparison.OrdinalIgnoreCase));
-
- if (prop == null || string.IsNullOrEmpty(prop.Value))
- return default;
-
- return CommonHelper.To<TPropType>(prop.Value);
- }
-
- #endregion
-}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Common/Startup/StartupApplication.cs b/src/Business/Grand.Business.Common/Startup/StartupApplication.cs
index 9f55bf0eb..6a884c43f 100644
--- a/src/Business/Grand.Business.Common/Startup/StartupApplication.cs
+++ b/src/Business/Grand.Business.Common/Startup/StartupApplication.cs
@@ -50,7 +50,6 @@ public class StartupApplication : IStartupApplication
{
serviceCollection.AddScoped<IAddressAttributeParser, AddressAttributeParser>();
serviceCollection.AddScoped<IAddressAttributeService, AddressAttributeService>();
- serviceCollection.AddScoped<IUserFieldService, UserFieldService>();
serviceCollection.AddScoped<IHistoryService, HistoryService>();
serviceCollection.AddScoped<IPdfService, HtmlToPdfService>();
}
diff --git a/src/Business/Grand.Business.Core/Extensions/UserFieldExtensions.cs b/src/Business/Grand.Business.Core/Extensions/UserFieldExtensions.cs
deleted file mode 100644
index 4b5014b2d..000000000
--- a/src/Business/Grand.Business.Core/Extensions/UserFieldExtensions.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using Grand.Business.Core.Interfaces.Common.Directory;
-using Grand.Domain;
-
-namespace Grand.Business.Core.Extensions;
-
-public static class UserFieldExtensions
-{
- /// <summary>
- /// Get an user field of an entity
- /// </summary>
- /// <typeparam name="TPropType">Property type</typeparam>
- /// <param name="entity">Entity</param>
- /// <param name="userFieldService">UserFieldService</param>
- /// <param name="key">Key</param>
- /// <param name="storeId">Load a value specific for a certain store; pass 0 to load a value shared for all stores</param>
- /// <returns>Attribute</returns>
- public static async Task<TPropType> GetUserField<TPropType>(this BaseEntity entity,
- IUserFieldService userFieldService, string key, string storeId = "")
- {
- ArgumentNullException.ThrowIfNull(entity);
-
- return await userFieldService.GetFieldsForEntity<TPropType>(entity, key, storeId);
- }
-}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Core/Interfaces/Common/Directory/IUserFieldService.cs b/src/Business/Grand.Business.Core/Interfaces/Common/Directory/IUserFieldService.cs
deleted file mode 100644
index 048fbd9c2..000000000
--- a/src/Business/Grand.Business.Core/Interfaces/Common/Directory/IUserFieldService.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using Grand.Domain;
-
-namespace Grand.Business.Core.Interfaces.Common.Directory;
-
-/// <summary>
-/// User fields service interface
-/// </summary>
-public interface IUserFieldService
-{
- Task SaveField<TPropType>(BaseEntity entity, string key, TPropType value, string storeId = "");
- Task<TPropType> GetFieldsForEntity<TPropType>(BaseEntity entity, string key, string storeId = "");
-}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Core/Interfaces/Customers/ICustomerService.cs b/src/Business/Grand.Business.Core/Interfaces/Customers/ICustomerService.cs
index 7291f6731..0a07b9087 100644
--- a/src/Business/Grand.Business.Core/Interfaces/Customers/ICustomerService.cs
+++ b/src/Business/Grand.Business.Core/Interfaces/Customers/ICustomerService.cs
@@ -142,6 +142,17 @@ public interface ICustomerService
/// <param name="customer">Customer</param>
Task UpdateCustomer(Customer customer);
+ /// <summary>
+ /// Updates the customer user field
+ /// </summary>
+ /// <param name="customer"></param>
+ /// <param name="key"></param>
+ /// <param name="value"></param>
+ /// <param name="storeId"></param>
+ /// <typeparam name="TPropType"></typeparam>
+ /// <returns></returns>
+ Task UpdateUserField<TPropType>(Customer customer, string key, TPropType value, string storeId = "");
+
/// <summary>
/// Delete a customer
/// </summary>
diff --git a/src/Business/Grand.Business.Customers/Services/CustomerManagerService.cs b/src/Business/Grand.Business.Customers/Services/CustomerManagerService.cs
index 352aa40bb..3ea2f34d2 100644
--- a/src/Business/Grand.Business.Customers/Services/CustomerManagerService.cs
+++ b/src/Business/Grand.Business.Customers/Services/CustomerManagerService.cs
@@ -25,7 +25,6 @@ public class CustomerManagerService : ICustomerManagerService
/// <param name="groupService">Group service</param>
/// <param name="encryptionService">Encryption service</param>
/// <param name="mediator">Mediator</param>
- /// <param name="userFieldService">UserFields service</param>
/// <param name="customerHistoryPasswordService">History password</param>
/// <param name="customerSettings">Customer settings</param>
public CustomerManagerService(
@@ -33,7 +32,6 @@ public class CustomerManagerService : ICustomerManagerService
IGroupService groupService,
IEncryptionService encryptionService,
IMediator mediator,
- IUserFieldService userFieldService,
ICustomerHistoryPasswordService customerHistoryPasswordService,
CustomerSettings customerSettings)
{
@@ -41,7 +39,6 @@ public class CustomerManagerService : ICustomerManagerService
_groupService = groupService;
_encryptionService = encryptionService;
_mediator = mediator;
- _userFieldService = userFieldService;
_customerHistoryPasswordService = customerHistoryPasswordService;
_customerSettings = customerSettings;
}
@@ -54,7 +51,6 @@ public class CustomerManagerService : ICustomerManagerService
private readonly IGroupService _groupService;
private readonly IEncryptionService _encryptionService;
private readonly IMediator _mediator;
- private readonly IUserFieldService _userFieldService;
private readonly ICustomerHistoryPasswordService _customerHistoryPasswordService;
private readonly CustomerSettings _customerSettings;
@@ -210,7 +206,7 @@ public class CustomerManagerService : ICustomerManagerService
await _customerHistoryPasswordService.InsertCustomerPassword(customer);
//create new login token
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.PasswordToken, Guid.NewGuid().ToString());
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.PasswordToken, Guid.NewGuid().ToString());
}
#endregion
diff --git a/src/Business/Grand.Business.Customers/Services/CustomerService.cs b/src/Business/Grand.Business.Customers/Services/CustomerService.cs
index d0a11f290..e0a0899f1 100644
--- a/src/Business/Grand.Business.Customers/Services/CustomerService.cs
+++ b/src/Business/Grand.Business.Customers/Services/CustomerService.cs
@@ -1,4 +1,3 @@
-using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Queries.Customers;
using Grand.Data;
@@ -11,6 +10,7 @@ using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Caching.Constants;
using Grand.Infrastructure.Extensions;
using Grand.SharedKernel;
+using Grand.SharedKernel.Extensions;
using MediatR;
using System.Linq.Expressions;
@@ -25,12 +25,10 @@ public class CustomerService : ICustomerService
public CustomerService(
IRepository<Customer> customerRepository,
- IUserFieldService userFieldService,
IMediator mediator,
ICacheBase cacheBase)
{
_customerRepository = customerRepository;
- _userFieldService = userFieldService;
_mediator = mediator;
_cacheBase = cacheBase;
}
@@ -40,7 +38,6 @@ public class CustomerService : ICustomerService
#region Fields
private readonly IRepository<Customer> _customerRepository;
- private readonly IUserFieldService _userFieldService;
private readonly IMediator _mediator;
private readonly ICacheBase _cacheBase;
@@ -361,6 +358,64 @@ public class CustomerService : ICustomerService
await _mediator.EntityUpdated(customer);
}
+ /// <summary>
+ /// Save attribute value
+ /// </summary>
+ /// <typeparam name="TPropType">Property type</typeparam>
+ /// <param name="customer"></param>
+ /// <param name="key">Key</param>
+ /// <param name="value">Value</param>
+ /// <param name="storeId">Store identifier; pass "" if this attribute will be available for all stores</param>
+ public virtual async Task UpdateUserField<TPropType>(Customer customer, string key, TPropType value, string storeId = "")
+ {
+ ArgumentNullException.ThrowIfNull(customer);
+ ArgumentNullException.ThrowIfNull(key);
+
+ var props = customer.UserFields.Where(x => string.IsNullOrEmpty(storeId) || x.StoreId == storeId);
+
+ var prop = props.FirstOrDefault(ga =>
+ ga.Key.Equals(key, StringComparison.OrdinalIgnoreCase)); //should be culture invariant
+
+ var valueStr = CommonHelper.To<string>(value);
+
+ if (prop != null)
+ {
+ if (string.IsNullOrWhiteSpace(valueStr))
+ {
+ //delete
+ await _customerRepository.PullFilter(customer.Id, x => x.UserFields,
+ y => y.Key == prop.Key && y.StoreId == storeId);
+
+ var entityProp = customer.UserFields.FirstOrDefault(x => x.Key == prop.Key && x.StoreId == storeId);
+ if (entityProp != null)
+ customer.UserFields.Remove(entityProp);
+ }
+ else
+ {
+ //update
+ prop.Value = valueStr;
+ await _customerRepository.UpdateToSet(customer.Id, x => x.UserFields,
+ y => y.Key == prop.Key && y.StoreId == storeId, prop);
+
+ var entityProp = customer.UserFields.FirstOrDefault(x => x.Key == prop.Key && x.StoreId == storeId);
+ if (entityProp != null)
+ entityProp.Value = valueStr;
+ }
+ }
+ else
+ {
+ if (!string.IsNullOrWhiteSpace(valueStr))
+ {
+ prop = new UserField {
+ Key = key,
+ Value = valueStr,
+ StoreId = storeId
+ };
+ await _customerRepository.AddToSet(customer.Id, x => x.UserFields, prop);
+ customer.UserFields.Add(prop);
+ }
+ }
+ }
/// <summary>
/// Delete a customer
@@ -492,41 +547,34 @@ public class CustomerService : ICustomerService
//clear entered coupon codes
if (clearCouponCodes)
{
- await _userFieldService.SaveField<string>(customer, SystemCustomerFieldNames.DiscountCoupons, null);
- await _userFieldService.SaveField<string>(customer, SystemCustomerFieldNames.GiftVoucherCoupons, null);
+ await UpdateUserField<string>(customer, SystemCustomerFieldNames.DiscountCoupons, null);
+ await UpdateUserField<string>(customer, SystemCustomerFieldNames.GiftVoucherCoupons, null);
}
//clear checkout attributes
if (clearCheckoutAttributes)
- await _userFieldService.SaveField<string>(customer, SystemCustomerFieldNames.CheckoutAttributes, null,
- storeId);
+ await UpdateUserField<string>(customer, SystemCustomerFieldNames.CheckoutAttributes, null, storeId);
//clear loyalty points flag
if (clearLoyaltyPoints)
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.UseLoyaltyPointsDuringCheckout, false,
- storeId);
+ await UpdateUserField(customer, SystemCustomerFieldNames.UseLoyaltyPointsDuringCheckout, false, storeId);
//clear selected shipping method
if (clearShipping)
{
- await _userFieldService.SaveField<ShippingOption>(customer, SystemCustomerFieldNames.SelectedShippingOption,
- null, storeId);
- await _userFieldService.SaveField<ShippingOption>(customer, SystemCustomerFieldNames.OfferedShippingOptions,
- null, storeId);
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.SelectedPickupPoint, "", storeId);
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.ShippingOptionAttributeDescription, "",
- storeId);
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.ShippingOptionAttribute, "", storeId);
+ await UpdateUserField<ShippingOption>(customer, SystemCustomerFieldNames.SelectedShippingOption, null, storeId);
+ await UpdateUserField<ShippingOption>(customer, SystemCustomerFieldNames.OfferedShippingOptions, null, storeId);
+ await UpdateUserField(customer, SystemCustomerFieldNames.SelectedPickupPoint, "", storeId);
+ await UpdateUserField(customer, SystemCustomerFieldNames.ShippingOptionAttributeDescription, "", storeId);
+ await UpdateUserField(customer, SystemCustomerFieldNames.ShippingOptionAttribute, "", storeId);
}
//clear selected payment method
if (clearPayment)
{
- await _userFieldService.SaveField<string>(customer, SystemCustomerFieldNames.SelectedPaymentMethod, null,
- storeId);
- await _userFieldService.SaveField<string>(customer, SystemCustomerFieldNames.PaymentTransaction, null,
- storeId);
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.PaymentOptionAttribute, "", storeId);
+ await UpdateUserField<string>(customer, SystemCustomerFieldNames.SelectedPaymentMethod, null, storeId);
+ await UpdateUserField<string>(customer, SystemCustomerFieldNames.PaymentTransaction, null, storeId);
+ await UpdateUserField(customer, SystemCustomerFieldNames.PaymentOptionAttribute, "", storeId);
}
}
diff --git a/src/Plugins/Authentication.Facebook/Infrastructure/Cache/FacebookAuthenticationEventConsumer.cs b/src/Plugins/Authentication.Facebook/Infrastructure/Cache/FacebookAuthenticationEventConsumer.cs
index 2587bb7a8..a1e94db96 100644
--- a/src/Plugins/Authentication.Facebook/Infrastructure/Cache/FacebookAuthenticationEventConsumer.cs
+++ b/src/Plugins/Authentication.Facebook/Infrastructure/Cache/FacebookAuthenticationEventConsumer.cs
@@ -1,5 +1,6 @@
using Grand.Business.Core.Commands.Customers;
using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Interfaces.Messages;
using Grand.Domain.Customers;
using Grand.Infrastructure;
@@ -16,12 +17,12 @@ public class FacebookAuthenticationEventConsumer : INotificationHandler<Register
#region Ctor
public FacebookAuthenticationEventConsumer(
- IUserFieldService userFieldService,
+ ICustomerService customerService,
IMessageProviderService messageProviderService,
IWorkContext workContext,
CustomerSettings customerSettings)
{
- _userFieldService = userFieldService;
+ _customerService = customerService;
_messageProviderService = messageProviderService;
_workContext = workContext;
_customerSettings = customerSettings;
@@ -45,12 +46,12 @@ public class FacebookAuthenticationEventConsumer : INotificationHandler<Register
var firstName = eventMessage.AuthenticationParameters.Claims
?.FirstOrDefault(claim => claim.Type == ClaimTypes.GivenName)?.Value;
if (!string.IsNullOrEmpty(firstName))
- await _userFieldService.SaveField(eventMessage.Customer, SystemCustomerFieldNames.FirstName, firstName);
+ await _customerService.UpdateUserField(eventMessage.Customer, SystemCustomerFieldNames.FirstName, firstName);
var lastName = eventMessage.AuthenticationParameters.Claims
?.FirstOrDefault(claim => claim.Type == ClaimTypes.Surname)?.Value;
if (!string.IsNullOrEmpty(lastName))
- await _userFieldService.SaveField(eventMessage.Customer, SystemCustomerFieldNames.LastName, lastName);
+ await _customerService.UpdateUserField(eventMessage.Customer, SystemCustomerFieldNames.LastName, lastName);
//notifications for admin
if (_customerSettings.NotifyNewCustomerRegistration)
@@ -66,7 +67,7 @@ public class FacebookAuthenticationEventConsumer : INotificationHandler<Register
#region Fields
- private readonly IUserFieldService _userFieldService;
+ private readonly ICustomerService _customerService;
private readonly IMessageProviderService _messageProviderService;
private readonly IWorkContext _workContext;
private readonly CustomerSettings _customerSettings;
diff --git a/src/Plugins/Authentication.Google/Infrastructure/GoogleAuthenticationEventConsumer.cs b/src/Plugins/Authentication.Google/Infrastructure/GoogleAuthenticationEventConsumer.cs
index 3573e9a34..ec42e316a 100644
--- a/src/Plugins/Authentication.Google/Infrastructure/GoogleAuthenticationEventConsumer.cs
+++ b/src/Plugins/Authentication.Google/Infrastructure/GoogleAuthenticationEventConsumer.cs
@@ -1,5 +1,6 @@
using Grand.Business.Core.Commands.Customers;
using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Interfaces.Messages;
using Grand.Domain.Customers;
using Grand.Infrastructure;
@@ -16,13 +17,13 @@ public class GoogleAuthenticationEventConsumer : INotificationHandler<Registered
#region Ctor
public GoogleAuthenticationEventConsumer(
- IUserFieldService userFieldService,
+ ICustomerService customerService,
IMessageProviderService messageProviderService,
IWorkContext workContext,
CustomerSettings customerSettings
)
{
- _userFieldService = userFieldService;
+ _customerService = customerService;
_messageProviderService = messageProviderService;
_workContext = workContext;
_customerSettings = customerSettings;
@@ -46,12 +47,12 @@ public class GoogleAuthenticationEventConsumer : INotificationHandler<Registered
var firstName = eventMessage.AuthenticationParameters.Claims
?.FirstOrDefault(claim => claim.Type == ClaimTypes.GivenName)?.Value;
if (!string.IsNullOrEmpty(firstName))
- await _userFieldService.SaveField(eventMessage.Customer, SystemCustomerFieldNames.FirstName, firstName);
+ await _customerService.UpdateUserField(eventMessage.Customer, SystemCustomerFieldNames.FirstName, firstName);
var lastName = eventMessage.AuthenticationParameters.Claims
?.FirstOrDefault(claim => claim.Type == ClaimTypes.Surname)?.Value;
if (!string.IsNullOrEmpty(lastName))
- await _userFieldService.SaveField(eventMessage.Customer, SystemCustomerFieldNames.LastName, lastName);
+ await _customerService.UpdateUserField(eventMessage.Customer, SystemCustomerFieldNames.LastName, lastName);
//notifications for admin
if (_customerSettings.NotifyNewCustomerRegistration)
@@ -67,7 +68,7 @@ public class GoogleAuthenticationEventConsumer : INotificationHandler<Registered
#region Fields
- private readonly IUserFieldService _userFieldService;
+ private readonly ICustomerService _customerService;
private readonly IMessageProviderService _messageProviderService;
private readonly IWorkContext _workContext;
private readonly CustomerSettings _customerSettings;
diff --git a/src/Plugins/Shipping.ShippingPoint/ShippingPointRateProvider.cs b/src/Plugins/Shipping.ShippingPoint/ShippingPointRateProvider.cs
index 9621d1388..47193db39 100644
--- a/src/Plugins/Shipping.ShippingPoint/ShippingPointRateProvider.cs
+++ b/src/Plugins/Shipping.ShippingPoint/ShippingPointRateProvider.cs
@@ -3,7 +3,9 @@ using Grand.Business.Core.Extensions;
using Grand.Business.Core.Interfaces.Checkout.Shipping;
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Utilities.Checkout;
+using Grand.Domain.Common;
using Grand.Domain.Customers;
using Grand.Domain.Orders;
using Grand.Domain.Shipping;
@@ -22,7 +24,7 @@ public class ShippingPointRateProvider : IShippingRateCalculationProvider
IShippingPointService shippingPointService,
ITranslationService translationService,
IWorkContext workContext,
- IUserFieldService userFieldService,
+ ICustomerService customerService,
ICountryService countryService,
ICurrencyService currencyService,
ShippingPointRateSettings shippingPointRateSettings
@@ -31,7 +33,7 @@ public class ShippingPointRateProvider : IShippingRateCalculationProvider
_shippingPointService = shippingPointService;
_translationService = translationService;
_workContext = workContext;
- _userFieldService = userFieldService;
+ _customerService = customerService;
_countryService = countryService;
_currencyService = currencyService;
_shippingPointRateSettings = shippingPointRateSettings;
@@ -44,7 +46,7 @@ public class ShippingPointRateProvider : IShippingRateCalculationProvider
private readonly IShippingPointService _shippingPointService;
private readonly ITranslationService _translationService;
private readonly IWorkContext _workContext;
- private readonly IUserFieldService _userFieldService;
+ private readonly ICustomerService _customerService;
private readonly ICountryService _countryService;
private readonly ICurrencyService _currencyService;
@@ -108,13 +110,12 @@ public class ShippingPointRateProvider : IShippingRateCalculationProvider
return new List<string> { _translationService.GetResource("Shipping.ShippingPoint.SelectBeforeProceed") };
//override price
- var offeredShippingOptions = await _workContext.CurrentCustomer.GetUserField<List<ShippingOption>>(
- _userFieldService, SystemCustomerFieldNames.OfferedShippingOptions, _workContext.CurrentStore.Id);
+ var offeredShippingOptions = _workContext.CurrentCustomer.GetUserFieldFromEntity<List<ShippingOption>>(SystemCustomerFieldNames.OfferedShippingOptions, _workContext.CurrentStore.Id);
offeredShippingOptions.Find(x => x.Name == shippingMethodName).Rate =
await _currencyService.ConvertFromPrimaryStoreCurrency(chosenShippingOption.PickupFee,
_workContext.WorkingCurrency);
- await _userFieldService.SaveField(
+ await _customerService.UpdateUserField(
_workContext.CurrentCustomer,
SystemCustomerFieldNames.OfferedShippingOptions,
offeredShippingOptions,
@@ -123,7 +124,7 @@ public class ShippingPointRateProvider : IShippingRateCalculationProvider
var forCustomer =
$"<strong>{_translationService.GetResource("Shipping.ShippingPoint.Fields.ShippingPointName")}:</strong> {chosenShippingOption.ShippingPointName}<br><strong>{_translationService.GetResource("Shipping.ShippingPoint.Fields.Description")}:</strong> {chosenShippingOption.Description}<br>";
- await _userFieldService.SaveField(
+ await _customerService.UpdateUserField(
_workContext.CurrentCustomer,
SystemCustomerFieldNames.ShippingOptionAttributeDescription,
forCustomer,
@@ -151,7 +152,7 @@ public class ShippingPointRateProvider : IShippingRateCalculationProvider
serializedAttribute = stringBuilder.ToString();
}
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.ShippingOptionAttribute,
serializedAttribute,
_workContext.CurrentStore.Id);
diff --git a/src/Tests/Grand.Business.Authentication.Tests/Services/CookieAuthenticationServiceTests.cs b/src/Tests/Grand.Business.Authentication.Tests/Services/CookieAuthenticationServiceTests.cs
index bc37aee23..c814c495d 100644
--- a/src/Tests/Grand.Business.Authentication.Tests/Services/CookieAuthenticationServiceTests.cs
+++ b/src/Tests/Grand.Business.Authentication.Tests/Services/CookieAuthenticationServiceTests.cs
@@ -23,7 +23,6 @@ public class CookieAuthenticationServiceTests
private Mock<IGroupService> _groupServiceMock;
private Mock<IHttpContextAccessor> _httpAccessorMock;
private DefaultHttpContext _httpContext;
- private Mock<IUserFieldService> _userFieldServiceMock;
private Mock<IServiceProvider> serviceProviderMock;
[TestInitialize]
@@ -34,13 +33,12 @@ public class CookieAuthenticationServiceTests
_httpAccessorMock = new Mock<IHttpContextAccessor>();
_customerSettings = new CustomerSettings();
_groupServiceMock = new Mock<IGroupService>();
- _userFieldServiceMock = new Mock<IUserFieldService>();
_config = new SecurityConfig {
CookieClaimsIssuer = "grandnode",
CookiePrefix = ".Grand."
};
_cookieAuthService = new CookieAuthenticationService(_customerSettings, _customerServiceMock.Object,
- _groupServiceMock.Object, _userFieldServiceMock.Object, _httpAccessorMock.Object, _config);
+ _groupServiceMock.Object, _httpAccessorMock.Object, _config);
//For mock HttpContext extension methods like SignOutAsync ,SignInAsync etc..
_authServiceMock = new Mock<IAuthenticationService>();
serviceProviderMock = new Mock<IServiceProvider>();
diff --git a/src/Tests/Grand.Business.Authentication.Tests/Services/RefreshTokenServiceTests.cs b/src/Tests/Grand.Business.Authentication.Tests/Services/RefreshTokenServiceTests.cs
index 56f72645d..727e61c98 100644
--- a/src/Tests/Grand.Business.Authentication.Tests/Services/RefreshTokenServiceTests.cs
+++ b/src/Tests/Grand.Business.Authentication.Tests/Services/RefreshTokenServiceTests.cs
@@ -1,11 +1,17 @@
using Grand.Business.Authentication.Services;
using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Domain;
+using Grand.Domain.Common;
using Grand.Domain.Customers;
using Grand.Domain.Security;
+using Grand.Domain.Stores;
using Grand.Infrastructure.Configuration;
+using Grand.Infrastructure.TypeConverters.Converter;
+using Grand.SharedKernel.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using System.ComponentModel;
namespace Grand.Business.Authentication.Tests.Services;
@@ -13,13 +19,13 @@ namespace Grand.Business.Authentication.Tests.Services;
public class RefreshTokenServiceTests
{
private RefreshTokenService _service;
- private Mock<IUserFieldService> _userFieldServiceMock;
+ private Mock<ICustomerService> _customerServiceMock;
[TestInitialize]
public void Init()
{
- _userFieldServiceMock = new Mock<IUserFieldService>();
- _service = new RefreshTokenService(_userFieldServiceMock.Object, new FrontendAPIConfig {
+ _customerServiceMock = new Mock<ICustomerService>();
+ _service = new RefreshTokenService(_customerServiceMock.Object, new FrontendAPIConfig {
SecretKey = "JWTRefreshTokenHIGHsecuredPasswordVVVp1OH7Xzyr",
ValidIssuer = "http://localhost:4200",
ValidAudience = "http://localhost:4200",
@@ -46,8 +52,8 @@ public class RefreshTokenServiceTests
public async Task SaveRefreshTokenToCustomerTest()
{
//Arrange
- _userFieldServiceMock.Setup(c =>
- c.SaveField(It.IsAny<BaseEntity>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()));
+ _customerServiceMock.Setup(c =>
+ c.UpdateUserField(It.IsAny<Customer>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()));
var token = Guid.NewGuid().ToString();
//Act
var result = await _service.SaveRefreshTokenToCustomer(new Customer(), token);
@@ -60,11 +66,15 @@ public class RefreshTokenServiceTests
public async Task GetCustomerRefreshTokenTest()
{
//Arrange
- _userFieldServiceMock.Setup(c =>
- c.GetFieldsForEntity<RefreshToken>(It.IsAny<BaseEntity>(), It.IsAny<string>(), It.IsAny<string>()))
- .Returns(Task.FromResult(new RefreshToken { Token = "123" }));
+ TypeDescriptor.AddAttributes(typeof(RefreshToken),
+ new TypeConverterAttribute(typeof(RefreshTokenTypeConverter)));
+
+ var valueStr = CommonHelper.To<string>(new RefreshToken { Token = "123" });
+ var customer = new Customer();
+ customer.UserFields.Add(new UserField() { Key = SystemCustomerFieldNames.RefreshToken, Value = valueStr, StoreId = "" });
+
//Act
- var result = await _service.GetCustomerRefreshToken(new Customer());
+ var result = await _service.GetCustomerRefreshToken(customer);
//Assert
Assert.IsNotNull(result);
Assert.AreEqual("123", result.Token);
diff --git a/src/Tests/Grand.Business.Authentication.Tests/Services/TwoFactorAuthenticationServiceTests.cs b/src/Tests/Grand.Business.Authentication.Tests/Services/TwoFactorAuthenticationServiceTests.cs
index ef7e1293a..ddd33f5c0 100644
--- a/src/Tests/Grand.Business.Authentication.Tests/Services/TwoFactorAuthenticationServiceTests.cs
+++ b/src/Tests/Grand.Business.Authentication.Tests/Services/TwoFactorAuthenticationServiceTests.cs
@@ -1,6 +1,7 @@
using Grand.Business.Authentication.Services;
using Grand.Business.Core.Interfaces.Authentication;
using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Domain.Customers;
using Grand.Domain.Localization;
using Grand.Domain.Stores;
@@ -15,17 +16,17 @@ public class TwoFactorAuthenticationServiceTests
{
private Mock<IEnumerable<ISMSVerificationService>> _sMsVerificationService;
private TwoFactorAuthenticationService _twoFactorAuthenticationService;
- private Mock<IUserFieldService> _userFieldServiceMock;
+ private Mock<ICustomerService> _customerServiceMock;
private Mock<IWorkContext> _workContextMock;
[TestInitialize]
public void Init()
{
_workContextMock = new Mock<IWorkContext>();
- _userFieldServiceMock = new Mock<IUserFieldService>();
+ _customerServiceMock = new Mock<ICustomerService>();
_sMsVerificationService = new Mock<IEnumerable<ISMSVerificationService>>();
_twoFactorAuthenticationService = new TwoFactorAuthenticationService(_workContextMock.Object,
- _userFieldServiceMock.Object, _sMsVerificationService.Object);
+ _customerServiceMock.Object, _sMsVerificationService.Object);
}
[TestMethod]
diff --git a/src/Tests/Grand.Business.Checkout.Tests/Services/Orders/ShoppingCartServiceTests.cs b/src/Tests/Grand.Business.Checkout.Tests/Services/Orders/ShoppingCartServiceTests.cs
index edd066fa8..19ef4f48f 100644
--- a/src/Tests/Grand.Business.Checkout.Tests/Services/Orders/ShoppingCartServiceTests.cs
+++ b/src/Tests/Grand.Business.Checkout.Tests/Services/Orders/ShoppingCartServiceTests.cs
@@ -27,7 +27,6 @@ public class ShoppingCartServiceTests
private ShoppingCartService _shoppingCartService;
private ShoppingCartSettings _shoppingCartSettings;
private Mock<IShoppingCartValidator> _shoppingCartValidatorMock;
- private Mock<IUserFieldService> _userFieldServiceMock;
private Mock<IWorkContext> _workContextMock;
[TestInitialize]
@@ -38,7 +37,6 @@ public class ShoppingCartServiceTests
_shoppingCartSettings = new ShoppingCartSettings();
_customerServiceMock = new Mock<ICustomerService>();
_mediatorMock = new Mock<IMediator>();
- _userFieldServiceMock = new Mock<IUserFieldService>();
_shoppingCartValidatorMock = new Mock<IShoppingCartValidator>();
_workContextMock.Setup(c => c.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
@@ -49,8 +47,7 @@ public class ShoppingCartServiceTests
_workContextMock.Setup(c => c.TaxDisplayType).Returns(() => TaxDisplayType.ExcludingTax);
_shoppingCartService = new ShoppingCartService(_workContextMock.Object, _productServiceMock.Object,
- _customerServiceMock.Object, _mediatorMock.Object, _userFieldServiceMock.Object,
- _shoppingCartValidatorMock.Object, _shoppingCartSettings);
+ _customerServiceMock.Object, _mediatorMock.Object, _shoppingCartValidatorMock.Object, _shoppingCartSettings);
}
[TestMethod]
diff --git a/src/Tests/Grand.Business.Cms.Tests/Services/CookiePreferenceTests.cs b/src/Tests/Grand.Business.Cms.Tests/Services/CookiePreferenceTests.cs
index 2fbd0c613..275a32e33 100644
--- a/src/Tests/Grand.Business.Cms.Tests/Services/CookiePreferenceTests.cs
+++ b/src/Tests/Grand.Business.Cms.Tests/Services/CookiePreferenceTests.cs
@@ -2,10 +2,14 @@
using Grand.Business.Core.Interfaces.Cms;
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Domain;
+using Grand.Domain.Common;
using Grand.Domain.Customers;
using Grand.Domain.Stores;
+using Grand.Infrastructure.TypeConverters.Converter;
+using Grand.SharedKernel.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using System.ComponentModel;
namespace Grand.Business.Cms.Tests.Services;
@@ -13,7 +17,6 @@ namespace Grand.Business.Cms.Tests.Services;
public class CookiePreferenceTests
{
private CookiePreference _cookiePreferences;
- private Mock<IUserFieldService> _userFieldServiceMock;
[TestInitialize]
public void Init()
@@ -25,9 +28,7 @@ public class CookiePreferenceTests
cookie2.Setup(c => c.DisplayOrder).Returns(2);
cookie2.Setup(c => c.SystemName).Returns("cookie2");
- _userFieldServiceMock = new Mock<IUserFieldService>();
- _cookiePreferences = new CookiePreference(_userFieldServiceMock.Object,
- new List<IConsentCookie> { cookie1.Object, cookie2.Object });
+ _cookiePreferences = new CookiePreference(new List<IConsentCookie> { cookie1.Object, cookie2.Object });
}
[TestMethod]
@@ -44,13 +45,16 @@ public class CookiePreferenceTests
var dic = new Dictionary<string, bool>();
dic.Add("cookie1", true);
dic.Add("cookie2", false);
- _userFieldServiceMock.Setup(c =>
- c.GetFieldsForEntity<Dictionary<string, bool>>(It.IsAny<BaseEntity>(), It.IsAny<string>(),
- It.IsAny<string>()))
- .Returns(Task.FromResult(dic));
- var result1 = await _cookiePreferences.IsEnable(new Customer(), new Store(), "cookie1");
- var result2 = await _cookiePreferences.IsEnable(new Customer(), new Store(), "cookie2");
+ TypeDescriptor.AddAttributes(typeof(Dictionary<string, bool>),
+ new TypeConverterAttribute(typeof(GenericDictionaryTypeConverter<string, bool>)));
+
+ var store = new Store();
+ var valueStr = CommonHelper.To<string>(dic);
+ var customer = new Customer();
+ customer.UserFields.Add(new UserField(){ StoreId = store.Id, Key = SystemCustomerFieldNames.ConsentCookies, Value = valueStr});
+ var result1 = await _cookiePreferences.IsEnable(customer, store, "cookie1");
+ var result2 = await _cookiePreferences.IsEnable(customer, store, "cookie2");
Assert.IsTrue(result1.Value);
Assert.IsFalse(result2.Value);
}
diff --git a/src/Tests/Grand.Business.Common.Tests/Services/Directory/UserFieldServiceTests.cs b/src/Tests/Grand.Business.Common.Tests/Services/Directory/UserFieldServiceTests.cs
deleted file mode 100644
index 7795d28d3..000000000
--- a/src/Tests/Grand.Business.Common.Tests/Services/Directory/UserFieldServiceTests.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-using Grand.Business.Common.Services.Directory;
-using Grand.Data;
-using Grand.Data.Tests.MongoDb;
-using Grand.Domain.Common;
-using Grand.Domain.Customers;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using MongoDB.Bson.Serialization.Conventions;
-
-namespace Grand.Business.Common.Tests.Services.Directory;
-
-[TestClass]
-public class UserFieldServiceTests
-{
- private IRepository<UserFieldBaseEntity> _repository;
- private IRepository<Customer> _repositoryCustomer;
- private UserFieldService _userFieldService;
-
- [TestInitialize]
- public void Init()
- {
- //global set an equivalent of [BsonIgnoreExtraElements] for every Domain Model
- var cp = new ConventionPack {
- new IgnoreExtraElementsConvention(true)
- };
- ConventionRegistry.Register("ApplicationConventions", cp, t => true);
-
- _repository = new MongoDBRepositoryTest<UserFieldBaseEntity>();
- _repositoryCustomer = new MongoDBRepositoryTest<Customer>();
- _userFieldService = new UserFieldService(_repository);
- }
-
- [TestMethod]
- public async Task SaveFieldTest_Insert()
- {
- //Arrange
- var customer = new Customer();
- _repositoryCustomer.Insert(customer);
- //Act
- await _userFieldService.SaveField(customer, "Field", "Value");
- //Assert
- var userFields = _repositoryCustomer.Table.FirstOrDefault(x => x.Id == customer.Id).UserFields;
- Assert.IsNotNull(userFields.FirstOrDefault(x => x.Key == "Field"));
- }
-
- [TestMethod]
- public async Task SaveFieldTest_Update()
- {
- //Arrange
- var customer = new Customer();
- customer.UserFields.Add(new UserField { Key = "Field", Value = "empty", StoreId = "" });
- _repositoryCustomer.Insert(customer);
- //Act
- await _userFieldService.SaveField(customer, "Field", "Value");
- //Assert
- var userFields = _repositoryCustomer.Table.FirstOrDefault(x => x.Id == customer.Id).UserFields;
- Assert.IsNotNull(userFields.FirstOrDefault(x => x.Key == "Field"));
- Assert.AreEqual("Value", userFields.FirstOrDefault(x => x.Key == "Field").Value);
- }
-
- [TestMethod]
- public async Task SaveFieldTest_Delete()
- {
- //Arrange
- var customer = new Customer();
- customer.UserFields.Add(new UserField { Key = "Field", Value = "Value", StoreId = "" });
- _repositoryCustomer.Insert(customer);
- //Act
- await _userFieldService.SaveField(customer, "Field", string.Empty);
- //Assert
- var userFields = _repositoryCustomer.Table.FirstOrDefault(x => x.Id == customer.Id).UserFields;
- Assert.IsNull(userFields.FirstOrDefault(x => x.Key == "Field"));
- }
-}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Customers.Tests/Services/CustomerManagerServiceTests.cs b/src/Tests/Grand.Business.Customers.Tests/Services/CustomerManagerServiceTests.cs
index 58ddc91e2..e23dd06be 100644
--- a/src/Tests/Grand.Business.Customers.Tests/Services/CustomerManagerServiceTests.cs
+++ b/src/Tests/Grand.Business.Customers.Tests/Services/CustomerManagerServiceTests.cs
@@ -22,8 +22,6 @@ public class CustomerManagerServiceTests
private Mock<IEncryptionService> _encryptionServiceMock;
private Mock<IGroupService> _groupServiceMock;
private Mock<IMediator> _mediatorMock;
- private Mock<ITranslationService> _translationServiceMock;
- private Mock<IUserFieldService> _userFieldServiceMock;
[TestInitialize]
public void Init()
@@ -31,17 +29,14 @@ public class CustomerManagerServiceTests
_customerServiceMock = new Mock<ICustomerService>();
_groupServiceMock = new Mock<IGroupService>();
_encryptionServiceMock = new Mock<IEncryptionService>();
- _translationServiceMock = new Mock<ITranslationService>();
_mediatorMock = new Mock<IMediator>();
- _userFieldServiceMock = new Mock<IUserFieldService>();
_customerHistoryPasswordServiceMock = new Mock<ICustomerHistoryPasswordService>();
_customerSettings = new CustomerSettings {
AllowUsersToChangeUsernames = true
};
_customerManagerService = new CustomerManagerService(_customerServiceMock.Object, _groupServiceMock.Object,
- _encryptionServiceMock.Object, _mediatorMock.Object, _userFieldServiceMock.Object,
- _customerHistoryPasswordServiceMock.Object, _customerSettings);
+ _encryptionServiceMock.Object, _mediatorMock.Object, _customerHistoryPasswordServiceMock.Object, _customerSettings);
}
[TestMethod]
diff --git a/src/Tests/Grand.Business.Customers.Tests/Services/CustomerServiceTests.cs b/src/Tests/Grand.Business.Customers.Tests/Services/CustomerServiceTests.cs
index c3ebeebe6..e53ca4030 100644
--- a/src/Tests/Grand.Business.Customers.Tests/Services/CustomerServiceTests.cs
+++ b/src/Tests/Grand.Business.Customers.Tests/Services/CustomerServiceTests.cs
@@ -23,18 +23,16 @@ public class CustomerServiceTests
private CustomerService _customerService;
private Mock<IMediator> _mediatorMock;
private IRepository<Customer> _repository;
- private IUserFieldService _userFieldService;
[TestInitialize]
public void TestInitialize()
{
_repository = new MongoDBRepositoryTest<Customer>();
_mediatorMock = new Mock<IMediator>();
- _userFieldService = new UserFieldService(new MongoDBRepositoryTest<UserFieldBaseEntity>());
_cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object,
new CacheConfig { DefaultCacheTimeMinutes = 1 });
- _customerService = new CustomerService(_repository, _userFieldService, _mediatorMock.Object, _cacheBase);
+ _customerService = new CustomerService(_repository, _mediatorMock.Object, _cacheBase);
}
@@ -206,7 +204,47 @@ public class CustomerServiceTests
//Assert
Assert.AreEqual("[email protected]", _repository.Table.FirstOrDefault(x => x.Id == customer.Id).Email);
}
+ [TestMethod]
+ public async Task SaveFieldTest_Insert()
+ {
+ //Arrange
+ var customer = new Customer();
+ _repository.Insert(customer);
+ //Act
+ await _customerService.UpdateUserField(customer, "Field", "Value");
+ //Assert
+ var userFields = _repository.Table.FirstOrDefault(x => x.Id == customer.Id).UserFields;
+ Assert.IsNotNull(userFields.FirstOrDefault(x => x.Key == "Field"));
+ }
+
+ [TestMethod]
+ public async Task SaveFieldTest_Update()
+ {
+ //Arrange
+ var customer = new Customer();
+ customer.UserFields.Add(new UserField { Key = "Field", Value = "empty", StoreId = "" });
+ _repository.Insert(customer);
+ //Act
+ await _customerService.UpdateUserField(customer, "Field", "Value");
+ //Assert
+ var userFields = _repository.Table.FirstOrDefault(x => x.Id == customer.Id).UserFields;
+ Assert.IsNotNull(userFields.FirstOrDefault(x => x.Key == "Field"));
+ Assert.AreEqual("Value", userFields.FirstOrDefault(x => x.Key == "Field").Value);
+ }
+ [TestMethod]
+ public async Task SaveFieldTest_Delete()
+ {
+ //Arrange
+ var customer = new Customer();
+ customer.UserFields.Add(new UserField { Key = "Field", Value = "Value", StoreId = "" });
+ _repository.Insert(customer);
+ //Act
+ await _customerService.UpdateUserField(customer, "Field", string.Empty);
+ //Assert
+ var userFields = _repository.Table.FirstOrDefault(x => x.Id == customer.Id).UserFields;
+ Assert.IsNull(userFields.FirstOrDefault(x => x.Key == "Field"));
+ }
[TestMethod]
public async Task DeleteCustomerTest()
{
diff --git a/src/Tests/Grand.Business.Storage.Tests/Services/DefaultMediaFileStoreTests.cs b/src/Tests/Grand.Business.Storage.Tests/Services/DefaultMediaFileStoreTests.cs
index 955899aa4..1f65055a0 100644
--- a/src/Tests/Grand.Business.Storage.Tests/Services/DefaultMediaFileStoreTests.cs
+++ b/src/Tests/Grand.Business.Storage.Tests/Services/DefaultMediaFileStoreTests.cs
@@ -62,9 +62,12 @@ public class DefaultMediaFileStoreTests
[TestMethod]
public void TryCreateDirectoryTest()
{
+ var directory = "Test";
//Act
- var result = _defaultMediaFileStore.TryCreateDirectory("Test");
+ var result = _defaultMediaFileStore.TryCreateDirectory(directory);
+ _ = _defaultMediaFileStore.TryDeleteDirectory(directory);
//Assert
+
Assert.IsTrue(result);
}
diff --git a/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs b/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs
index b15a7f3ce..5885919ac 100644
--- a/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs
@@ -39,7 +39,6 @@ public class CustomerController : BaseAdminController
IProductReviewViewModelService productReviewViewModelService,
IProductViewModelService productViewModelService,
ICustomerViewModelService customerViewModelService,
- IUserFieldService userFieldService,
ICustomerManagerService customerManagerService,
ITranslationService translationService,
IWorkContext workContext,
@@ -58,7 +57,6 @@ public class CustomerController : BaseAdminController
_productReviewViewModelService = productReviewViewModelService;
_productViewModelService = productViewModelService;
_customerViewModelService = customerViewModelService;
- _userFieldService = userFieldService;
_customerManagerService = customerManagerService;
_translationService = translationService;
_workContext = workContext;
@@ -192,7 +190,6 @@ public class CustomerController : BaseAdminController
private readonly IProductReviewViewModelService _productReviewViewModelService;
private readonly IProductViewModelService _productViewModelService;
private readonly ICustomerViewModelService _customerViewModelService;
- private readonly IUserFieldService _userFieldService;
private readonly ICustomerManagerService _customerManagerService;
private readonly ITranslationService _translationService;
private readonly IWorkContext _workContext;
@@ -344,7 +341,7 @@ public class CustomerController : BaseAdminController
//No customer found with the specified id
return RedirectToAction("List");
- await _userFieldService.SaveField(customer,
+ await _customerService.UpdateUserField(customer,
SystemCustomerFieldNames.VatNumberStatusId,
(int)VatNumberStatus.Valid);
@@ -360,7 +357,7 @@ public class CustomerController : BaseAdminController
//No customer found with the specified id
return RedirectToAction("List");
- await _userFieldService.SaveField(customer,
+ await _customerService.UpdateUserField(customer,
SystemCustomerFieldNames.VatNumberStatusId,
(int)VatNumberStatus.Invalid);
@@ -444,7 +441,7 @@ public class CustomerController : BaseAdminController
return RedirectToAction("Edit", customer.Id);
}
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.ImpersonatedCustomerId, customer.Id);
return RedirectToAction("Index", "Home", new { area = "" });
@@ -477,7 +474,7 @@ public class CustomerController : BaseAdminController
return RedirectToAction("List");
//email validation message
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.AccountActivationToken,
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.AccountActivationToken,
Guid.NewGuid().ToString());
await _messageProviderService.SendCustomerEmailValidationMessage(customer, _workContext.CurrentStore,
_workContext.WorkingLanguage.Id);
diff --git a/src/Web/Grand.Web.Admin/Controllers/HomeController.cs b/src/Web/Grand.Web.Admin/Controllers/HomeController.cs
index 672802f7c..1d4bcf81f 100644
--- a/src/Web/Grand.Web.Admin/Controllers/HomeController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/HomeController.cs
@@ -2,6 +2,7 @@
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Interfaces.System.Reports;
using Grand.Business.Core.Queries.Checkout.Orders;
using Grand.Business.Core.Queries.Customers;
@@ -23,7 +24,7 @@ public class HomeController : BaseAdminController
public HomeController(
ITranslationService translationService,
IStoreService storeService,
- IUserFieldService userFieldService,
+ ICustomerService customerService,
IWorkContext workContext,
IGroupService groupService,
IOrderReportService orderReportService,
@@ -34,7 +35,7 @@ public class HomeController : BaseAdminController
{
_translationService = translationService;
_storeService = storeService;
- _userFieldService = userFieldService;
+ _customerService = customerService;
_workContext = workContext;
_groupService = groupService;
_orderReportService = orderReportService;
@@ -84,7 +85,7 @@ public class HomeController : BaseAdminController
private readonly ITranslationService _translationService;
private readonly IStoreService _storeService;
- private readonly IUserFieldService _userFieldService;
+ private readonly ICustomerService _customerService;
private readonly IWorkContext _workContext;
private readonly IGroupService _groupService;
private readonly IOrderReportService _orderReportService;
@@ -115,11 +116,12 @@ public class HomeController : BaseAdminController
public async Task<IActionResult> SetLanguage(string langid,
[FromServices] ILanguageService languageService,
+ [FromServices] ICustomerService _customerService,
string returnUrl = "")
{
var language = await languageService.GetLanguageById(langid);
if (language != null)
- await _userFieldService.SaveField(_workContext.CurrentCustomer, SystemCustomerFieldNames.LanguageId,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer, SystemCustomerFieldNames.LanguageId,
language.Id, _workContext.CurrentStore.Id);
//home page
@@ -141,10 +143,10 @@ public class HomeController : BaseAdminController
var store = await _storeService.GetStoreById(storeid);
if (store != null || storeid == "")
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration, storeid);
else
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration, "");
//home page
diff --git a/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs b/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
index 91c31cb81..2d5035c7a 100644
--- a/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
@@ -67,7 +67,6 @@ public class CustomerViewModelService : ICustomerViewModelService
private readonly TaxSettings _taxSettings;
private readonly ITranslationService _translationService;
- private readonly IUserFieldService _userFieldService;
private readonly IVendorService _vendorService;
private readonly IWorkContext _workContext;
@@ -76,7 +75,6 @@ public class CustomerViewModelService : ICustomerViewModelService
IGroupService groupService,
ICustomerProductService customerProductService,
INewsLetterSubscriptionService newsLetterSubscriptionService,
- IUserFieldService userFieldService,
IDateTimeService dateTimeService,
ITranslationService translationService,
ILoyaltyPointsService loyaltyPointsService,
@@ -105,7 +103,6 @@ public class CustomerViewModelService : ICustomerViewModelService
_groupService = groupService;
_customerProductService = customerProductService;
_newsLetterSubscriptionService = newsLetterSubscriptionService;
- _userFieldService = userFieldService;
_dateTimeService = dateTimeService;
_translationService = translationService;
_loyaltyPointsService = loyaltyPointsService;
@@ -492,7 +489,7 @@ public class CustomerViewModelService : ICustomerViewModelService
customer.Attributes = model.Attributes;
if (!model.TwoFactorEnabled)
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.TwoFactorEnabled,
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.TwoFactorEnabled,
model.TwoFactorEnabled);
customer.Email = model.Email;
@@ -516,10 +513,9 @@ public class CustomerViewModelService : ICustomerViewModelService
//VAT number
if (_taxSettings.EuVatEnabled)
{
- var prevVatNumber =
- await customer.GetUserField<string>(_userFieldService, SystemCustomerFieldNames.VatNumber);
+ var prevVatNumber = customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.VatNumber);
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.VatNumber, model.VatNumber);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.VatNumber, model.VatNumber);
//set VAT number status
if (!string.IsNullOrEmpty(model.VatNumber))
{
@@ -527,14 +523,14 @@ public class CustomerViewModelService : ICustomerViewModelService
{
var checkVatService =
_httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IVatService>();
- await _userFieldService.SaveField(customer,
+ await _customerService.UpdateUserField(customer,
SystemCustomerFieldNames.VatNumberStatusId,
(int)(await checkVatService.GetVatNumberStatus(model.VatNumber)).status);
}
}
else
{
- await _userFieldService.SaveField(customer,
+ await _customerService.UpdateUserField(customer,
SystemCustomerFieldNames.VatNumberStatusId,
(int)VatNumberStatus.Empty);
}
@@ -551,30 +547,30 @@ public class CustomerViewModelService : ICustomerViewModelService
//user fields
if (_customerSettings.GenderEnabled)
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.Gender, model.Gender);
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.FirstName, model.FirstName);
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.LastName, model.LastName);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.Gender, model.Gender);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.FirstName, model.FirstName);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.LastName, model.LastName);
if (_customerSettings.DateOfBirthEnabled)
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.DateOfBirth, model.DateOfBirth);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.DateOfBirth, model.DateOfBirth);
if (_customerSettings.CompanyEnabled)
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.Company, model.Company);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.Company, model.Company);
if (_customerSettings.StreetAddressEnabled)
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.StreetAddress, model.StreetAddress);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.StreetAddress, model.StreetAddress);
if (_customerSettings.StreetAddress2Enabled)
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.StreetAddress2, model.StreetAddress2);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.StreetAddress2, model.StreetAddress2);
if (_customerSettings.ZipPostalCodeEnabled)
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.ZipPostalCode, model.ZipPostalCode);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.ZipPostalCode, model.ZipPostalCode);
if (_customerSettings.CityEnabled)
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.City, model.City);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.City, model.City);
if (_customerSettings.CountryEnabled)
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.CountryId, model.CountryId);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.CountryId, model.CountryId);
if (_customerSettings.CountryEnabled && _customerSettings.StateProvinceEnabled)
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.StateProvinceId,
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.StateProvinceId,
model.StateProvinceId);
if (_customerSettings.PhoneEnabled)
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.Phone, model.Phone);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.Phone, model.Phone);
if (_customerSettings.FaxEnabled)
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.Fax, model.Fax);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.Fax, model.Fax);
//newsletter subscriptions
if (!string.IsNullOrEmpty(customer.Email))
diff --git a/src/Web/Grand.Web/App_Data/appsettings.json b/src/Web/Grand.Web/App_Data/appsettings.json
index 6d0a0c45e..95c709df4 100644
--- a/src/Web/Grand.Web/App_Data/appsettings.json
+++ b/src/Web/Grand.Web/App_Data/appsettings.json
@@ -69,7 +69,7 @@
"UseHsts": false,
//When enabled, allow Razor files to be updated if they're edited.
- "EnableRuntimeCompilation": true,
+ "EnableRuntimeCompilation": false,
//We recommend all ASP.NET Core web apps call HTTPS Redirection Middleware to redirect all HTTP requests to HTTPS
"UseHttpsRedirection": false,
diff --git a/src/Web/Grand.Web/Commands/Handler/Customers/CustomerRegisteredCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/Customers/CustomerRegisteredCommandHandler.cs
index 2847dea2a..93ab6dd4e 100644
--- a/src/Web/Grand.Web/Commands/Handler/Customers/CustomerRegisteredCommandHandler.cs
+++ b/src/Web/Grand.Web/Commands/Handler/Customers/CustomerRegisteredCommandHandler.cs
@@ -27,10 +27,8 @@ public class CustomerRegisteredCommandHandler : IRequestHandler<CustomerRegister
private readonly INewsLetterSubscriptionService _newsLetterSubscriptionService;
private readonly TaxSettings _taxSettings;
- private readonly IUserFieldService _userFieldService;
public CustomerRegisteredCommandHandler(
- IUserFieldService userFieldService,
IVatService checkVatService,
IMessageProviderService messageProviderService,
INewsLetterSubscriptionService newsLetterSubscriptionService,
@@ -42,7 +40,6 @@ public class CustomerRegisteredCommandHandler : IRequestHandler<CustomerRegister
AddressSettings addressSettings,
LanguageSettings languageSettings)
{
- _userFieldService = userFieldService;
_checkVatService = checkVatService;
_messageProviderService = messageProviderService;
_newsLetterSubscriptionService = newsLetterSubscriptionService;
@@ -60,55 +57,55 @@ public class CustomerRegisteredCommandHandler : IRequestHandler<CustomerRegister
//VAT number
if (_taxSettings.EuVatEnabled)
{
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.VatNumber,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.VatNumber,
request.Model.VatNumber);
var vat = await _checkVatService.GetVatNumberStatus(request.Model.VatNumber);
- await _userFieldService.SaveField(request.Customer,
+ await _customerService.UpdateUserField(request.Customer,
SystemCustomerFieldNames.VatNumberStatusId,
(int)vat.status);
}
//form fields
if (_customerSettings.GenderEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Gender,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.Gender,
request.Model.Gender);
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.FirstName,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.FirstName,
request.Model.FirstName);
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.LastName,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.LastName,
request.Model.LastName);
if (_customerSettings.DateOfBirthEnabled)
{
var dateOfBirth = request.Model.ParseDateOfBirth();
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.DateOfBirth, dateOfBirth);
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.DateOfBirth, dateOfBirth);
}
if (_customerSettings.CompanyEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Company,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.Company,
request.Model.Company);
if (_customerSettings.StreetAddressEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.StreetAddress,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.StreetAddress,
request.Model.StreetAddress);
if (_customerSettings.StreetAddress2Enabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.StreetAddress2,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.StreetAddress2,
request.Model.StreetAddress2);
if (_customerSettings.ZipPostalCodeEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.ZipPostalCode,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.ZipPostalCode,
request.Model.ZipPostalCode);
if (_customerSettings.CityEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.City, request.Model.City);
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.City, request.Model.City);
if (_customerSettings.CountryEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.CountryId,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.CountryId,
request.Model.CountryId);
if (_customerSettings.CountryEnabled && _customerSettings.StateProvinceEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.StateProvinceId,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.StateProvinceId,
request.Model.StateProvinceId);
if (_customerSettings.PhoneEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Phone,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.Phone,
request.Model.Phone);
if (_customerSettings.FaxEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Fax, request.Model.Fax);
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.Fax, request.Model.Fax);
//newsletter
if (_customerSettings.NewsletterEnabled)
diff --git a/src/Web/Grand.Web/Commands/Handler/Customers/PasswordRecoverySendCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/Customers/PasswordRecoverySendCommandHandler.cs
index 517f8f39a..82936a151 100644
--- a/src/Web/Grand.Web/Commands/Handler/Customers/PasswordRecoverySendCommandHandler.cs
+++ b/src/Web/Grand.Web/Commands/Handler/Customers/PasswordRecoverySendCommandHandler.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Interfaces.Messages;
using Grand.Domain.Customers;
using Grand.Web.Commands.Models.Customers;
@@ -9,13 +9,13 @@ namespace Grand.Web.Commands.Handler.Customers;
public class PasswordRecoverySendCommandHandler : IRequestHandler<PasswordRecoverySendCommand, bool>
{
private readonly IMessageProviderService _messageProviderService;
- private readonly IUserFieldService _userFieldService;
+ private readonly ICustomerService _customerService;
public PasswordRecoverySendCommandHandler(
- IUserFieldService userFieldService,
+ ICustomerService customerService,
IMessageProviderService messageProviderService)
{
- _userFieldService = userFieldService;
+ _customerService = customerService;
_messageProviderService = messageProviderService;
}
@@ -23,10 +23,10 @@ public class PasswordRecoverySendCommandHandler : IRequestHandler<PasswordRecove
{
//save token and current date
var passwordRecoveryToken = Guid.NewGuid();
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.PasswordRecoveryToken,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.PasswordRecoveryToken,
passwordRecoveryToken.ToString());
DateTime? generatedDateTime = DateTime.UtcNow;
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.PasswordRecoveryTokenDateGenerated,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.PasswordRecoveryTokenDateGenerated,
generatedDateTime);
//send email
diff --git a/src/Web/Grand.Web/Commands/Handler/Customers/SubAccountAddCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/Customers/SubAccountAddCommandHandler.cs
index c8c0536b4..970f0a0a8 100644
--- a/src/Web/Grand.Web/Commands/Handler/Customers/SubAccountAddCommandHandler.cs
+++ b/src/Web/Grand.Web/Commands/Handler/Customers/SubAccountAddCommandHandler.cs
@@ -1,5 +1,4 @@
-using Grand.Business.Core.Interfaces.Common.Directory;
-using Grand.Business.Core.Interfaces.Customers;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Utilities.Customers;
using Grand.Domain.Customers;
using Grand.Web.Commands.Models.Customers;
@@ -12,17 +11,14 @@ public class SubAccountAddCommandHandler : IRequestHandler<SubAccountAddCommand>
private readonly ICustomerManagerService _customerManagerService;
private readonly ICustomerService _customerService;
private readonly CustomerSettings _customerSettings;
- private readonly IUserFieldService _userFieldService;
public SubAccountAddCommandHandler(
ICustomerService customerService,
ICustomerManagerService customerManagerService,
- IUserFieldService userFieldService,
CustomerSettings customerSettings)
{
_customerService = customerService;
_customerManagerService = customerManagerService;
- _userFieldService = userFieldService;
_customerSettings = customerSettings;
}
@@ -36,8 +32,8 @@ public class SubAccountAddCommandHandler : IRequestHandler<SubAccountAddCommand>
await _customerManagerService.RegisterCustomer(registrationRequest);
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.FirstName, request.Model.FirstName);
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.LastName, request.Model.LastName);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.FirstName, request.Model.FirstName);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.LastName, request.Model.LastName);
}
protected async Task<Customer> PrepareCustomer(SubAccountAddCommand request)
diff --git a/src/Web/Grand.Web/Commands/Handler/Customers/SubAccountEditCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/Customers/SubAccountEditCommandHandler.cs
index 1c0b69f44..0ef2f16ea 100644
--- a/src/Web/Grand.Web/Commands/Handler/Customers/SubAccountEditCommandHandler.cs
+++ b/src/Web/Grand.Web/Commands/Handler/Customers/SubAccountEditCommandHandler.cs
@@ -1,5 +1,4 @@
-using Grand.Business.Core.Interfaces.Common.Directory;
-using Grand.Business.Core.Interfaces.Customers;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Utilities.Customers;
using Grand.Domain.Customers;
using Grand.Web.Commands.Models.Customers;
@@ -12,17 +11,14 @@ public class SubAccountEditCommandHandler : IRequestHandler<SubAccountEditComman
private readonly ICustomerManagerService _customerManagerService;
private readonly ICustomerService _customerService;
private readonly CustomerSettings _customerSettings;
- private readonly IUserFieldService _userFieldService;
public SubAccountEditCommandHandler(
ICustomerService customerService,
ICustomerManagerService customerManagerService,
- IUserFieldService userFieldService,
CustomerSettings customerSettings)
{
_customerService = customerService;
_customerManagerService = customerManagerService;
- _userFieldService = userFieldService;
_customerSettings = customerSettings;
}
@@ -50,8 +46,8 @@ public class SubAccountEditCommandHandler : IRequestHandler<SubAccountEditComman
await _customerService.UpdateActive(customer);
//update attributes
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.FirstName, request.EditModel.FirstName);
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.LastName, request.EditModel.LastName);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.FirstName, request.EditModel.FirstName);
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.LastName, request.EditModel.LastName);
return true;
}
diff --git a/src/Web/Grand.Web/Commands/Handler/Customers/UpdateCustomerInfoCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/Customers/UpdateCustomerInfoCommandHandler.cs
index 1fd0d879b..6c4719b59 100644
--- a/src/Web/Grand.Web/Commands/Handler/Customers/UpdateCustomerInfoCommandHandler.cs
+++ b/src/Web/Grand.Web/Commands/Handler/Customers/UpdateCustomerInfoCommandHandler.cs
@@ -1,9 +1,8 @@
-using Grand.Business.Core.Extensions;
-using Grand.Business.Core.Interfaces.Authentication;
+using Grand.Business.Core.Interfaces.Authentication;
using Grand.Business.Core.Interfaces.Catalog.Tax;
-using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Interfaces.Marketing.Newsletters;
+using Grand.Domain.Common;
using Grand.Domain.Customers;
using Grand.Domain.Messages;
using Grand.Domain.Tax;
@@ -16,27 +15,20 @@ public class UpdateCustomerInfoCommandHandler : IRequestHandler<UpdateCustomerIn
{
private readonly IGrandAuthenticationService _authenticationService;
private readonly IVatService _checkVatService;
- private readonly ICustomerManagerService _customerManagerService;
private readonly ICustomerService _customerService;
-
- private readonly CustomerSettings _customerSettings;
private readonly INewsLetterSubscriptionService _newsLetterSubscriptionService;
+ private readonly CustomerSettings _customerSettings;
private readonly TaxSettings _taxSettings;
- private readonly IUserFieldService _userFieldService;
public UpdateCustomerInfoCommandHandler(
- ICustomerManagerService customerManagerService,
IGrandAuthenticationService authenticationService,
- IUserFieldService userFieldService,
IVatService checkVatService,
INewsLetterSubscriptionService newsLetterSubscriptionService,
ICustomerService customerService,
CustomerSettings customerSettings,
TaxSettings taxSettings)
{
- _customerManagerService = customerManagerService;
_authenticationService = authenticationService;
- _userFieldService = userFieldService;
_checkVatService = checkVatService;
_newsLetterSubscriptionService = newsLetterSubscriptionService;
_customerService = customerService;
@@ -89,16 +81,15 @@ public class UpdateCustomerInfoCommandHandler : IRequestHandler<UpdateCustomerIn
private async Task UpdateTax(UpdateCustomerInfoCommand request)
{
- var prevVatNumber =
- await request.Customer.GetUserField<string>(_userFieldService, SystemCustomerFieldNames.VatNumber);
+ var prevVatNumber = request.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.VatNumber);
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.VatNumber,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.VatNumber,
request.Model.VatNumber);
if (prevVatNumber != request.Model.VatNumber)
{
var vat = await _checkVatService.GetVatNumberStatus(request.Model.VatNumber);
- await _userFieldService.SaveField(request.Customer,
+ await _customerService.UpdateUserField(request.Customer,
SystemCustomerFieldNames.VatNumberStatusId,
(int)vat.status);
}
@@ -107,41 +98,41 @@ public class UpdateCustomerInfoCommandHandler : IRequestHandler<UpdateCustomerIn
private async Task UpdateUserFieldFields(UpdateCustomerInfoCommand request)
{
if (_customerSettings.GenderEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Gender, request.Model.Gender);
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.Gender, request.Model.Gender);
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.FirstName,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.FirstName,
request.Model.FirstName);
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.LastName, request.Model.LastName);
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.LastName, request.Model.LastName);
if (_customerSettings.DateOfBirthEnabled)
{
var dateOfBirth = request.Model.ParseDateOfBirth();
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.DateOfBirth, dateOfBirth);
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.DateOfBirth, dateOfBirth);
}
if (_customerSettings.CompanyEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Company,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.Company,
request.Model.Company);
if (_customerSettings.StreetAddressEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.StreetAddress,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.StreetAddress,
request.Model.StreetAddress);
if (_customerSettings.StreetAddress2Enabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.StreetAddress2,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.StreetAddress2,
request.Model.StreetAddress2);
if (_customerSettings.ZipPostalCodeEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.ZipPostalCode,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.ZipPostalCode,
request.Model.ZipPostalCode);
if (_customerSettings.CityEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.City, request.Model.City);
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.City, request.Model.City);
if (_customerSettings.CountryEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.CountryId,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.CountryId,
request.Model.CountryId);
if (_customerSettings.CountryEnabled && _customerSettings.StateProvinceEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.StateProvinceId,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.StateProvinceId,
request.Model.StateProvinceId);
if (_customerSettings.PhoneEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Phone, request.Model.Phone);
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.Phone, request.Model.Phone);
if (_customerSettings.FaxEnabled)
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Fax, request.Model.Fax);
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.Fax, request.Model.Fax);
}
private async Task UpdateNewsletter(UpdateCustomerInfoCommand request)
diff --git a/src/Web/Grand.Web/Commands/Handler/ShoppingCart/SaveCheckoutAttributesCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/ShoppingCart/SaveCheckoutAttributesCommandHandler.cs
index 153c5306d..18dff48fa 100644
--- a/src/Web/Grand.Web/Commands/Handler/ShoppingCart/SaveCheckoutAttributesCommandHandler.cs
+++ b/src/Web/Grand.Web/Commands/Handler/ShoppingCart/SaveCheckoutAttributesCommandHandler.cs
@@ -1,5 +1,6 @@
using Grand.Business.Core.Interfaces.Checkout.CheckoutAttributes;
using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Interfaces.Storage;
using Grand.Domain.Catalog;
using Grand.Domain.Common;
@@ -16,18 +17,18 @@ public class
private readonly ICheckoutAttributeParser _checkoutAttributeParser;
private readonly ICheckoutAttributeService _checkoutAttributeService;
private readonly IDownloadService _downloadService;
- private readonly IUserFieldService _userFieldService;
+ private readonly ICustomerService _customerService;
public SaveCheckoutAttributesCommandHandler(
ICheckoutAttributeService checkoutAttributeService,
ICheckoutAttributeParser checkoutAttributeParser,
IDownloadService downloadService,
- IUserFieldService userFieldService)
+ ICustomerService customerService)
{
_checkoutAttributeService = checkoutAttributeService;
_checkoutAttributeParser = checkoutAttributeParser;
_downloadService = downloadService;
- _userFieldService = userFieldService;
+ _customerService = customerService;
}
public async Task<IList<CustomAttribute>> Handle(SaveCheckoutAttributesCommand request,
@@ -114,7 +115,7 @@ public class
.ToList();
}
- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.CheckoutAttributes,
+ await _customerService.UpdateUserField(request.Customer, SystemCustomerFieldNames.CheckoutAttributes,
customAttributes, request.Store.Id);
return customAttributes;
diff --git a/src/Web/Grand.Web/Controllers/AccountController.cs b/src/Web/Grand.Web/Controllers/AccountController.cs
index 8f024ae9c..0866bb187 100644
--- a/src/Web/Grand.Web/Controllers/AccountController.cs
+++ b/src/Web/Grand.Web/Controllers/AccountController.cs
@@ -1,5 +1,4 @@
using Grand.Business.Core.Events.Customers;
-using Grand.Business.Core.Extensions;
using Grand.Business.Core.Interfaces.Authentication;
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
@@ -39,7 +38,6 @@ public class AccountController : BasePublicController
IWorkContext workContext,
ICustomerService customerService,
IGroupService groupService,
- IUserFieldService userFieldService,
ICustomerManagerService customerManagerService,
ICountryService countryService,
IMediator mediator,
@@ -52,7 +50,6 @@ public class AccountController : BasePublicController
_workContext = workContext;
_customerService = customerService;
_groupService = groupService;
- _userFieldService = userFieldService;
_customerManagerService = customerManagerService;
_customerSettings = customerSettings;
_countryService = countryService;
@@ -157,7 +154,6 @@ public class AccountController : BasePublicController
private readonly IWorkContext _workContext;
private readonly ICustomerService _customerService;
private readonly IGroupService _groupService;
- private readonly IUserFieldService _userFieldService;
private readonly ICustomerManagerService _customerManagerService;
private readonly ICountryService _countryService;
private readonly IMediator _mediator;
@@ -323,7 +319,7 @@ public class AccountController : BasePublicController
if (_workContext.OriginalCustomerIfImpersonated != null)
{
//logout impersonated customer
- await _userFieldService.SaveField<int?>(_workContext.OriginalCustomerIfImpersonated,
+ await _customerService.UpdateUserField<int?>(_workContext.OriginalCustomerIfImpersonated,
SystemCustomerFieldNames.ImpersonatedCustomerId, null);
//redirect back to customer details page (admin area)
@@ -404,7 +400,7 @@ public class AccountController : BasePublicController
await _customerManagerService.ChangePassword(new ChangePasswordRequest(model.Email,
_customerSettings.DefaultPasswordFormat, model.NewPassword));
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.PasswordRecoveryToken, "");
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.PasswordRecoveryToken, "");
model.DisablePasswordChanging = true;
model.Result = _translationService.GetResource("Account.PasswordRecovery.PasswordHasBeenChanged");
@@ -483,7 +479,7 @@ public class AccountController : BasePublicController
case UserRegistrationType.EmailValidation:
{
//email validation message
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.AccountActivationToken, Guid.NewGuid().ToString());
await _messageProviderService.SendCustomerEmailValidationMessage(
_workContext.CurrentCustomer, _workContext.CurrentStore,
@@ -598,8 +594,7 @@ public class AccountController : BasePublicController
if (customer == null)
return RedirectToRoute("HomePage");
- var activationToken =
- await customer.GetUserField<string>(_userFieldService, SystemCustomerFieldNames.AccountActivationToken);
+ var activationToken = customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.AccountActivationToken);
if (string.IsNullOrEmpty(activationToken))
return RedirectToRoute("HomePage");
@@ -610,7 +605,7 @@ public class AccountController : BasePublicController
customer.Active = true;
customer.StoreId = _workContext.CurrentStore.Id;
await _customerService.UpdateActive(customer);
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.AccountActivationToken, "");
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.AccountActivationToken, "");
//send welcome message
await _messageProviderService.SendCustomerWelcomeMessage(customer, _workContext.CurrentStore,
@@ -1028,9 +1023,9 @@ public class AccountController : BasePublicController
if (await twoFactorAuthenticationService.AuthenticateTwoFactor(model.SecretKey, model.Code,
_workContext.CurrentCustomer, _customerSettings.TwoFactorAuthenticationType))
{
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.TwoFactorEnabled, true);
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.TwoFactorSecretKey, model.SecretKey);
Success(_translationService.GetResource("Account.TwoFactorAuth.Enabled"));
@@ -1094,9 +1089,9 @@ public class AccountController : BasePublicController
if (await twoFactorAuthenticationService.AuthenticateTwoFactor(secretKey, model.Code,
_workContext.CurrentCustomer, _customerSettings.TwoFactorAuthenticationType))
{
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.TwoFactorEnabled, false);
- await _userFieldService.SaveField<string>(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField<string>(_workContext.CurrentCustomer,
SystemCustomerFieldNames.TwoFactorSecretKey, null);
Success(_translationService.GetResource("Account.TwoFactorAuth.Disabled"));
diff --git a/src/Web/Grand.Web/Controllers/CatalogController.cs b/src/Web/Grand.Web/Controllers/CatalogController.cs
index 7da800004..175deed7c 100644
--- a/src/Web/Grand.Web/Controllers/CatalogController.cs
+++ b/src/Web/Grand.Web/Controllers/CatalogController.cs
@@ -36,7 +36,6 @@ public class CatalogController : BasePublicController
IWorkContext workContext,
IGroupService groupService,
ITranslationService translationService,
- IUserFieldService userFieldService,
IAclService aclService,
IPermissionService permissionService,
IMediator mediator,
@@ -49,7 +48,6 @@ public class CatalogController : BasePublicController
_workContext = workContext;
_groupService = groupService;
_translationService = translationService;
- _userFieldService = userFieldService;
_aclService = aclService;
_permissionService = permissionService;
_mediator = mediator;
@@ -67,7 +65,6 @@ public class CatalogController : BasePublicController
private readonly IWorkContext _workContext;
private readonly IGroupService _groupService;
private readonly ITranslationService _translationService;
- private readonly IUserFieldService _userFieldService;
private readonly IAclService _aclService;
private readonly IPermissionService _permissionService;
private readonly IMediator _mediator;
diff --git a/src/Web/Grand.Web/Controllers/CheckoutController.cs b/src/Web/Grand.Web/Controllers/CheckoutController.cs
index c287990c4..8d0ca564d 100644
--- a/src/Web/Grand.Web/Controllers/CheckoutController.cs
+++ b/src/Web/Grand.Web/Controllers/CheckoutController.cs
@@ -40,7 +40,6 @@ public class CheckoutController : BasePublicController
ICustomerService customerService,
IGroupService groupService,
IShoppingCartService shoppingCartService,
- IUserFieldService userFieldService,
IShippingService shippingService,
IPickupPointService pickupPointService,
IPaymentService paymentService,
@@ -61,7 +60,6 @@ public class CheckoutController : BasePublicController
_customerService = customerService;
_groupService = groupService;
_shoppingCartService = shoppingCartService;
- _userFieldService = userFieldService;
_shippingService = shippingService;
_pickupPointService = pickupPointService;
_paymentService = paymentService;
@@ -98,9 +96,7 @@ public class CheckoutController : BasePublicController
await _customerService.ResetCheckoutData(customer, _workContext.CurrentStore.Id);
//validation (cart)
- var checkoutAttributes = await customer.GetUserField<List<CustomAttribute>>(_userFieldService,
- SystemCustomerFieldNames.CheckoutAttributes,
- _workContext.CurrentStore.Id);
+ var checkoutAttributes = customer.GetUserFieldFromEntity<List<CustomAttribute>>(SystemCustomerFieldNames.CheckoutAttributes, _workContext.CurrentStore.Id);
var scWarnings = await _shoppingCartValidator.GetShoppingCartWarnings(cart, checkoutAttributes, true, true);
if (scWarnings.Any())
return RedirectToRoute("ShoppingCart", new { checkoutAttributes = true });
@@ -253,7 +249,7 @@ public class CheckoutController : BasePublicController
await _customerService.UpdateCustomerField(_workContext.CurrentCustomer, x => x.ShippingAddress,
null);
- await _userFieldService.SaveField<ShippingOption>(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField<ShippingOption>(_workContext.CurrentCustomer,
SystemCustomerFieldNames.SelectedShippingOption, null, _workContext.CurrentStore.Id);
//load next step
return await LoadStepAfterShippingMethod(cart);
@@ -293,9 +289,9 @@ public class CheckoutController : BasePublicController
null);
//clear shipping option XML/Description
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.ShippingOptionAttribute, "", _workContext.CurrentStore.Id);
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.ShippingOptionAttributeDescription, "",
_workContext.CurrentStore.Id);
@@ -314,12 +310,12 @@ public class CheckoutController : BasePublicController
ShippingRateProviderSystemName = $"PickupPoint_{selectedPoint.Id}"
};
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.SelectedShippingOption,
pickUpInStoreShippingOption,
_workContext.CurrentStore.Id);
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.SelectedPickupPoint,
selectedPoint.Id,
_workContext.CurrentStore.Id);
@@ -327,7 +323,7 @@ public class CheckoutController : BasePublicController
else
//set value indicating that "pick up in store" option has not been chosen
{
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.SelectedPickupPoint, "", _workContext.CurrentStore.Id);
}
}
@@ -409,7 +405,7 @@ public class CheckoutController : BasePublicController
_workContext.CurrentCustomer.BillingAddress = _workContext.CurrentCustomer.ShippingAddress;
await _customerService.UpdateBillingAddress(_workContext.CurrentCustomer.BillingAddress,
_workContext.CurrentCustomer.Id);
- await _userFieldService.SaveField<ShippingOption>(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField<ShippingOption>(_workContext.CurrentCustomer,
SystemCustomerFieldNames.SelectedShippingOption, null, _workContext.CurrentStore.Id);
return await LoadStepAfterBillingAddress(cart);
}
@@ -469,9 +465,9 @@ public class CheckoutController : BasePublicController
var shippingRateProviderSystemName = splitOption[1];
//clear shipping option XML/Description
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.ShippingOptionAttribute, "",
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.ShippingOptionAttribute, "",
store.Id);
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.ShippingOptionAttributeDescription,
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.ShippingOptionAttributeDescription,
"", store.Id);
//validate customer's input
@@ -479,8 +475,7 @@ public class CheckoutController : BasePublicController
//find it
//performance optimization. try cache first
- var shippingOptions = await customer.GetUserField<List<ShippingOption>>(_userFieldService,
- SystemCustomerFieldNames.OfferedShippingOptions, store.Id);
+ var shippingOptions = customer.GetUserFieldFromEntity<List<ShippingOption>>(SystemCustomerFieldNames.OfferedShippingOptions, store.Id);
if (shippingOptions == null || shippingOptions.Count == 0)
//not found? load them using shipping service
shippingOptions = (await _shippingService
@@ -502,7 +497,7 @@ public class CheckoutController : BasePublicController
throw new Exception("Selected shipping method can't be loaded");
//save
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.SelectedShippingOption,
+ await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.SelectedShippingOption,
shippingOption, store.Id);
if (!warnings.Any())
@@ -545,7 +540,7 @@ public class CheckoutController : BasePublicController
//loyalty points
if (_loyaltyPointsSettings.Enabled)
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.UseLoyaltyPointsDuringCheckout, model.UseLoyaltyPoints,
_workContext.CurrentStore.Id);
@@ -555,7 +550,7 @@ public class CheckoutController : BasePublicController
if (!isPaymentWorkflowRequired)
{
//payment is not required
- await _userFieldService.SaveField<string>(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField<string>(_workContext.CurrentCustomer,
SystemCustomerFieldNames.SelectedPaymentMethod, null, _workContext.CurrentStore.Id);
var confirmOrderModel = await _mediator.Send(new GetConfirmOrder {
@@ -578,16 +573,16 @@ public class CheckoutController : BasePublicController
throw new Exception("Selected payment method can't be parsed");
//save
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.SelectedPaymentMethod, model.PaymentMethod, _workContext.CurrentStore.Id);
var paymentTransaction = await paymentMethodInst.InitPaymentTransaction();
if (paymentTransaction != null)
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.PaymentTransaction, paymentTransaction.Id,
_workContext.CurrentStore.Id);
else
- await _userFieldService.SaveField<string>(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField<string>(_workContext.CurrentCustomer,
SystemCustomerFieldNames.PaymentTransaction, null, _workContext.CurrentStore.Id);
return await LoadStepAfterPaymentMethod(paymentMethodInst, cart);
@@ -609,9 +604,7 @@ public class CheckoutController : BasePublicController
ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
await CartValidate(cart);
- var paymentMethodSystemName = await _workContext.CurrentCustomer.GetUserField<string>(
- _userFieldService, SystemCustomerFieldNames.SelectedPaymentMethod,
- _workContext.CurrentStore.Id);
+ var paymentMethodSystemName = _workContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.SelectedPaymentMethod, _workContext.CurrentStore.Id);
var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(paymentMethodSystemName);
if (paymentMethod == null)
throw new Exception("Payment method is not selected");
@@ -623,7 +616,7 @@ public class CheckoutController : BasePublicController
var paymentTransaction = await paymentMethod.SavePaymentInfo(model);
if (paymentTransaction != null)
//save
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.PaymentTransaction, paymentTransaction.Id,
_workContext.CurrentStore.Id);
@@ -808,7 +801,6 @@ public class CheckoutController : BasePublicController
private readonly ICustomerService _customerService;
private readonly IGroupService _groupService;
private readonly IShoppingCartService _shoppingCartService;
- private readonly IUserFieldService _userFieldService;
private readonly IShippingService _shippingService;
private readonly IPickupPointService _pickupPointService;
private readonly IPaymentService _paymentService;
@@ -911,7 +903,7 @@ public class CheckoutController : BasePublicController
goto_section = "shipping_method"
});
if (!(_shippingSettings.AllowPickUpInStore && !string.IsNullOrEmpty(selectedPickupPoint)))
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.SelectedShippingOption,
shippingMethodModel.ShippingMethods.First().ShippingOption,
_workContext.CurrentStore.Id);
@@ -959,7 +951,7 @@ public class CheckoutController : BasePublicController
//so customer doesn't have to choose a payment method
var selectedPaymentMethodSystemName = paymentMethodModel.PaymentMethods[0].PaymentMethodSystemName;
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.SelectedPaymentMethod,
selectedPaymentMethodSystemName, _workContext.CurrentStore.Id);
@@ -976,7 +968,7 @@ public class CheckoutController : BasePublicController
}
//payment is not required
- await _userFieldService.SaveField<string>(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField<string>(_workContext.CurrentCustomer,
SystemCustomerFieldNames.SelectedPaymentMethod, null, _workContext.CurrentStore.Id);
var confirmOrderModel = await _mediator.Send(new GetConfirmOrder {
diff --git a/src/Web/Grand.Web/Controllers/CommonController.cs b/src/Web/Grand.Web/Controllers/CommonController.cs
index 41b244db3..dbcbcc939 100644
--- a/src/Web/Grand.Web/Controllers/CommonController.cs
+++ b/src/Web/Grand.Web/Controllers/CommonController.cs
@@ -2,6 +2,7 @@
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Domain.Common;
using Grand.Domain.Customers;
using Grand.Domain.Localization;
@@ -141,7 +142,7 @@ public class CommonController : BasePublicController
[DenySystemAccount]
public virtual async Task<IActionResult> SetLanguage(
[FromServices] AppConfig config,
- [FromServices] IUserFieldService userFieldService,
+ [FromServices] ICustomerService customerService,
string langCode, string returnUrl = default)
{
var language = await _languageService.GetLanguageByCode(langCode);
@@ -164,9 +165,7 @@ public class CommonController : BasePublicController
returnUrl = AddLanguageSeo(returnUrl, language);
}
-
- await userFieldService.SaveField(_workContext.CurrentCustomer, SystemCustomerFieldNames.LanguageId, language.Id,
- _workContext.CurrentStore.Id);
+ await customerService.UpdateUserField(_workContext.CurrentCustomer, SystemCustomerFieldNames.LanguageId, language.Id, _workContext.CurrentStore.Id);
//notification
await _mediator.Publish(new ChangeLanguageEvent(_workContext.CurrentCustomer, language));
@@ -211,19 +210,19 @@ public class CommonController : BasePublicController
[HttpGet]
public virtual async Task<IActionResult> SetCurrency(
[FromServices] ICurrencyService currencyService,
- [FromServices] IUserFieldService userFieldService,
+ [FromServices] ICustomerService customerService,
string currencyCode, string returnUrl = "")
{
var currency = await currencyService.GetCurrencyByCode(currencyCode);
if (currency != null)
- await userFieldService.SaveField(_workContext.CurrentCustomer, SystemCustomerFieldNames.CurrencyId,
+ await customerService.UpdateUserField(_workContext.CurrentCustomer, SystemCustomerFieldNames.CurrencyId,
currency.Id, _workContext.CurrentStore.Id);
//clear coupon code
- await userFieldService.SaveField(_workContext.CurrentCustomer, SystemCustomerFieldNames.DiscountCoupons, "");
+ await customerService.UpdateUserField(_workContext.CurrentCustomer, SystemCustomerFieldNames.DiscountCoupons, "");
//clear gift card
- await userFieldService.SaveField(_workContext.CurrentCustomer, SystemCustomerFieldNames.GiftVoucherCoupons, "");
+ await customerService.UpdateUserField(_workContext.CurrentCustomer, SystemCustomerFieldNames.GiftVoucherCoupons, "");
//notification
await _mediator.Publish(new ChangeCurrencyEvent(_workContext.CurrentCustomer, currency));
@@ -284,7 +283,7 @@ public class CommonController : BasePublicController
[HttpGet]
public virtual async Task<IActionResult> SetTaxType(
[FromServices] TaxSettings taxSettings,
- [FromServices] IUserFieldService userFieldService,
+ [FromServices] ICustomerService customerService,
int customerTaxType, string returnUrl = default)
{
var taxDisplayType = (TaxDisplayType)Enum.ToObject(typeof(TaxDisplayType), customerTaxType);
@@ -302,7 +301,7 @@ public class CommonController : BasePublicController
return Redirect(returnUrl);
//save passed value
- await userFieldService.SaveField(_workContext.CurrentCustomer,
+ await customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.TaxDisplayTypeId, (int)taxDisplayType, _workContext.CurrentStore.Id);
//notification
@@ -357,7 +356,7 @@ public class CommonController : BasePublicController
[DenySystemAccount]
public virtual async Task<IActionResult> CookieAccept(bool accept,
[FromServices] StoreInformationSettings storeInformationSettings,
- [FromServices] IUserFieldService userFieldService,
+ [FromServices] ICustomerService customerService,
[FromServices] ICookiePreference cookiePreference)
{
if (!storeInformationSettings.DisplayCookieInformation)
@@ -365,18 +364,18 @@ public class CommonController : BasePublicController
return Json(new { stored = false });
//save consent cookies
- await userFieldService.SaveField(_workContext.CurrentCustomer, SystemCustomerFieldNames.ConsentCookies, "",
+ await customerService.UpdateUserField(_workContext.CurrentCustomer, SystemCustomerFieldNames.ConsentCookies, "",
_workContext.CurrentStore.Id);
var dictionary = new Dictionary<string, bool>();
var consentCookies = cookiePreference.GetConsentCookies();
foreach (var item in consentCookies.Where(x => x.AllowToDisable)) dictionary.Add(item.SystemName, accept);
if (dictionary.Any())
- await userFieldService.SaveField(_workContext.CurrentCustomer, SystemCustomerFieldNames.ConsentCookies,
+ await customerService.UpdateUserField(_workContext.CurrentCustomer, SystemCustomerFieldNames.ConsentCookies,
dictionary, _workContext.CurrentStore.Id);
//save setting - CookieAccepted
- await userFieldService.SaveField(_workContext.CurrentCustomer, SystemCustomerFieldNames.CookieAccepted,
+ await customerService.UpdateUserField(_workContext.CurrentCustomer, SystemCustomerFieldNames.CookieAccepted,
true, _workContext.CurrentStore.Id);
return Json(new { stored = true });
@@ -409,14 +408,14 @@ public class CommonController : BasePublicController
[DenySystemAccount]
public virtual async Task<IActionResult> PrivacyPreference(IDictionary<string, string> model,
[FromServices] StoreInformationSettings storeInformationSettings,
- [FromServices] IUserFieldService userFieldService,
+ [FromServices] ICustomerService customerService,
[FromServices] ICookiePreference cookiePreference)
{
if (!storeInformationSettings.DisplayPrivacyPreference)
return Json(new { success = false });
const string consent = "ConsentCookies";
- await userFieldService.SaveField(_workContext.CurrentCustomer, SystemCustomerFieldNames.ConsentCookies, "",
+ await customerService.UpdateUserField(_workContext.CurrentCustomer, SystemCustomerFieldNames.ConsentCookies, "",
_workContext.CurrentStore.Id);
var selectedConsentCookies = new List<string>();
foreach (var item in model)
@@ -429,8 +428,7 @@ public class CommonController : BasePublicController
if (item.AllowToDisable)
dictionary.Add(item.SystemName, selectedConsentCookies.Contains(item.SystemName));
- await userFieldService.SaveField(_workContext.CurrentCustomer, SystemCustomerFieldNames.ConsentCookies,
- dictionary, _workContext.CurrentStore.Id);
+ await customerService.UpdateUserField(_workContext.CurrentCustomer, SystemCustomerFieldNames.ConsentCookies, dictionary, _workContext.CurrentStore.Id);
return Json(new { success = true });
}
diff --git a/src/Web/Grand.Web/Controllers/ShoppingCartController.cs b/src/Web/Grand.Web/Controllers/ShoppingCartController.cs
index 64b4a57fe..794eb59a6 100644
--- a/src/Web/Grand.Web/Controllers/ShoppingCartController.cs
+++ b/src/Web/Grand.Web/Controllers/ShoppingCartController.cs
@@ -40,7 +40,6 @@ public class ShoppingCartController : BasePublicController
IGroupService groupService,
ICheckoutAttributeService checkoutAttributeService,
IPermissionService permissionService,
- IUserFieldService userFieldService,
IMediator mediator,
IShoppingCartValidator shoppingCartValidator,
ShoppingCartSettings shoppingCartSettings,
@@ -54,7 +53,6 @@ public class ShoppingCartController : BasePublicController
_groupService = groupService;
_checkoutAttributeService = checkoutAttributeService;
_permissionService = permissionService;
- _userFieldService = userFieldService;
_mediator = mediator;
_shoppingCartValidator = shoppingCartValidator;
_shoppingCartSettings = shoppingCartSettings;
@@ -89,7 +87,6 @@ public class ShoppingCartController : BasePublicController
private readonly IGroupService _groupService;
private readonly ICheckoutAttributeService _checkoutAttributeService;
private readonly IPermissionService _permissionService;
- private readonly IUserFieldService _userFieldService;
private readonly IMediator _mediator;
private readonly IShoppingCartValidator _shoppingCartValidator;
private readonly ShoppingCartSettings _shoppingCartSettings;
@@ -528,7 +525,7 @@ public class ShoppingCartController : BasePublicController
_workContext.CurrentCustomer.ApplyCouponCode(SystemCustomerFieldNames.DiscountCoupons,
model.DiscountCouponCode);
//apply new value
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.DiscountCoupons, applyCouponCode);
message = _translationService.GetResource("ShoppingCart.DiscountCouponCode.Applied");
isApplied = true;
@@ -572,7 +569,7 @@ public class ShoppingCartController : BasePublicController
var result = _workContext.CurrentCustomer.ApplyCouponCode(SystemCustomerFieldNames.GiftVoucherCoupons,
model.GiftVoucherCouponCode.ToLower());
//apply new value
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.GiftVoucherCoupons, result);
message = _translationService.GetResource("ShoppingCart.Code.Applied");
@@ -637,7 +634,7 @@ public class ShoppingCartController : BasePublicController
//remove coupon
var result =
_workContext.CurrentCustomer.RemoveCouponCode(SystemCustomerFieldNames.DiscountCoupons, item);
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.DiscountCoupons, result);
}
}
@@ -672,7 +669,7 @@ public class ShoppingCartController : BasePublicController
var result =
_workContext.CurrentCustomer.RemoveCouponCode(SystemCustomerFieldNames.GiftVoucherCoupons,
giftvoucher.Code);
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_workContext.CurrentCustomer,
SystemCustomerFieldNames.GiftVoucherCoupons, result);
}
}
diff --git a/src/Web/Grand.Web/Features/Handlers/Checkout/GetShippingMethodHandler.cs b/src/Web/Grand.Web/Features/Handlers/Checkout/GetShippingMethodHandler.cs
index a5c7a5707..646e5ef67 100644
--- a/src/Web/Grand.Web/Features/Handlers/Checkout/GetShippingMethodHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Checkout/GetShippingMethodHandler.cs
@@ -2,7 +2,7 @@
using Grand.Business.Core.Interfaces.Catalog.Tax;
using Grand.Business.Core.Interfaces.Checkout.Orders;
using Grand.Business.Core.Interfaces.Checkout.Shipping;
-using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Domain.Common;
using Grand.Domain.Customers;
using Grand.Domain.Shipping;
@@ -18,16 +18,16 @@ public class GetShippingMethodHandler : IRequestHandler<GetShippingMethod, Check
private readonly IPriceFormatter _priceFormatter;
private readonly IShippingService _shippingService;
private readonly ITaxService _taxService;
- private readonly IUserFieldService _userFieldService;
+ private readonly ICustomerService _customerService;
public GetShippingMethodHandler(IShippingService shippingService,
- IUserFieldService userFieldService,
+ ICustomerService customerService,
IOrderCalculationService orderTotalCalculationService,
ITaxService taxService,
IPriceFormatter priceFormatter)
{
_shippingService = shippingService;
- _userFieldService = userFieldService;
+ _customerService = customerService;
_orderTotalCalculationService = orderTotalCalculationService;
_taxService = taxService;
_priceFormatter = priceFormatter;
@@ -46,7 +46,7 @@ public class GetShippingMethodHandler : IRequestHandler<GetShippingMethod, Check
{
//performance optimization. cache returned shipping options.
//we'll use them later (after a customer has selected an option).
- await _userFieldService.SaveField(request.Customer,
+ await _customerService.UpdateUserField(request.Customer,
SystemCustomerFieldNames.OfferedShippingOptions,
getShippingOptionResponse.ShippingOptions,
request.Store.Id);