Extend a Retail Server OData controller


This topic applies to Dynamics 365 for Retail and Dynamics 365 for Finance and Operations.

This topic provides code that extends the CustomersController class.

A controller is a mapping for a commerce entity that controls create, read, update, and delete (CRUD) behaviors and actions for a commerce entity type. Each commerce entity must have a corresponding controller. You can extend a controller that is included with Microsoft Dynamics 365 for Retail to add new business actions that meet your business requirement. To extend an existing controller, you must define a new class that extends an existing controller class. When you create a new controller that extends an existing controller, the new controller can create new or override existing methods in the controller that is being extended. All methods in the extended controller that have not been overridden will continue to function as before. In this example, the ExtendedCustomersController class extends the CustomersController class, and the CustomersController class is the controller for the Customers entity type. You will need to update the extensionComposition section of the Retail Server Web.config file. For more information, see the How to call the new retail server API from MPOS/Cloud POS section of Commerce runtime (CRT) and Retail Server extensibility. You can find the sample code from this topic in the Retail software development kit (SDK).

using System.Web.Http;
using System.Web.OData;
using Microsoft.Dynamics.Commerce.Runtime;
using Microsoft.Dynamics.Commerce.Runtime.DataModel;
using Microsoft.Dynamics.Retail.RetailServerLibrary;
using Microsoft.Dynamics.Retail.RetailServerLibrary.ODataControllers;
namespace Microsoft.Dynamics.RetailServer.ExtensionSamples
	class ExtendedCustomersController : CustomersController
	    [CommerceAuthorization(new string[] { "Employee", "Application" })]
	    public override PageResult<GlobalCustomer> Search(ODataActionParameters parameters)
	        ThrowIf.Null<ODataActionParameters>(parameters, nameof(parameters));
	        parameters["customerSearchCriteria"] += " My custom criteria";
	        return base.Search(parameters);