-
Notifications
You must be signed in to change notification settings - Fork 804
Methodic How To VR Architect's How To List
The goal of this is to document code blocks into re-usable snippets that can be used to accomplish a task.
In order to quickly conduct a search and replace, I use a set of naming conventions in the snippets in this document.
- "Parent" defines a table in a database which has a primary key assigned to it.
- "Child" defines a table in a database with it's own primary key AND a foreign key to a parent table.
- "Module" is the name of the module in Serenity's folder structure. This is used typically in namespaces
- "Project" is the name of the project's root namespace
Capitalization: If the code snippet uses a lowercase or uppercase for the name of one of the above, make sure to use the same case when replacing the values.
Example:
- If your main table was called "Order", your project was called "Acme", and your module was called "Northwinds" then you wanted to replace a namespace of "Project.Module.Parent" then it would become "Acme.Northwinds.Order"
File names are prefixed with an asterisk so you should replace the asterisk with the name of your Parent. For example, *Dialog.ts or *Grid.ts would become OrderDialog.ts and OrderGrid.ts
After following the main Serenity Guide on setting up a multi-tenant project.
- Ensure the parent table has a column called TenantId with a data type of int and set to not null
- Using sergen, create the child table's forms
- In Module\Parent\*Row.cs file add:
...
using Project.Administration;
using Project.Administration.Entities;
...
..., IMultiTenantRow
...
[Insertable(false), Updatable(false), ReadPermission(AdminPermissionKeys.Tenants)]
public Int32? TenantId
{
get { return Fields.TenantId[this]; }
set { Fields.TenantId[this] = value; }
}
public Int32Field TenantIdField
{
get { return Fields.TenantId; }
}
...
- To hide the tenant on Module\Parent*Form.cs from none-Admins:
- In Module\Parent\*Dialog.ts file add:
// Hide TenantId unless have permission
protected getPropertyItems() {
var items = super.getPropertyItems();
if (!Q.Authorization.hasPermission("Administration:Tenants"))
items = items.filter(x => x.name != Project.Administration.ParentRow.Fields.TenantId);
return items;
}
- In Module\Parent\*Row.cs file add:
...
using Project.Administration;
...
[ReadPermission(AdminPermissionKeys.Tenants)]
public Int32? TenantId
...
- To the child being looked up, add a lookup script definition to the top of the Module\Child\*Row.cs file:
- If the child being looked up is not multi-tenant:
...
[LookupScript("Module.Child")]
public sealed class ChildRow : Row, IIdRow, INameRow
{
...
- If the child being looked up is multi-tenant:
...
[LookupScript("Module.Child", LookupType = typeof(MultiTenantRowLookupScript<>))]
public sealed class ChildRow : Row, IIdRow, INameRow, IMultiTenantRow
{
...
- To the parent which is using the child lookup add to the Module\Parent\*Row.cs file:
...
[LookupEditor(typeof(ChildRow), InplaceAdd = false)]
...
Set the InplaceAdd to true if you want the user to be able to see a button next to the editor so they can add a new child record. Set it to false to not show such a button. Note that permissions can also be set as to when the button is shown.
Copyright © Serenity Platform 2017-present. All rights reserved.
Documentation | Serene Template | Live Demo | Premium Support | Issues | Discussions