Create your first Team
This page will explains how to create a team inside your project.
Prerequisites
Make sure to have your project created by following the steps on this page.
Create the Model
- In '...\MyFirstProject\DotNet\MyCompany.MyFirstProject.Domain' create 'Company' folder, then create a folder 'Entities' into it. Use the parent's domain existing module folder if exists.
- Create empty class 'Company.cs' and add following:
Company.cs
// <copyright file="Company.cs" company="MyCompany">
// Copyright (c) MyCompany. All rights reserved.
// </copyright>
namespace MyCompany.MyFirstProject.Domain.Company.Entities
{
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using MyCompany.MyFirstProject.Domain.User.Entities;
/// <summary>
/// The company entity.
/// </summary>
public class Company : Team
{
/// <summary>
/// Gets or sets the Id.
/// </summary>
public int Id { get; set; }
/// <summary>
/// Gets or sets the company name.
/// </summary>
public string CompanyName { get; set; }
/// <summary>
/// Add row version timestamp in table Company.
/// </summary>
[Timestamp]
[Column("RowVersion")]
public byte[] RowVersionCompany { get; set; }
}
}
- In case of children team, ensure to have logical links between the parent and child entities.
Make sure to inherit from Team
and expose a byte[]
row version property mapped to column RowVersion
.
Complete with all necessary properties.
NOTE : you should expose the Id
property even if it's hide the inherited property of Team
Complete DataContext
- Go in '...\MyFirstProject\DotNet\MyCompany.MyFirstProject.Infrastructure.Data' folder.
- Open DataContext.cs and add your new
DbSet<Company>
:
DataContext.cs
public class DataContext : BiaDataContext
{
// Existing DbSet<T>
/// <summary>
/// Gets or sets the Company DBSet.
/// </summary>
public DbSet<Company> Companies { get; set; }
}
- In folder ModelBuilders, create class CompanyModelBuilder.cs or use parent's model builder, and add :
CompanyModelBuilder.cs
namespace MyCompany.MyFirstProject.Infrastructure.Data.ModelBuilders
{
using Microsoft.EntityFrameworkCore;
using MyCompany.MyFirstProject.Domain.Company.Entities;
/// <summary>
/// Class used to update the model builder for Company domain.
/// </summary>
public static class CompanyModelBuilder
{
/// <summary>
/// Create the model for projects.
/// </summary>
/// <param name="modelBuilder">The model builder.</param>
public static void CreateModel(ModelBuilder modelBuilder)
{
CreateCompanyModel(modelBuilder);
}
/// <summary>
/// Create the model for companiess.
/// </summary>
/// <param name="modelBuilder">The model builder.</param>
private static void CreateCompanyModel(ModelBuilder modelBuilder)
{
// Use ToTable() to create the inherited relation with Team in database
modelBuilder.Entity<Company>().ToTable("Companies");
}
}
}
- If added to existing parent's model builder, add only the method
CreateCompanyModel
and make a call inside theCreateModel
method. - Back to DataContext.cs, ensure to have a call to your model builder's method
CreateModel
:
DataContext.cs
public class DataContext : BiaDataContext
{
/// <inheritdoc cref="DbContext.OnModelCreating"/>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Existing model builders
CompanyModelBuilder.CreateModel(modelBuilder);
this.OnEndModelCreating(modelBuilder);
}
}
- In case of children team, ensure to specify logical links between the parent and child entities.
Generate DTO
Using BIAToolKit
- Launch the BIAToolKit, go to the tab "Modify existing project".
- Set your parent project path, then select your project folder.
- Go to "DTO Generator" tab.
- Fill the form as following :
- Then, click on Generate button !
Children Team case
Complete the generated DTO :
- ensure to set the first
AncestorTeam
parent's type intoBiaDtoClass
class annotation - set
IsParent
to true inBiaDtoField
field annotation for parent's id property
CompanyChildDto.cs
/// <summary>
/// The DTO used to represent a company child.
/// </summary>
[BiaDtoClass(AncestorTeam = "Company")]
public class CompanyChildDto : TeamDto
{
[...]
/// <summary>
/// Gets or sets the parent's company id.
/// </summary>
[BiaDtoField(IsParent = true, Required = true)]
public int CompanyId { get; set; }
}
Generate CRUD
Using BIAToolKit
- Launch the BIAToolKit, go to the tab "Modify existing project".
- Set your parent project path, then select your project folder.
- Go to "CRUD Generator" tab.
- Fill the form as following :
- If your Team inherits from parent, click on the "Has Parent" checkbox and complete the parent's name singular and plural
- Then, click on Generate button !
Customize generated files
After the files generation, some customization is needed.
Back
Open your DotNet project solution in '...\MyFirstProject\DotNet' and complete the following files.
RoleId.cs
- Go in 'MyCompany.MyFirstProject.Crosscutting.Common\Enum' folder and open RoleId.cs file.
- Adapt the enum value of the generated value
CompanyAdmin
. - In case of children team, review the
TeamLeader
created value. Delete new generated value if already exists and in use by other teams.
TeamTypeId.cs
- Stay in 'MyCompany.MyFirstProject.Crosscutting.Common\Enum' folder and open TeamTypeId.cs file.
- Adapt the enum value of the generated value
Company
.
Front
Open your Angular project folder '...\MyFirstProject\Angular' and complete the following files.
constants.ts
- Go in 'src\app\shared' folder and open constants.ts file.
- Go in
TeamTypeId
enum declaration. - Adapt the enum value of the generated value
Company
.
navigation.ts
- Stay in 'src\app\shared' folder and open navigation.ts file.
- Adapt the path of the generated navigation for companies :
navigation.ts
{
labelKey: 'app.companies',
permissions: [Permission.Company_List_Access],
/// TODO after creation of CRUD Team Company : adapt the path
path: ['/companies'],
},
- In case of children team, you can move if needed the generated content into the children's array of parent
BiaNavigation
:
navigation.ts
{
labelKey: 'app.companies',
permissions: [Permission.Company_List_Access],
path: ['/companies'],
children: [
/// BIAToolKit - Begin Partial Navigation CompanyMaintenance
{
labelKey: 'app.company-maintenances',
permissions: [Permission.CompanyMaintenance_List_Access],
/// TODO after creation of CRUD Team Company : adapt the path
path: ['/company-maintenances'],
},
/// BIAToolKit - End Partial Navigation CompanyMaintenance
],
},
model.ts
- Go in 'src\app\features\companies\model' or the children parent's path of the generated feature
companies
and open the company.ts file. - Adapt the field configuration if needed.
- Remove all unused imports from the generated file.
Complete traductions
- Go in '...\MyFirstProject\Angular\src\assets\i18n\app'
- Complete each available language traduction JSON file with the correct values :
en.json
"app": {
//...
"companies": "companies"
},
"company": {
"add": "Add company",
"edit": "Edit company",
"listOf": "List of companies",
"headerLabel": "Company",
"admins": "Company administrators",
"filterMember": "Member user",
"goto": "View Company",
"companyName": "Company name"
},
Update the database
- Open the solution '...\MyFirstProject\DotNet\MyFirstProject.sln'.
- Open a new Package Manager Console.
- Set default project to MyCompany.MyFirstProject.Infrastructure.Data.
- Run command
add-migration -context "DataContext" AddTeamCompany
(replace Company by your new team). - Verify the generated migration.
- Run command
update-database -context "DataContext"
- Verify your database.
Testing your Team
- Run the DotNet solution.
- Launch
npm start
in Angular folder. - Go to http://localhost:4200/
- Navigate to the company team list.