Table of Contents

Class TrinityResource<TPrimaryKeyType>

Namespace
AbanoubNassem.Trinity.Resources
Assembly
AbanoubNassem.Trinity.dll

The Trinity Resource.

public abstract class TrinityResource<TPrimaryKeyType> : CanMakeComponent, ITrinityResource

Type Parameters

TPrimaryKeyType

The PrimaryKey-Type used in the Table , whether it's int or Guid etc.

Inheritance
TrinityResource<TPrimaryKeyType>
Implements
Derived
Inherited Members

Properties

Actions

The actions available for the resource.

public List<object> Actions { get; }

Property Value

List<object>

BottomWidgets

Get the bottom widgets displayed by the resource.

public List<object> BottomWidgets { get; }

Property Value

List<object>

BulkActions

The bulk actions available for the resource.

public List<object> BulkActions { get; }

Property Value

List<object>

CanCreate

Whether the user can Create a new record in the resource or not.

public virtual bool CanCreate { get; }

Property Value

bool

CanDelete

Whether the user can Delete records from the resource or not.

public virtual bool CanDelete { get; }

Property Value

bool

CanUpdate

Whether the user can Update a record in the resource or not.

public virtual bool CanUpdate { get; }

Property Value

bool

CanView

Whether the user can View the resource or not.

public virtual bool CanView { get; }

Property Value

bool

Columns

Get the columns displayed by the resource.

public List<object> Columns { get; }

Property Value

List<object>

Fields

Gets the fields of the form.

public Dictionary<string, object> Fields { get; }

Property Value

Dictionary<string, object>

The fields of the form.

Icon

The Navigation icon for the resource.

public virtual string? Icon { get; }

Property Value

string

IsCreateRequest

Whether the current request is a Create request or not.

protected bool IsCreateRequest { get; init; }

Property Value

bool

IsUpdateRequest

Whether the current request is a Update request or not.

protected bool IsUpdateRequest { get; init; }

Property Value

bool

Label

the singular displayable label of the resource.

public virtual string? Label { get; init; }

Property Value

string

Name

The resource name.

public string Name { get; init; }

Property Value

string

PluralLabel

the plural displayable label of the resource.

public virtual string? PluralLabel { get; init; }

Property Value

string

PrimaryKeyColumn

The Table primary key, to be used when Querying the records from the Table.

public virtual string PrimaryKeyColumn { get; }

Property Value

string

Schema

Get the schema displayed by the resource.

public List<object> Schema { get; }

Property Value

List<object>

ShowGridlines

Enabling showGridlines displays borders between Table cells.

public virtual bool ShowGridlines { get; }

Property Value

bool

StripedRows

Alternating rows are displayed when stripedRows property is present.

public virtual bool StripedRows { get; }

Property Value

bool

Table

The table associated with the resource in the Database.

protected virtual string? Table { get; init; }

Property Value

string

TitleColumn

The column to be used to get the single value , that should be used to represent the resource when being displayed.

public abstract string TitleColumn { get; }

Property Value

string

TopWidgets

Get the top widgets displayed by the resource.

public List<object> TopWidgets { get; }

Property Value

List<object>

TrinityForm

A reference to the current TrinityForm

protected TrinityForm TrinityForm { get; }

Property Value

TrinityForm

TrinityTable

A reference to the current TrinityTable

protected TrinityTable TrinityTable { get; }

Property Value

TrinityTable

Methods

AfterCreate(IReadOnlyDictionary<string, object?>, TPrimaryKeyType?)

Fired after inserting a new record to the Resource table.

protected virtual Task AfterCreate(IReadOnlyDictionary<string, object?> form, TPrimaryKeyType? insertedKey)

Parameters

form IReadOnlyDictionary<string, object>

The validated form used to insert the new record.

insertedKey TPrimaryKeyType

The new inserted record Id.

Returns

Task

AfterDelete(IReadOnlyList<string>, bool)

Fired after deleting the given ids from the Resource table.

protected virtual Task AfterDelete(IReadOnlyList<string> deletedIds, bool isDeletedSuccessfully)

Parameters

deletedIds IReadOnlyList<string>

The given ids used to delete the records.

isDeletedSuccessfully bool

Whether the delete was successful or not.

Returns

Task

