Class LinksHelper
Helper class for links management on entities
Inheritance
Implements
Inherited Members
Namespace: SuperOffice.CRM.Entities
Assembly: SoDataBase.dll
Syntax
public abstract class LinksHelper : EntityDetailsHelper<TableRowBase, RelationsRow>, INestedPersist
Constructors
LinksHelper(TableRowBase)
Default constructor setting the link source info
Declaration
protected LinksHelper(TableRowBase sourceEntityRow)
Parameters
Type | Name | Description |
---|---|---|
TableRowBase | sourceEntityRow | The row object of the source entity |
Properties
IsDeleted
Gets a value indicating whether this instance is deleted.
Declaration
public override bool IsDeleted { get; }
Property Value
Type | Description |
---|---|
bool |
|
Overrides
SourceTableId
Helper class for links management on entities
Declaration
protected short SourceTableId { get; }
Property Value
Type | Description |
---|---|
short |
Methods
AddLinkAsync(TableRowBase, string, CancellationToken)
Adds a link relation to the entity. If the source does not match the LinkHelper source an exception is thrown.
Declaration
protected Task<RelationsRow> AddLinkAsync(TableRowBase targetEntityRow, string relationComment, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
TableRowBase | targetEntityRow | The target/destination data row |
string | relationComment | Any relation comment |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<RelationsRow> | The saved RelationsRow or null if the target did not exist |
AddLinkAsync(TableInfo, int, string, CancellationToken)
Adds a link relation to the entity. If the source does not match the LinkHelper source an exception is thrown.
Declaration
protected Task<RelationsRow> AddLinkAsync(TableInfo targetTableInfo, int targetEntityId, string relationComment, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
TableInfo | targetTableInfo | The target/destination table info |
int | targetEntityId | The target/destination entity id |
string | relationComment | Any relation comment |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<RelationsRow> |
AddLinkAsync(short, int, string, CancellationToken)
Helper class for links management on entities
Declaration
protected Task<RelationsRow> AddLinkAsync(short targetTableId, int targetEntityId, string relationComment, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
short | targetTableId | |
int | targetEntityId | |
string | relationComment | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<RelationsRow> |
AddLinksAsync(RelationsRows, CancellationToken)
Adds link relations to the entity. If the source does not match the LinkHelper source an exception is thrown.
Declaration
public virtual Task<RelationsRows> AddLinksAsync(RelationsRows relationsRows, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
RelationsRows | relationsRows | Collection of Relation Rows to save |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<RelationsRows> | The saved RelationsRows |
AddSimilarLinkAsync(RelationsRow, CancellationToken)
Add similar link
Declaration
public Task<RelationsRow> AddSimilarLinkAsync(RelationsRow relationsRow, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
RelationsRow | relationsRow | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<RelationsRow> | The new link |
CopyToAsync(LinksHelper, CancellationToken)
Remove all the links from the other LinksHelper, and create new links identical with this one.
Declaration
public Task CopyToAsync(LinksHelper otherLinksHelper, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
LinksHelper | otherLinksHelper | The links helper to apply the links on. |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task |
DeleteLinks(params int[])
Deletes the links if the link belongs to the source entity
Declaration
public virtual void DeleteLinks(params int[] linkIds)
Parameters
Type | Name | Description |
---|---|---|
int[] | linkIds |
DeleteSimilarLinkAsync(RelationsRow, CancellationToken)
Delete similar link if it exists.
Declaration
public Task DeleteSimilarLinkAsync(RelationsRow relationsRow, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
RelationsRow | relationsRow | Relations row pointing to the item to remove link to. |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task |
EditSimilarLinkAsync(RelationsRow, CancellationToken)
Edit similar link if it exists.
Declaration
public Task<RelationsRow> EditSimilarLinkAsync(RelationsRow relationsRow, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
RelationsRow | relationsRow | Relations row pointing to the item to edit. |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<RelationsRow> |
GetLinks()
Gets all links (Relation rows) that belong to the source entity
Declaration
public RelationsRows GetLinks()
Returns
Type | Description |
---|---|
RelationsRows | All links (Relation rows) that belong to the source entity |
InitializeAsync(TableRowBase)
Helper class for links management on entities
Declaration
protected Task InitializeAsync(TableRowBase sourceEntityRow)
Parameters
Type | Name | Description |
---|---|---|
TableRowBase | sourceEntityRow |
Returns
Type | Description |
---|---|
Task |
IsSameChild(RelationsRow, RelationsRow)
Two links records are equivalent if their sources and destinations match, and they refer to the same relation definition
Declaration
protected override bool IsSameChild(RelationsRow child1, RelationsRow child2)
Parameters
Type | Name | Description |
---|---|---|
RelationsRow | child1 | |
RelationsRow | child2 |
Returns
Type | Description |
---|---|
bool |
Overrides
LoadChildItemsAsync(TableRowBase, CancellationToken)
Load the Relations items, based on our (parent) table type and primary key
Declaration
public override Task LoadChildItemsAsync(TableRowBase parent, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
TableRowBase | parent | Parent on whose behalf we are loading relations |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task |
Overrides
Remarks
To support two-way links (i.e., a row in the relations table should be present in the Links collections of both the source AND the destination entity), we load in two stages. First stage is the normal left-to-right; second stage is right-to-left. In the second stage, we set the RelationsRowImplementation.SuperOffice.CRM.Rows.Implementation.RelationsRowImplementation.IsRightToLeft flag, which causes all access to the Source and Destination properties to be mirrored. In this way, we make the right-to-left links appear as though they were ordinary left-to-right links.
OnChildIdUpdate(TableRowBase, RelationsRow, bool)
Helper class for links management on entities
Declaration
protected override void OnChildIdUpdate(TableRowBase parent, RelationsRow child, bool isRemoved)
Parameters
Type | Name | Description |
---|---|---|
TableRowBase | parent | |
RelationsRow | child | |
bool | isRemoved |
Overrides
OnChildPreIdUpdate(TableRowBase, RelationsRow, bool)
Helper class for links management on entities
Declaration
protected override void OnChildPreIdUpdate(TableRowBase parent, RelationsRow child, bool isRemoved)
Parameters
Type | Name | Description |
---|---|---|
TableRowBase | parent | |
RelationsRow | child | |
bool | isRemoved |
Overrides
SetLinksAsync(RelationsRows, CancellationToken)
Sets link relations to the entity. Existing relations are deleted or updated If the source does not match the LinkHelper source an exception is thrown.
Declaration
public virtual Task SetLinksAsync(RelationsRows relationsRows, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
RelationsRows | relationsRows | Collection of Relation Rows to save |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task | The saved RelationsRows |
hasChanged(RelationsRow, RelationsRow)
Helper class for links management on entities
Declaration
protected override bool hasChanged(RelationsRow child1, RelationsRow child2)
Parameters
Type | Name | Description |
---|---|---|
RelationsRow | child1 | |
RelationsRow | child2 |
Returns
Type | Description |
---|---|
bool |