-
Notifications
You must be signed in to change notification settings - Fork 2
The Intwenty DataService
The Intwenty.DataService is one of the core somponents of Intwenty. It handles all data I/O for Intwenty Applications. By using the service it's guaranteed that your application can be persisted / retrieved the same way regardless of which supported database you're using.
The Intwenty.DataService implements IIntwentyDataService and you use it by injecting it into the class / controller where you need it.
public class MyIntwentyController : Controller
{
private readonly IIntwentyModelService _modelservice;
private readonly IIntwentyDataService _dataservice;
private readonly IntwentySettings _settings;
public MyIntwentyController(IIntwentyModelService modelservice,
IIntwentyDataService dataservice,
IOptions<IntwentySettings> settings)
{
_modelservice = modelservice;
_dataservice = dataservice;
_settings = settings.Value;
}
Creates JSON for a new application, if default values is defined they are set.
{ ApplicationName:{AplicationId:10, SomeField: DefaultValue}, ApplicationSubTable1:[], ApplicationSubTable2:[] }
Saves a new or existing Intwenty Application. If state.Id is 0 a new application will be saved otherwise it will be updated. If the operation is carried out with success, a new Id is returned if the application was new. If versioning is enabled for the application a new version id is also returned. (If versioning is not enabled version 1 is always returned)
[HttpPost("/Application/API/Save")]
public JsonResult Save([FromBody] System.Text.Json.JsonElement model)
{
var state = ClientStateInfo.CreateFromJSON(model);
var res = DataRepository.Save(state);
return new JsonResult(res);
}
Deletes all application data (maintable and subtables) by id. If the application uses versioning, all versions are deleted.
- Deletes data by Id
- Parameter Id can be an Id of an application subtable row, or an application maintable Id
- Parameter dbname can be an application subtable name or main tablename
- If the dbname represents a main application table, all application data (maintable and subtables) is deleted.
- If the dbname represents an application subtable, only the subtable row that matches the id parameter is deleted.
- If the application uses versioning, all versions are deleted.
Get the latest version data for and application based on Id.
var state = new ClientStateInfo() { Id = 1782, ApplicationId = 10 };
var data = DataRepository.GetLatestVersionById(state);
return new JsonResult(data);
{"Customer: {"Id":1782,"Version":1,"OwnerId":0,"ApplicationId":10,"CreatedBy":"SYSTEM","ChangedBy":"SYSTEM","OwnedBy":"SYSTEM","CustomerId":"CUST1900","CustomerName":"John Philips","Address":"Farmersroad 15","Email":"[email protected]","Phone":"\u002B4577777777","Country":"Denmark","ZipCode":"777 88"}}}
Get the latest version data for and application based on Id.
var state = new ClientStateInfo() { ApplicationId = 10, OwnerUserId="[email protected]" };
var data = DataRepository.GetLatestVersionById(state);
return new JsonResult(data);
{"Customer: {"Id":2782,"Version":1,"OwnerId":0,"ApplicationId":10,"CreatedBy":"SYSTEM","ChangedBy":"SYSTEM","[email protected]":"SYSTEM","CustomerId":"CUST1900","CustomerName":"John Richards","Address":"Farmersroad 16","Email":"[email protected]","Phone":"\u002B4577777777","Country":"Sweden","ZipCode":"777 88"}}}
- Get a list of (latest version) application data that matches the filter specified in args.
- If there's a LISTVIEW defined for the application, the columns in the list view is returned otherwise all columns.
- This function supports paging. It returns the number of records specified in args.BatchSize
- Returns an OperationResult including a json array and the current paging rownum
- Get a list of (latest version) application data, based on OwnedBy and that matches the filter specified in args.
- If there's a LISTVIEW defined for the application, the columns in the list view is returned otherwise all columns.
- This function supports paging. It returns the number of records specified in BatchSize
- Returns an OperationResult including a json array and the current paging rownum
- Get a list of (latest version) application data.
- All columns from the application's main table is returned.
- Returns an OperationResult including a json array
- Get a list of (latest version) application data based on OwnedBy.
- All columns from the application's main table is returned.
- Returns an OperationResult including a json array
Get value domains used by UI in the application specified by application id
- Returns an OperationResult including a json array
Get all value domains used by UI in the application specified by application id
- Returns an OperationResult including a json array
Gets a list of data based on the DataView defined by args.DataViewMetaCode and that matches the filter specified in args.
- Returns an OperationResult including a json array
Gets the first record of data based on the DataView defined by args.DataViewMetaCode and that matches the filter specified in args.
- Returns an OperationResult including a json array
void LogWarning(string message, int applicationid = 0, string appmetacode = "NONE", string username = "");
void LogInfo(string message, int applicationid = 0, string appmetacode = "NONE", string username = "");
Get an object mapper that performs ORM operations regardless of the database you're using.
[DbTablePrimaryKey("Id")]
[DbTableName("myTableName")]
public class CustomObject{
[BsonId]
[AutoIncrement]
public int Id { get; set; }
public string MyProperty { get; set; }
}
IIntwentyDbORM dbstore = _dataservice.GetDbObjectMapper();
dbstore.CreateTable<CustomObject>();
var t = new CustomObject() { MyProperty = "TEST" };
dbstore.Insert(t);