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.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Register form / Account Info - remove IFormCollection
support6aa507bc059a
diff --git a/src/Web/Grand.Web/Commands/Handler/Customers/CustomerRegisteredCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/Customers/CustomerRegisteredCommandHandler.csindex 163021d0d..5c442322c 100644--- a/src/Web/Grand.Web/Commands/Handler/Customers/CustomerRegisteredCommandHandler.cs+++ b/src/Web/Grand.Web/Commands/Handler/Customers/CustomerRegisteredCommandHandler.cs@@ -57,11 +57,11 @@ namespace Grand.Web.Commands.Handler.Customerspublic async Task<bool> Handle(CustomerRegisteredCommand request, CancellationToken cancellationToken){-//VAT numberif (_taxSettings.EuVatEnabled){- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.VatNumber, request.Model.VatNumber);+ await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.VatNumber,+ request.Model.VatNumber);var vat = await _checkVatService.GetVatNumberStatus(request.Model.VatNumber);@@ -72,56 +72,56 @@ namespace Grand.Web.Commands.Handler.Customers//form fieldsif (_customerSettings.GenderEnabled)- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Gender, request.Model.Gender);- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.FirstName, request.Model.FirstName);- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.LastName, request.Model.LastName);+ await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Gender,+ request.Model.Gender);+ await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.FirstName,+ request.Model.FirstName);+ await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.LastName,+ request.Model.LastName);if (_customerSettings.DateOfBirthEnabled){DateTime? dateOfBirth = request.Model.ParseDateOfBirth();await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.DateOfBirth, dateOfBirth);}+if (_customerSettings.CompanyEnabled)- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Company, request.Model.Company);+ await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Company,+ request.Model.Company);if (_customerSettings.StreetAddressEnabled)- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.StreetAddress, request.Model.StreetAddress);+ await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.StreetAddress,+ request.Model.StreetAddress);if (_customerSettings.StreetAddress2Enabled)- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.StreetAddress2, request.Model.StreetAddress2);+ await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.StreetAddress2,+ request.Model.StreetAddress2);if (_customerSettings.ZipPostalCodeEnabled)- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.ZipPostalCode, request.Model.ZipPostalCode);+ await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.ZipPostalCode,+ request.Model.ZipPostalCode);if (_customerSettings.CityEnabled)await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.City, request.Model.City);if (_customerSettings.CountryEnabled)- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.CountryId, request.Model.CountryId);+ await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.CountryId,+ request.Model.CountryId);if (_customerSettings.CountryEnabled && _customerSettings.StateProvinceEnabled)- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.StateProvinceId, request.Model.StateProvinceId);+ await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.StateProvinceId,+ request.Model.StateProvinceId);if (_customerSettings.PhoneEnabled)- await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Phone, request.Model.Phone);+ await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Phone,+ request.Model.Phone);if (_customerSettings.FaxEnabled)await _userFieldService.SaveField(request.Customer, SystemCustomerFieldNames.Fax, request.Model.Fax);//newsletterif (_customerSettings.NewsletterEnabled){- var categories = new List<string>();- foreach (string formKey in request.Form.Keys)- {- if (formKey.Contains("customernewsletterCategory_"))- {- try- {- var category = formKey.Split('_')[1];- categories.Add(category);- }- catch { }- }- }-+ var categories = request.Model.SelectedNewsletterCategory?.ToList();//save newsletter value- var newsletter = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(request.Model.Email, request.Store.Id);+ var newsletter =+ await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(request.Model.Email,+ request.Store.Id);if (newsletter != null){newsletter.Categories.Clear();- categories.ForEach(x => newsletter.Categories.Add(x));+ categories?.ForEach(x => newsletter.Categories.Add(x));if (request.Model.Newsletter){newsletter.Active = true;@@ -132,8 +132,7 @@ namespace Grand.Web.Commands.Handler.Customers{if (request.Model.Newsletter){- var newsLetterSubscription = new NewsLetterSubscription- {+ var newsLetterSubscription = new NewsLetterSubscription {NewsLetterSubscriptionGuid = Guid.NewGuid(),Email = request.Model.Email,CustomerId = request.Customer.Id,@@ -141,7 +140,7 @@ namespace Grand.Web.Commands.Handler.CustomersStoreId = request.Store.Id,CreatedOnUtc = DateTime.UtcNow};- categories.ForEach(x => newsLetterSubscription.Categories.Add(x));+ categories?.ForEach(x => newsLetterSubscription.Categories.Add(x));await _newsLetterSubscriptionService.InsertNewsLetterSubscription(newsLetterSubscription);}}@@ -151,17 +150,22 @@ namespace Grand.Web.Commands.Handler.Customersawait _customerService.UpdateCustomerField(request.Customer, x => x.Attributes, request.CustomerAttributes);//insert default address (if possible)- var defaultAddress = new Address- {+ var defaultAddress = new Address {FirstName = request.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.FirstName),LastName = request.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.LastName),Email = request.Customer.Email,Company = request.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.Company),VatNumber = request.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.VatNumber),- CountryId = !string.IsNullOrEmpty(request.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.CountryId)) ?- request.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.CountryId) : "",- StateProvinceId = !string.IsNullOrEmpty(request.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.StateProvinceId)) ?- request.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.StateProvinceId) : "",+ CountryId =+ !string.IsNullOrEmpty(+ request.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.CountryId))+ ? request.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.CountryId)+ : "",+ StateProvinceId =+ !string.IsNullOrEmpty(+ request.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.StateProvinceId))+ ? request.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.StateProvinceId)+ : "",City = request.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.City),Address1 = request.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.StreetAddress),Address2 = request.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.StreetAddress2),@@ -184,7 +188,8 @@ namespace Grand.Web.Commands.Handler.Customers//notificationsif (_customerSettings.NotifyNewCustomerRegistration)- await _messageProviderService.SendCustomerRegisteredMessage(request.Customer, request.Store, _languageSettings.DefaultAdminLanguageId);+ await _messageProviderService.SendCustomerRegisteredMessage(request.Customer, request.Store,+ _languageSettings.DefaultAdminLanguageId);//New customer has a free shipping for the first orderif (_customerSettings.RegistrationFreeShipping)@@ -203,33 +208,33 @@ namespace Grand.Web.Commands.Handler.Customersif (address == null)throw new ArgumentNullException(nameof(address));- if (String.IsNullOrWhiteSpace(address.FirstName))+ if (string.IsNullOrWhiteSpace(address.FirstName))return false;- if (String.IsNullOrWhiteSpace(address.LastName))+ if (string.IsNullOrWhiteSpace(address.LastName))return false;- if (String.IsNullOrWhiteSpace(address.Email))+ if (string.IsNullOrWhiteSpace(address.Email))return false;if (_addressSettings.CompanyEnabled &&_addressSettings.CompanyRequired &&- String.IsNullOrWhiteSpace(address.Company))+ string.IsNullOrWhiteSpace(address.Company))return false;if (_addressSettings.VatNumberEnabled &&_addressSettings.VatNumberRequired &&- String.IsNullOrWhiteSpace(address.VatNumber))+ string.IsNullOrWhiteSpace(address.VatNumber))return false;if (_addressSettings.StreetAddressEnabled &&_addressSettings.StreetAddressRequired &&- String.IsNullOrWhiteSpace(address.Address1))+ string.IsNullOrWhiteSpace(address.Address1))return false;if (_addressSettings.StreetAddress2Enabled &&_addressSettings.StreetAddress2Required &&- String.IsNullOrWhiteSpace(address.Address2))+ string.IsNullOrWhiteSpace(address.Address2))return false;if (_addressSettings.ZipPostalCodeEnabled &&@@ -240,7 +245,7 @@ namespace Grand.Web.Commands.Handler.Customersif (_addressSettings.CountryEnabled){- if (String.IsNullOrEmpty(address.CountryId))+ if (string.IsNullOrEmpty(address.CountryId))return false;var country = await _countryService.GetCountryById(address.CountryId);@@ -264,25 +269,21 @@ namespace Grand.Web.Commands.Handler.Customersif (_addressSettings.CityEnabled &&_addressSettings.CityRequired &&- String.IsNullOrWhiteSpace(address.City))+ string.IsNullOrWhiteSpace(address.City))return false;if (_addressSettings.PhoneEnabled &&_addressSettings.PhoneRequired &&- String.IsNullOrWhiteSpace(address.PhoneNumber))+ string.IsNullOrWhiteSpace(address.PhoneNumber))return false;if (_addressSettings.FaxEnabled &&_addressSettings.FaxRequired &&- String.IsNullOrWhiteSpace(address.FaxNumber))+ string.IsNullOrWhiteSpace(address.FaxNumber))return false;var attributes = await _addressAttributeService.GetAllAddressAttributes();- if (attributes.Any(x => x.IsRequired))- return false;-- return true;+ return !attributes.Any(x => x.IsRequired);}-}-}+}\ No newline at end of filediff --git a/src/Web/Grand.Web/Commands/Handler/Customers/UpdateCustomerInfoCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/Customers/UpdateCustomerInfoCommandHandler.csindex bfd4ebd74..ca2ea4791 100644--- a/src/Web/Grand.Web/Commands/Handler/Customers/UpdateCustomerInfoCommandHandler.cs+++ b/src/Web/Grand.Web/Commands/Handler/Customers/UpdateCustomerInfoCommandHandler.cs@@ -8,7 +8,6 @@ using Grand.Domain.Customers;using Grand.Domain.Messages;using Grand.Domain.Tax;using Grand.Web.Commands.Models.Customers;-using Grand.Web.Events;using MediatR;namespace Grand.Web.Commands.Handler.Customers@@ -91,15 +90,9 @@ namespace Grand.Web.Commands.Handler.Customers{await UpdateNewsletter(request);}-//save customer attributesawait _customerService.UpdateCustomerField(request.Customer, x => x.Attributes, request.CustomerAttributes);-- //notification- await _mediator.Publish(new CustomerInfoEvent(request.Customer, request.Model, request.Form, request.CustomerAttributes));-return true;-}private async Task UpdateTax(UpdateCustomerInfoCommand request)@@ -151,26 +144,14 @@ namespace Grand.Web.Commands.Handler.Customersprivate async Task UpdateNewsletter(UpdateCustomerInfoCommand request){- var categories = new List<string>();- foreach (string formKey in request.Form.Keys)- {- if (formKey.Contains("customernewsletterCategory_"))- {- try- {- var category = formKey.Split('_')[1];- categories.Add(category);- }- catch { }- }- }+ var categories = request.Model.SelectedNewsletterCategory?.ToList();//save newsletter valuevar newsletter = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(request.Customer.Email, request.Store.Id);if (newsletter != null){newsletter.Categories.Clear();- categories.ForEach(x => newsletter.Categories.Add(x));+ categories?.ForEach(x => newsletter.Categories.Add(x));if (request.Model.Newsletter){@@ -196,7 +177,7 @@ namespace Grand.Web.Commands.Handler.CustomersStoreId = request.Store.Id,CreatedOnUtc = DateTime.UtcNow};- categories.ForEach(x => newsLetterSubscription.Categories.Add(x));+ categories?.ForEach(x => newsLetterSubscription.Categories.Add(x));await _newsLetterSubscriptionService.InsertNewsLetterSubscription(newsLetterSubscription);}}diff --git a/src/Web/Grand.Web/Commands/Models/Customers/CustomerRegisteredCommand.cs b/src/Web/Grand.Web/Commands/Models/Customers/CustomerRegisteredCommand.csindex 1a552ef03..11e613705 100644--- a/src/Web/Grand.Web/Commands/Models/Customers/CustomerRegisteredCommand.cs+++ b/src/Web/Grand.Web/Commands/Models/Customers/CustomerRegisteredCommand.cs@@ -3,7 +3,6 @@ using Grand.Domain.Customers;using Grand.Domain.Stores;using Grand.Web.Models.Customer;using MediatR;-using Microsoft.AspNetCore.Http;namespace Grand.Web.Commands.Models.Customers{@@ -12,7 +11,6 @@ namespace Grand.Web.Commands.Models.Customerspublic Customer Customer { get; set; }public Store Store { get; set; }public RegisterModel Model { get; set; }- public IFormCollection Form { get; set; }public IList<CustomAttribute> CustomerAttributes { get; set; }}}diff --git a/src/Web/Grand.Web/Commands/Models/Customers/UpdateCustomerInfoCommand.cs b/src/Web/Grand.Web/Commands/Models/Customers/UpdateCustomerInfoCommand.csindex 996684d7e..896eed640 100644--- a/src/Web/Grand.Web/Commands/Models/Customers/UpdateCustomerInfoCommand.cs+++ b/src/Web/Grand.Web/Commands/Models/Customers/UpdateCustomerInfoCommand.cs@@ -3,7 +3,6 @@ using Grand.Domain.Customers;using Grand.Domain.Stores;using Grand.Web.Models.Customer;using MediatR;-using Microsoft.AspNetCore.Http;namespace Grand.Web.Commands.Models.Customers{@@ -12,7 +11,6 @@ namespace Grand.Web.Commands.Models.Customerspublic Customer Customer { get; set; }public Store Store { get; set; }public CustomerInfoModel Model { get; set; }- public IFormCollection Form { get; set; }public IList<CustomAttribute> CustomerAttributes { get; set; }public Customer OriginalCustomerIfImpersonated { get; set; }}diff --git a/src/Web/Grand.Web/Controllers/AccountController.cs b/src/Web/Grand.Web/Controllers/AccountController.csindex 9c9a88559..b005a8337 100644--- a/src/Web/Grand.Web/Controllers/AccountController.cs+++ b/src/Web/Grand.Web/Controllers/AccountController.cs@@ -23,12 +23,11 @@ using Grand.Web.Models.Customer;using MediatR;using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.Mvc;-using Grand.Business.Core.Interfaces.ExportImport;namespace Grand.Web.Controllers{[DenySystemAccount]- public partial class AccountController : BasePublicController+ public class AccountController : BasePublicController{#region Fields@@ -405,7 +404,7 @@ namespace Grand.Web.Controllers[AutoValidateAntiforgeryToken]//available even when navigation is not allowed[PublicStore(true)]- public virtual async Task<IActionResult> Register(RegisterModel model, string returnUrl, bool captchaValid, IFormCollection form,+ public virtual async Task<IActionResult> Register(RegisterModel model, string returnUrl, bool captchaValid,[FromServices] ICustomerAttributeParser customerAttributeParser){//check whether registration is allowed@@ -419,7 +418,7 @@ namespace Grand.Web.Controllers}//custom customer attributes- var customerAttributes = await _mediator.Send(new GetParseCustomAttributes() { Form = form });+ var customerAttributes = await _mediator.Send(new GetParseCustomAttributes() { SelectedAttributes = model.SelectedAttributes });var customerAttributeWarnings = await customerAttributeParser.GetAttributeWarnings(customerAttributes);foreach (var error in customerAttributeWarnings){@@ -439,7 +438,7 @@ namespace Grand.Web.Controllersmodel.Username = model.Username.Trim();}- bool isApproved = _customerSettings.UserRegistrationType == UserRegistrationType.Standard;+ var isApproved = _customerSettings.UserRegistrationType == UserRegistrationType.Standard;var registrationRequest = new RegistrationRequest(_workContext.CurrentCustomer, model.Email,_customerSettings.UsernamesEnabled ? model.Username : model.Email, model.Password,_customerSettings.DefaultPasswordFormat, _workContext.CurrentStore.Id, isApproved);@@ -449,7 +448,6 @@ namespace Grand.Web.Controllersawait _mediator.Send(new CustomerRegisteredCommand() {Customer = _workContext.CurrentCustomer,CustomerAttributes = customerAttributes,- Form = form,Model = model,Store = _workContext.CurrentStore});@@ -595,8 +593,9 @@ namespace Grand.Web.Controllers//send welcome messageawait _messageProviderService.SendCustomerWelcomeMessage(customer, _workContext.CurrentStore, _workContext.WorkingLanguage.Id);- var model = new AccountActivationModel();- model.Result = _translationService.GetResource("Account.AccountActivation.Activated");+ var model = new AccountActivationModel {+ Result = _translationService.GetResource("Account.AccountActivation.Activated")+ };return View(model);}@@ -620,14 +619,14 @@ namespace Grand.Web.Controllers[HttpPost][AutoValidateAntiforgeryToken]- public virtual async Task<IActionResult> Info(CustomerInfoModel model, IFormCollection form,+ public virtual async Task<IActionResult> Info(CustomerInfoModel model,[FromServices] ICustomerAttributeParser customerAttributeParser){if (!await _groupService.IsRegistered(_workContext.CurrentCustomer))return Challenge();//custom customer attributes- var customerAttributes = await _mediator.Send(new GetParseCustomAttributes() { Form = form, CustomerCustomAttribute = _workContext.CurrentCustomer.Attributes.ToList() });+ var customerAttributes = await _mediator.Send(new GetParseCustomAttributes() { SelectedAttributes = model.SelectedAttributes, CustomerCustomAttribute = _workContext.CurrentCustomer.Attributes.ToList() });var customerAttributeWarnings = await customerAttributeParser.GetAttributeWarnings(customerAttributes);foreach (var error in customerAttributeWarnings)@@ -637,12 +636,11 @@ namespace Grand.Web.Controllerstry{- if (ModelState.IsValid && ModelState.ErrorCount == 0)+ if (ModelState is { IsValid: true, ErrorCount: 0 }){await _mediator.Send(new UpdateCustomerInfoCommand() {Customer = _workContext.CurrentCustomer,CustomerAttributes = customerAttributes,- Form = form,Model = model,OriginalCustomerIfImpersonated = _workContext.OriginalCustomerIfImpersonated,Store = _workContext.CurrentStorediff --git a/src/Web/Grand.Web/Events/CustomerInfoEvent.cs b/src/Web/Grand.Web/Events/CustomerInfoEvent.csdeleted file mode 100644index e0c0a19bd..000000000--- a/src/Web/Grand.Web/Events/CustomerInfoEvent.cs+++ /dev/null@@ -1,24 +0,0 @@-using Grand.Domain.Common;-using Grand.Domain.Customers;-using Grand.Web.Models.Customer;-using MediatR;-using Microsoft.AspNetCore.Http;--namespace Grand.Web.Events-{- public class CustomerInfoEvent : INotification- {- public Customer Customer { get; set; }- public CustomerInfoModel Model { get; set; }- public IFormCollection Form { get; set; }- public IList<CustomAttribute> CustomerAttributes { get; set; }-- public CustomerInfoEvent(Customer customer, CustomerInfoModel model, IFormCollection form, IList<CustomAttribute> customerAttributes)- {- Customer = customer;- Model = model;- Form = form;- CustomerAttributes = customerAttributes;- }- }-}diff --git a/src/Web/Grand.Web/Features/Handlers/Customers/GetParseCustomAttributesHandler.cs b/src/Web/Grand.Web/Features/Handlers/Customers/GetParseCustomAttributesHandler.csindex 7ed96d671..330ebffa7 100644--- a/src/Web/Grand.Web/Features/Handlers/Customers/GetParseCustomAttributesHandler.cs+++ b/src/Web/Grand.Web/Features/Handlers/Customers/GetParseCustomAttributesHandler.cs@@ -31,13 +31,12 @@ namespace Grand.Web.Features.Handlers.Customerscontinue;}- string controlId = string.Format("customer_attribute_{0}", attribute.Id);switch (attribute.AttributeControlTypeId){case AttributeControlType.DropdownList:case AttributeControlType.RadioList:{- request.Form.TryGetValue(controlId, out var ctrlAttributes);+ var ctrlAttributes = request.SelectedAttributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;if (!string.IsNullOrEmpty(ctrlAttributes)){customAttributes = _customerAttributeParser.AddCustomerAttribute(customAttributes,@@ -47,10 +46,10 @@ namespace Grand.Web.Features.Handlers.Customersbreak;case AttributeControlType.Checkboxes:{- request.Form.TryGetValue(controlId, out var cblAttributes);+ var cblAttributes = request.SelectedAttributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;if (!string.IsNullOrEmpty(cblAttributes)){- foreach (var item in cblAttributes)+ foreach (var item in cblAttributes.Split(',')){if (!String.IsNullOrEmpty(item))customAttributes = _customerAttributeParser.AddCustomerAttribute(customAttributes,@@ -77,7 +76,7 @@ namespace Grand.Web.Features.Handlers.Customerscase AttributeControlType.MultilineTextbox:case AttributeControlType.Hidden:{- request.Form.TryGetValue(controlId, out var ctrlAttributes);+ var ctrlAttributes = request.SelectedAttributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;if (!string.IsNullOrEmpty(ctrlAttributes)){var enteredText = ctrlAttributes.ToString().Trim();diff --git a/src/Web/Grand.Web/Features/Models/Customers/GetParseCustomAttributes.cs b/src/Web/Grand.Web/Features/Models/Customers/GetParseCustomAttributes.csindex e747f7b74..fd5e100e5 100644--- a/src/Web/Grand.Web/Features/Models/Customers/GetParseCustomAttributes.cs+++ b/src/Web/Grand.Web/Features/Models/Customers/GetParseCustomAttributes.cs@@ -1,7 +1,6 @@--using Grand.Domain.Common;+using Grand.Domain.Common;+using Grand.Web.Common.Models;using MediatR;-using Microsoft.AspNetCore.Http;namespace Grand.Web.Features.Models.Customers{@@ -11,7 +10,8 @@ namespace Grand.Web.Features.Models.Customers{CustomerCustomAttribute = new List<CustomAttribute>();}- public IFormCollection Form { get; set; }++ public IList<CustomAttributeModel> SelectedAttributes { get; set; }public List<CustomAttribute> CustomerCustomAttribute { get; set; }}diff --git a/src/Web/Grand.Web/Models/Customer/CustomerInfoModel.cs b/src/Web/Grand.Web/Models/Customer/CustomerInfoModel.csindex 04984685e..4d937e5a2 100644--- a/src/Web/Grand.Web/Models/Customer/CustomerInfoModel.cs+++ b/src/Web/Grand.Web/Models/Customer/CustomerInfoModel.cs@@ -1,7 +1,10 @@using Grand.Domain.Customers;using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Web.Common.Binders;+using Grand.Web.Common.Models;using Grand.Web.Models.Newsletter;+using Microsoft.AspNetCore.Mvc;using Microsoft.AspNetCore.Mvc.Rendering;using System.ComponentModel.DataAnnotations;@@ -15,6 +18,7 @@ namespace Grand.Web.Models.CustomerAvailableStates = new List<SelectListItem>();AssociatedExternalAuthRecords = new List<AssociatedExternalAuthModel>();CustomerAttributes = new List<CustomerAttributeModel>();+ SelectedAttributes = new List<CustomAttributeModel>();NewsletterCategories = new List<NewsletterSimpleCategory>();}@@ -113,7 +117,8 @@ namespace Grand.Web.Models.Customerpublic bool NewsletterEnabled { get; set; }[GrandResourceDisplayName("Account.Fields.Newsletter")]public bool Newsletter { get; set; }-+ public string[] SelectedNewsletterCategory { get; set; }+//2factorypublic bool Is2faEnabled { get; set; }@@ -127,7 +132,10 @@ namespace Grand.Web.Models.Customer[GrandResourceDisplayName("Account.AssociatedExternalAuth")]public IList<AssociatedExternalAuthModel> AssociatedExternalAuthRecords { get; set; }public int NumberOfExternalAuthenticationProviders { get; set; }-++ [ModelBinder(BinderType = typeof(CustomAttributesBinder))]+ public IList<CustomAttributeModel> SelectedAttributes { get; set; }+public IList<CustomerAttributeModel> CustomerAttributes { get; set; }public IList<NewsletterSimpleCategory> NewsletterCategories { get; set; }diff --git a/src/Web/Grand.Web/Models/Customer/RegisterModel.cs b/src/Web/Grand.Web/Models/Customer/RegisterModel.csindex 0092812e9..f6bdbdab9 100644--- a/src/Web/Grand.Web/Models/Customer/RegisterModel.cs+++ b/src/Web/Grand.Web/Models/Customer/RegisterModel.cs@@ -1,6 +1,9 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Web.Common.Binders;+using Grand.Web.Common.Models;using Grand.Web.Models.Newsletter;+using Microsoft.AspNetCore.Mvc;using Microsoft.AspNetCore.Mvc.Rendering;using System.ComponentModel.DataAnnotations;@@ -13,6 +16,7 @@ namespace Grand.Web.Models.CustomerAvailableCountries = new List<SelectListItem>();AvailableStates = new List<SelectListItem>();CustomerAttributes = new List<CustomerAttributeModel>();+ SelectedAttributes = new List<CustomAttributeModel>();NewsletterCategories = new List<NewsletterSimpleCategory>();}[DataType(DataType.EmailAddress)]@@ -120,7 +124,7 @@ namespace Grand.Web.Models.Customerpublic bool NewsletterEnabled { get; set; }[GrandResourceDisplayName("Account.Fields.Newsletter")]public bool Newsletter { get; set; }-+ public string[] SelectedNewsletterCategory { get; set; }public bool AcceptPrivacyPolicyEnabled { get; set; }//EU VAT@@ -130,6 +134,9 @@ namespace Grand.Web.Models.Customerpublic bool DisplayCaptcha { get; set; }+ [ModelBinder(BinderType = typeof(CustomAttributesBinder))]+ public IList<CustomAttributeModel> SelectedAttributes { get; set; }+public IList<CustomerAttributeModel> CustomerAttributes { get; set; }public IList<NewsletterSimpleCategory> NewsletterCategories { get; set; }}diff --git a/src/Web/Grand.Web/Views/Account/Partials/CustomerAttributes.cshtml b/src/Web/Grand.Web/Views/Account/Partials/CustomerAttributes.cshtmlindex 5e06e4d2c..ab17df4bf 100644--- a/src/Web/Grand.Web/Views/Account/Partials/CustomerAttributes.cshtml+++ b/src/Web/Grand.Web/Views/Account/Partials/CustomerAttributes.cshtml@@ -1,11 +1,9 @@@model IList<Grand.Web.Models.Customer.CustomerAttributeModel>-@using Grand.Domain.Catalog;@foreach (var attribute in Model){- string controlId = string.Format("customer_attribute_{0}", attribute.Id);- string textPrompt = attribute.Name;- string required = attribute.IsRequired ? "required" : "";- string readonlyAttr = attribute.IsReadOnly ? "disabled=\"disabled\"" : "";+ var controlId = string.Format("customer_attribute_{0}", attribute.Id);+ var controlName = $"attributes[{attribute.Id}]";+ var textPrompt = attribute.Name;<div class="row"><div class="col-12 form-group custom-attributes">@@ -19,8 +17,8 @@case AttributeControlType.DropdownList:{- <validation-provider @if (attribute.IsRequired) { <text> rules="required" </text> } name="@(controlId)" v-slot="{ errors, classes }">- <select v-model="customer.@(controlId)" data-val-required="@(string.Format(Loc["Fields.IsRequired"], textPrompt))" v-bind:class="[classes , 'custom-select form-control']" name="@(controlId)" id="@(controlId)">+ <validation-provider @if (attribute.IsRequired) { <text> rules="required" </text> } v-slot="{ errors, classes }">+ <select v-model="customer.@(controlId)" data-val-required="@(string.Format(Loc["Fields.IsRequired"], textPrompt))" v-bind:class="[classes , 'custom-select form-control']" name="@(controlName)" id="@(controlId)">@if (!attribute.IsRequired){<option value="">---</option>@@ -53,7 +51,7 @@@foreach (var attributeValue in attribute.Values){<label class="custom-control custom-radio">- <input class="custom-control-input" type="radio" id="@(controlId)_@(attributeValue.Id)" name="@(controlId)" value="@(attributeValue.Id)" v-model="customer.@(controlId)" @if (attributeValue.IsPreSelected) { <text> data-checked="true" </text> }>+ <input class="custom-control-input" type="radio" id="@(controlId)_@(attributeValue.Id)" name="@(controlName)" value="@(attributeValue.Id)" v-model="customer.@(controlId)" @if (attributeValue.IsPreSelected) { <text> data-checked="true" </text> }><span class="custom-control-label"></span><span class="custom-control-description">@attributeValue.Name</span></label>@@ -77,7 +75,7 @@@foreach (var attributeValue in attribute.Values){<label class="custom-control custom-checkbox">- <input class="custom-control-input" type="checkbox" id="@(controlId)_@(attributeValue.Id)" name="@(controlId)" value="@(attributeValue.Id)" v-model="customer.@(controlId)" @(attribute.AttributeControlType == AttributeControlType.ReadonlyCheckboxes ? Html.Raw(" disabled=\"disabled\"") : null)>+ <input class="custom-control-input" type="checkbox" id="@(controlId)_@(attributeValue.Id)" name="@(controlName)" value="@(attributeValue.Id)" v-model="customer.@(controlId)" @(attribute.AttributeControlType == AttributeControlType.ReadonlyCheckboxes ? Html.Raw(" disabled=\"disabled\"") : null)><span class="custom-control-label"></span><span class="custom-control-description">@attributeValue.Name</span></label>@@ -90,8 +88,8 @@break;case AttributeControlType.TextBox:{- <validation-provider @if (attribute.IsRequired) { <text> rules="required" </text> } name="@(controlId)" v-slot="{ errors, classes }">- <input name="@(controlId)" type="text"+ <validation-provider @if (attribute.IsRequired) { <text> rules="required" </text> } v-slot="{ errors, classes }">+ <input name="@(controlName)" type="text"id="@(controlId)" v-model="customer.@(controlId)" data-val-required="@(string.Format(Loc["Fields.IsRequired"], textPrompt))" v-bind:class="[classes , 'form-control textbox']" /><span class="field-validation-error">{{ errors[0] }}</span></validation-provider>@@ -99,8 +97,8 @@break;case AttributeControlType.MultilineTextbox:{- <validation-provider @if (attribute.IsRequired) { <text> rules="required" </text> } name="@(controlId)" v-slot="{ errors, classes }">- <textarea name="@(controlId)"+ <validation-provider @if (attribute.IsRequired) { <text> rules="required" </text> } v-slot="{ errors, classes }">+ <textarea name="@(controlName)"id="@(controlId)" v-model="customer.@(controlId)" data-val-required="@(string.Format(Loc["Fields.IsRequired"], textPrompt))" v-bind:class="[classes , 'form-control']"></textarea><span class="field-validation-error">{{ errors[0] }}</span></validation-provider>diff --git a/src/Web/Grand.Web/Views/Account/Partials/NewsLetterCategories.cshtml b/src/Web/Grand.Web/Views/Account/Partials/NewsLetterCategories.cshtmlindex 6fdded161..4a709b6d2 100644--- a/src/Web/Grand.Web/Views/Account/Partials/NewsLetterCategories.cshtml+++ b/src/Web/Grand.Web/Views/Account/Partials/NewsLetterCategories.cshtml@@ -8,14 +8,13 @@{<li>@{- string controlId = $"customernewsletterCategory_{attribute.Id}";- string textPrompt = attribute.Name;+ var controlId = $"customerNewsletterCategory_{attribute.Id}";}<label for="@(controlId)" class="custom-control custom-checkbox">- <input class="custom-control-input" id="@(controlId)" type="checkbox" name="@(controlId)" value="@(attribute.Id)"+ <input class="custom-control-input" id="@(controlId)" type="checkbox" name="SelectedNewsletterCategory" value="@(attribute.Id)"checked="@(attribute.Selected)" /><span class="custom-control-label"></span>- <span class="custom-control-description">@textPrompt</span>+ <span class="custom-control-description">@(attribute.Name)</span></label><div>@Html.Raw(attribute.Description)