Generated Code

The examples below are taken from an example database with tables like: WorkItem and WorkItemLog (similar to Order and OrderItems). The root namespace is WorkItemManager

Dataportal

  1: private static async System.Threading.Tasks.Task CRUDOperations()
  2: {
  3:   // Create new item
  4:   var workItem = new WorkItemManager.Net.Services.V1.WorkItem()
  5:   {
  6:     DisplayName = "New work item",
  7:     IsEnabled = true,
  8:   };
  9:   // Save new item to database
 10:   workItem = await workItem.SaveItemAsync();
 11:   // Get item from database
 12:   workItem = await WorkItemManager.SystemContext.Current.DataPortal.WorkItemManager.GetItemByPrimaryKeyAsync(1);
 13:   // Load child items
 14:   await workItem.LoadWorkItemLogsAsync();
 15:   // Update item
 16:   workItem.FailedExecutionCount += 1;
 17:   // Save updates to database
 18:   workItem = await workItem.SaveItemAsync();
 19:   // Delete item from database
 20:   await WorkItemManager.SystemContext.Current.DataPortal.WorkItemManager.DeleteItemByPrimaryKeyAsync(1);
 21: }
 22: 

 

Dataportal

EntityFacade

  1: private static async System.Threading.Tasks.Task EntityOperations()
  2: {
  3:   // Get item from database
  4:   var workItem = await WorkItemManager.SystemContext.Current.DataPortal.WorkItemManager.GetItemByPrimaryKeyAsync(1);
  5: 
  6:   // Copy item
  7:   var copy = WorkItemManager.SystemContext.Current.EntityFacade.WorkItemManager.Copy(workItem);
  8: 
  9:   // Copy new name to workItem
 10:   copy.Name = "New name";
 11:   WorkItemManager.SystemContext.Current.EntityFacade.WorkItemManager.Import(workItem, copy);
 12: 
 13:   // Validate item
 14:   var brokenRules = WorkItemManager.SystemContext.Current.EntityFacade.WorkItemManager.Validate(workItem);
 15: }
 16: 

 

EntityCache

  1: private static async System.Threading.Tasks.Task CacheOperations()
  2: {
  3:   // Load items into cache
  4:   await WorkItemManager.SystemContext.Current.EntityCache.LoadWorkItemCacheAsync();
  5: 
  6:   // Find item in cache using index (loads cache if it's empty)
  7:   var workItemLog = await WorkItemManager.SystemContext.Current.EntityCache.FindWorkItemLogAsync(1);
  8: 
  9:   // Same result as the statement above without index search
 10:   workItemLog = (from o in WorkItemManager.SystemContext.Current.EntityCache.WorkItemLogCache
 11:           where o.WorkItemLogId == 1
 12:           select o).FirstOrDefault();
 13: }
 14: 

 

Web Client

  1: // Get localized string
  2: alert(WorkItemManager.Globalization.ResourceManager.LoadDialog());
  3: // Make AJAX call
  4: var criteria = new Sidvall.Data.FetchListCriteria<WorkItemManager.Fields.WorkItemField, WorkItemManager.Relations.WorkItemRelation>();
  5: criteria.IncludedEntities.push(WorkItemManager.Relations.WorkItemRelation.WorkItemLogs);
  6: WorkItemManager.DataPortals.WorkItemManager.GetItems(criteria);
  7: 

Because TypeScript is used you get intellisense in Visual Studio.

Last edited Jun 26, 2014 at 11:33 AM by sidwall, version 5