Add handlers to return custom properties to a service
Describes how to add handlers to return custom properties.
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.
-
Open Visual Studio and add a new class for the new handler.
Name:GetAccountHandler\_Custom.cs
-
Derive from the
HandlerBase<GetAccountParameter, GetAccountResult>
. -
Add an
OrgCode
custom property to the collection property of the return object. This can be done by usingCurrentContextUserProfile.GetProperty("OrgCode")
. -
Set the Order to 600 so that the base handler is called first in the chain.
[DependencyName("GetAccountHandler_Custom")] 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) { result.Properties.Add("OrgCode", this.CurrentContext.UserProfile.GetProperty("OrgCode", "Insite")); return this.NextHandler.Execute(unitOfWork, parameter, result); } public override int Order { get { return 600; } } }
-
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.<h4>{{vm.account.properties['OrgCode']}}</h4>
-
Rebuild the solution and view the results. The
OrgCode
can now be managed from within the Admin Console
Updated over 1 year ago