if (_customerSettings.groupownerEnabled) await _genericAttributeService.SaveAttributeAsync(customer, NopCustomerDefaults.groupownerAttribute, model.groupowner);
as we can see that you have stored the value into Generic attribute , so you need to assign the value from the generic attribute only and store from there only ,
you can take reference from the other field of generic attribute click here to see the screenshot you need to assign like this
Thanks for ur reply, after debugging, I still did not fix the problem yet, the reason is, when I change the value in the page "My account - Customer info", I can see the value has been changed to the new value, like 12345(old) to 55555(new). if (_customerSettings.groupownerEnabled) await _genericAttributeService.SaveAttributeAsync(customer, NopCustomerDefaults.groupownerAttribute, model.groupowner);
However, sames like the new data has not been saved into the database after the above code., so when the code skip to the next step, the page will be refreshed, so the data will go back to the old value(12345) after the below code, any idea? thanks. in PrepareCustomerInfoModelAsync: //model.groupowner = await _genericAttributeService.GetAttributeAsync<string>(customer, NopCustomerDefaults.groupownerAttribute); model.groupowner = customer.groupowner;
BTW, I cannot use the below code since I have to fetch the data in the 1st time, that's why I switch to (model.groupowner = customer.groupowner;) as you said, fyi. //model.groupowner = await _genericAttributeService.GetAttributeAsync<string>(customer, NopCustomerDefaults.groupownerAttribute);
did you verify the things in the Database the changes are reflected? -- Yes I verified in the database, the value did not change, still the old value.
I am a bit confused are you store the value in the DB of the customer Table or the Generic attribute ? -- I am just using the below code in PrepareCustomerInfoModelAsync to save the data, any other method to save the data? //model.groupowner = await _genericAttributeService.GetAttributeAsync<string>(customer, NopCustomerDefaults.groupownerAttribute); model.groupowner = customer.groupowner;
my expectation is to save the data in DB, when I change the data(groupowner) in the page of "My account - Customer info", then click the button "Submit", the new data can be saved to the database. Thanks.
so in the post method, you just need to assign a model value into customer object I have already explained the flow before this 2 post inot same forum post
You need to assign model value into customer object
The result is still same as before(data did not save), after debugging, I found the code will always run into the below except. Then the code will re-fetch the data from the database, so the result is still same as below, why got this?
ForceMultiFactorAuthenticationAttribute /// <summary> /// Called asynchronously before the action, after model binding is complete. /// </summary> /// <param name="context">A context for action filters</param> /// <param name="next">A delegate invoked to execute the next action filter or the action itself</param> /// <returns>A task that represents the asynchronous operation</returns> public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { await ValidateAuthenticationForceAsync(context); if (context.Result == null) await next(); }
I am confused what you are trying to do ? There are two different ways of storing a value for a customer Do you want to store the value from model.groupowner in the customer table or as a Generic Attribute
Via debugging, after this code, I can see: customer.groupowner changed from '12345' to '55555' mode.groupowner='55555', which is what I changed from the web page.
My question is, after above code, the data has not been written to the DB.
I have verified: 1. the data has NOT been written to the DB, after: customer.groupowner= model.groupowner not sure why?
2. Attribute has been changed by the below code, I can see the value has been changed on the page after the button "Save", but the data is not in the DB. How can I save the data to DB? #1 ddid not work. await _genericAttributeService.SaveAttributeAsync(customer, NopCustomerDefaults.groupownerAttribute, model.groupowner);
As per Yidna's question, how are you trying to store the data? It seems that you are trying to put it in BOTH the Customer table backed field, and ALSO in Generic Attributes. Why?