ODataModelBuilder Action is a part of the Microsoft.AspNet.OData package library. It allows developers to define custom actions that can be executed by clients using the OData protocol.
Example 1:
public class CustomersController : ODataController { private readonly List _customers; public CustomersController() { _customers = new List { new Customer { Id = 1, Name = "John" }, new Customer { Id = 2, Name = "Mary" }, new Customer { Id = 3, Name = "Bob" } }; }
private void ApplyDiscount(int discount) { //apply the discount } }
In this example, an action named "Discount" is defined in the CustomersController. The action takes an integer parameter named "key" and an ODataActionParameters object containing the "discount" parameter. The action applies the discount to the customer with the specified ID and returns an OK response.
Example 2:
ODataModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet("Customers"); var action = builder.Entity().Action("ResetCustomers"); action.Returns(); action.Namespace = "MyNamespace"; action.Parameter("customerId"); action.AddParameter("reason");
In this example, an action named "ResetCustomers" is defined in the Customer entity. The action takes an integer parameter named "customerId" and a string parameter named "reason". The action returns a boolean value.
C# (CSharp) ODataModelBuilder.Action - 60 examples found. These are the top rated real world C# (CSharp) examples of ODataModelBuilder.Action extracted from open source projects. You can rate examples to help us improve the quality of examples.