AfterUpdate(IReadOnlyDictionary<string, object?>, IReadOnlyDictionary<string, object?>?)

Fired after updating the record in the Resource table.

protected virtual Task AfterUpdate(IReadOnlyDictionary<string, object?> oldRecord, IReadOnlyDictionary<string, object?>? newRecord)

Parameters

oldRecord IReadOnlyDictionary<string, object>

The old record value before update.

newRecord IReadOnlyDictionary<string, object>

the new record value after update.

Returns

Task

BeforeCreate(ref Dictionary<string, object?>)

Fired before inserting a new record to the Resource table.

protected virtual Task BeforeCreate(ref Dictionary<string, object?> form)

Parameters

form Dictionary<string, object>

The given form after validation.

Returns

Task

BeforeDelete(ref List<string>)

Fired before deleting the given ids from the Resource table.

protected virtual Task BeforeDelete(ref List<string> idsToBeDeleted)

Parameters

idsToBeDeleted List<string>

The given ids to be deleted.

Returns

Task

BeforeUpdate(ref Dictionary<string, object?>, IReadOnlyDictionary<string, object?>)

Fired before updating the given record with the form.

protected virtual Task BeforeUpdate(ref Dictionary<string, object?> form, IReadOnlyDictionary<string, object?> record)

Parameters

form Dictionary<string, object>

The validated form used to update the record.

record IReadOnlyDictionary<string, object>

The current record in the Database.

Returns

Task

Create()

Creates a new record in the Database based on the given Fields.

public virtual Task<object?> Create()

Returns

Task<object>

The new record if it succeeded.

Delete()

Deletes all the records from the Database based on the sent keys.

public virtual Task<object?> Delete()

Returns

Task<object>

A fresh GetTableData()

GetEditData()

Retrieves the record to be edited from the Database based on the given id in RouteValues.

public virtual Task<IDictionary<string, object?>?> GetEditData()

Returns

Task<IDictionary<string, object>>

The record to be edited from the Database.

GetRelationData()

Retrieves all the records from the Database based on the giving column key in Query.

public virtual Task<IActionResult> GetRelationData()

Returns

Task<IActionResult>

A list of all the related records.

GetTableData()

Retrieves all the records from the Database based on the Columns given.

public virtual Task<IPaginator?> GetTableData()

Returns

Task<IPaginator>

IPaginator of all the records retrieved from the Database

GetTrinityForm()

Get the form displayed by the resource.

protected virtual TrinityForm GetTrinityForm()

Returns

TrinityForm

A new TrinityForm

GetTrinityTable()

Get the Table displayed by the resource.

protected virtual TrinityTable GetTrinityTable()

Returns

TrinityTable

A new TrinityTable

HandleAction(ITrinityAction, Dictionary<string, object?>, List<string>)

Handle and Execute the action given.

public Task<object> HandleAction(ITrinityAction action, Dictionary<string, object?> form, List<string> primaryKeys)

Parameters

action ITrinityAction

The ITrinityAction given in the request.

form Dictionary<string, object>

The form values sent with the action, if any.

primaryKeys List<string>

The keys of the records to apply the action to.

Returns

Task<object>

TrinityActionResult

OnIndexQuery(ref Query)

Executes before executing resource index page query.

protected virtual void OnIndexQuery(ref Query query)

Parameters

query Query

The query being executed.

Setup()

Setup is being called on each request, once the Resource is resolved from the The IServiceProvider. Can be used to resolve extra Services or do some logic before using the Resource.

public virtual Task Setup()

Returns

Task

Update()

Updates the given record in the Database with the given Fields.

public virtual Task<object?> Update()

Returns

Task<object>

The updated record if it succeeded.

ValidateRequest(Dictionary<string, JsonElement>?, Dictionary<string, object>?)

Validate the upcoming request based on the JsonFrom sent , and the registered (Fields , or any given custom fields).

public virtual Task<Dictionary<string, object?>?> ValidateRequest(Dictionary<string, JsonElement>? jsonForm = null, Dictionary<string, object>? fields = null)

Parameters

jsonForm Dictionary<string, JsonElement>

The JsonFrom sent.

fields Dictionary<string, object>

The registered Fields in the resource, or custom fields.

Returns

Task<Dictionary<string, object>>

Null if validation failed, otherwise the validated values.