Adding New Entities and Child Tables
This membership isn't free! Let's create a Membership Payment
entity to track all the payments related to a Member.
In this section, you'll learn how to:
- Create a New Entity
- Create a Migration Class
- Configure a Child Table
- Configure a Filter for the Table
- Implement a Script to Call an Endpoint
Create a New Entity
- Navigate to
Shesha.Membership.Domain
>Domain
- Right click on the
Domain
folder,Add
>Class
- Give your class the name of:
MembershipPayment.cs
, and click onAdd
This is how your class should be constructed:
using Abp.Domain.Entities.Auditing;
using Shesha.Domain.Attributes;
using System;
namespace Shesha.Membership.Domain.Domain
{
/// <summary>
/// A member's membership payment
/// </summary>
[Entity(TypeShortAlias = "Mem.MembershipPayment")]
public class MembershipPayment : FullAuditedEntity<Guid>
{
/// <summary>
/// The unique member
/// </summary>
public virtual Member Member { get; set; }
/// <summary>
/// The payment amount
/// </summary>
public virtual double Amount { get; set; }
/// <summary>
/// The date when the payment was made
/// </summary>
public virtual DateTime? PaymentDate { get; set; }
}
}
Create a Migration Class
- Navigate to
Shesha.Membership.Domain
>Migrations
- Right click on the
Migrations
folder,Add
>Class
- Create a new migration class with a file name following this format: M[YEAR][MONTH][DAY][HOUR][MINUTE][SECONDS].cs e.g. M20231124090300.cs for 24 November 2023 08:53:00.
- Add the below code:
using FluentMigrator;
using Shesha.FluentMigrator;
using System;
namespace Shesha.Membership.Domain.Migrations
{
[Migration(20231124090300)]
public class M20231124090300 : Migration
{
/// <summary>
/// Code to execute when executing the migrations
/// </summary>
public override void Up()
{
Create.Table("Mem_MembershipPayments")
.WithIdAsGuid()
.WithFullAuditColumns()
.WithForeignKeyColumn("MemberId", "Core_Persons").Nullable()
.WithColumn("Amount").AsDouble().Nullable()
.WithColumn("PaymentDate").AsDateTime().Nullable();
}
/// <summary>
/// Code to execute when rolling back the migration
/// </summary>
public override void Down()
{
throw new NotImplementedException();
}
}
}
You can check out Fluent Migrator for more options about database migrations.
- You can run your application by going to the menu and selecting
Debug
>Start Debugging
or by clickingF5
- The application should open in your browser on the default Swagger API page.
- Search and navigate to the
Member
endpoints that have been dynamically created by Shesha.
Read more about dynamic APIs here
Updating Configurations
Details View
- Navigate to the
member-details
form designer - Search and drag in a
Datatable Context
component from theBuilder Widgets
below the existingdetails
panel
You can find more information about implementation of the Datatable Context component here
- Set the
Entity Type
property of theDatatable Context
to the newly createdMembership Payment
entity
- Search and drag in a
Panel
component from theBuilder Widgets
onto theDatatable Context
- Give the panel component a label of
Member Payments
You can find more information about implementation of the Panel component here
-
Search and drag in a
Datatable
component from theBuilder Widgets
onto thePanel
-
Configure columns with the following information:
Type Property Name Caption Create Component CRUD Operations N/A leave empty N/A Data amount Amount Number Field Data paymentDate Payment Date Date Field
- Click
save
on theconfigure columns
modal.
You can find more information about implementation of the Datatable component here
Taking full advantage of Shesha's datatable functionalities, we are going to be utilizing the inline-editing to input the Member Payments
.
Check out the inline-editing how-to-guide
- Update the
datatable
configuration to the following:
- Can add inline:
Yes
- New row init:
return {
member: form.data.id,
};
Let's accessorize our datatable
and make it more flexible.
- Search and drag in the following components from the
Builder Widgets
onto the the header of theMember Payments
panel:
- Select the
Table View Selector
component and update the filter configurations to look like this:
This filters all the membership payments
to only show payments of the member whose details we are viewing.
- Save your filter and toggle the
Hidden
property totrue
- Save your form
- Using the main menu, navigate to the
members-table
and refresh your page to make sure your changes have taken effect. - Drill down into the
details view
of your recently created member. - Create a
Membership Payment