Area: Episerver B2B Commerce

Adding handlers to return custom properties to a service

Recommended reading 

This article demonstrates how to display custom properties in the browser. This requires adding a new handler to the chain of responsibility and adding custom data to the model.

The example shows how to add an organization code custom properties to a user profile.

  1. Open Visual Studio and add a new class for the new handler.
    Name: GetAccountHandler_Custom.cs
  2. Derive from the HandlerBase<GetAccountParameter, GetAccountResult>
  3. Add an OrgCode custom property to the collection property of the return object. This can be done by using CurrentContextUserProfile.GetProperty("OrgCode")
  4. Set the Order to 600 so that the base handler is called first in the chain
    public class GetAccountHandler_Custom : HandlerBase<GetAccountParameter, GetAccountResult>
        protected readonly IAccountHelper AccountHelper;
        public GetAccountHandler_Custom(IAccountHelper accountHelper)
            this.AccountHelper = accountHelper;
        public override GetAccountResult Execute(InSite.Model.Interfaces.IUnitOfWork unitOfWork, 
    			GetAccountParameter parameter, GetAccountResult result)
    			this.CurrentContext.UserProfile.GetProperty("OrgCode", "Insite"));
            return this.NextHandler.Execute(unitOfWork, parameter, result);
        public override int Order
            get { return 600; }
  5. The code has now been complete and now the user interface needs to be updated to display the organization code. In this example we will update the existing theme but it is recommended to derive a new theme and directive.

Add the following line to the AccountSettings.cshtml directive under the <h3> at the top of the page.

  1. Rebuild the solution and view the results
  2. The OrgCode can now be managed from within the Admin Console
Do you find this information helpful? Please log in to provide feedback.

Last updated: Dec 11, 2020

Recommended reading