/// <reference path="../tsfiles/jquery.d.ts" /> /// <reference path="../tsfiles/ej.web.all.d.ts" /> class CustomerService { private content: HTMLElement; private grid: ej.Grid; constructor(content: HTMLElement) { this.content = content; } initGrid() { const customerDataManager = new ej.DataManager({ url: "api/Customers", adaptor: new ej.WebApiAdaptor() }); const subscriptionDataManager = new ej.DataManager({ url: "api/Subscriptions", adaptor: new ej.WebApiAdaptor() }); this.grid = new ej.Grid(this.content, { dataSource: customerDataManager, childGrid: { dataSource: subscriptionDataManager, queryString: "id", allowSorting: true, allowGrouping: true, groupSettings: { showToggleButton: true }, columns: [ { field: "entitlement_id", headerText: "Subscription ID" }, { field: "meter_category", headerText: "Category"}, { field: "meter_name", headerText: "Naam" }, { field: "usage_start_time", headerText: "Start verbruik" }, { field: "usage_end_time", headerText: "Einde verbruik" }, { headerText: "Verbruik", template: "{{:quantity}} ({{:unit}})" } ] }, allowFiltering: true, allowSorting: true, columns: [ { field: "id", isPrimaryKey: true, visible: false }, { field: "companyProfile.companyName", headerText: "Naam" }, { field: "companyProfile.domain", headerText: "Domein"}, { field: "companyProfile.tenantId", headerText: "Tenant" }, { field: "relationshipToPartner", headerText: "Relatie" } ] }); } } |
// create a Sorting class
public class Sort
{
public string direction { get; set; }
public string name { get; set; }
}
// here we can pass the paremeter
[HttpPost, Route("api/Subscriptions")]
public async Task<object> Subscriptions(int skip, int take, List<Sort> sorted, List<string> group)
{
//we can get the child query string filter value from filter parameters
// for paging we can also get the skip and take value from ski and take paramete
// Code something
return new { result = subscriptions, count = subscriptions.Count };
}
|
[HttpGet, Route("api/Customers")] public async Task<object> Customers() { var customers = await _customerService .GetCustomersAsync(); return new { result = customers, count = customers.Count }; } [HttpGet, Route("api/Subscriptions")] public async Task<object> Subscriptions() { var filter = HttpContext.Request.Query["$filter"]; if (string.IsNullOrEmpty(filter)) return NoContent(); var filterArray = filter.ToString().Split(' '); if (filterArray.Length < 3) return NoContent(); var tenantId = filterArray[2].TrimStart("guid'".ToCharArray()).TrimEnd("'}".ToCharArray()); var subscriptions = await _subscriptionService .GetSubscriptionsForCustomerAsync(tenantId); var saToken = await _authenticationService.GetCrestAccessToken(User); var totalUsageRecords = new List<UsageRecord>(); foreach (var subscription in subscriptions) { var usageRecords = await _usageService.GetUsageRecordsForSubscription( subscription.Id, DateTime.Today.AddDays(-7), DateTime.Today, saToken); totalUsageRecords.AddRange(usageRecords); } return new { result = totalUsageRecords, count = totalUsageRecords.Count }; } |
[HttpGet, Route("api/Customers")] public async Task<object> Customers( Boolean requiresCounts) { var customers = await _customerService .GetCustomersAsync(); return requiresCounts ? new { result = customers, count = customers.Count }: customers as Object; } |