Create Plane CRUD

Create the Plane Entity
- In '...\MyFirstProject\DotNet\MyCompany.MyFirstProject.Domain\Fleet\Entities'.
- Create empty class 'Plane.cs' and add:
// <copyright file="Plane.cs" company="MyCompany">
// Copyright (c) MyCompany. All rights reserved.
// </copyright>
namespace MyCompany.MyFirstProject.Domain.Fleet.Entities
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using BIA.Net.Core.Domain.Entity;
/// <summary>
/// The plane entity.
/// </summary>
public class Plane : BaseEntity<int>
{
/// <summary>
/// Gets or sets the id.
/// </summary>
public int Id { get; set; }
/// <summary>
/// Gets or sets the site.
/// </summary>
public virtual Airline Airline { get; set; }
/// <summary>
/// Gets or sets the site id.
/// </summary>
public int AirlineId { get; set; }
/// <summary>
/// Gets or sets the Manufacturer's Serial Number.
/// </summary>
public string Msn { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the plane is active.
/// </summary>
public bool IsActive { get; set; }
/// <summary>
/// Gets or sets the last flight date.
/// </summary>
public DateTime? LastFlightDate { get; set; }
/// <summary>
/// Gets or sets the delivery date.
/// </summary>
[Column(TypeName = "date")]
public DateTime? DeliveryDate { get; set; }
/// <summary>
/// Gets or sets the daily synchronization hour.
/// </summary>
[Column(TypeName = "time")]
public TimeSpan? SyncTime { get; set; }
/// <summary>
/// Gets or sets the capacity.
/// </summary>
public int Capacity { get; set; }
}
}
Update Data
Open the 'PlaneModelBuilder.cs' in '...\MyFirstProject\DotNet\MyCompany.MyFirstProject.Infrastructure.Data\ModelBuilders' and add :
public static void CreateModel(ModelBuilder modelBuilder)
{
...
CreatePlaneModel(modelBuilder);
}
/// <summary>
/// Create the model for planes.
/// </summary>
/// <param name="modelBuilder">The model builder.</param>
private static void CreatePlaneModel(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Plane>().HasKey(p => p.Id);
modelBuilder.Entity<Plane>().Property(p => p.Msn).IsRequired().HasMaxLength(64);
modelBuilder.Entity<Plane>().Property(p => p.IsActive).IsRequired();
modelBuilder.Entity<Plane>().Property(p => p.LastFlightDate).IsRequired(false);
modelBuilder.Entity<Plane>().Property(p => p.DeliveryDate).IsRequired(false);
modelBuilder.Entity<Plane>().Property(p => p.SyncTime).IsRequired(false);
modelBuilder.Entity<Plane>().Property(p => p.Capacity).IsRequired();
}
Update DataContext file
Open '...\MyFirstProject\DotNet\MyCompany.MyFirstProject.Infrastructure.Data\DataContext.cs' file and declare the DbSet associated to Plane:
/// <summary>
/// Gets or sets the Plane DBSet.
/// </summary>
public DbSet<Plane> Planes { get; set; }
Update the DataBase
- In VSCode (folder MyFirstProject) press F1
- Click "Tasks: Run Tasks".
- Click "Database Add migration SqlServer" if you use SqlServer or "Database Add migration PostGreSql" if you use PostGerSql.
- Set the name "NewFeaturePlane" and press enter.
- Verify new file 'xxx_NewFeaturePlane.cs' is created on '...\MyFirstProject\DotNet\MyCompany.MyFirstProject.Infrastructure.Data\Migrations' folder, and file is not empty.

- In VSCode Run and Debug "DotNet DeployDB"
- Verify 'Planes' table is created in the database.

Create the DTO
Using BIAToolKit
- Open the BIAToolKi
- Go to "Modify existing project" tab
- Set the projects parent path and choose your project
- Go to tab 3 "DTO Generator"
- Select your entity Plane on the list

- Click on "Map to" button
- Check the required checkbox for the Id, Msn, Capacity and AirlineId mapping property
- Check AirlineId as Parent Identifier
- Then click the "Generate" button
- The DTO and the mapper will be generated
- Check in the project solution if the DTO and mapper are present

Create the CRUD
Using the BIAToolKit
- Start the BIAToolKit and go on "Modify existing project" tab*
- Set the projects parent path and choose your project
- Go to tab 4 "CRUD Generator"
- Fill the fields with the corresponding informations

- Click on generate button
Launch application generation
- In VSCode Stop all debug launched.
- Run and debug "Debug Full Stack"
- The swagger page will be open.
- Open a browser at address http://localhost:4200/
- Click on "APP.PLANES" in menu to display 'Planes' page.
Complete traduction
- Open 'src/assets/i18n/app/en.json' and add:
"app": {
...,
"planes": "Planes"
},
"plane": {
"add": "Add plane",
"capacity": "Capacity",
"deliveryDate": "Delivery Date",
"edit": "Edit plane",
"isActive": "Active",
"lastFlightDate": "Last flight date",
"listOf": "List of planes",
"msn": "Msn",
"syncTime": "Synchronization time"
}
- Open 'src/assets/i18n/app/es.json' and add:
"app": {
...,
"planes": "Aviones"
},
"plane": {
"add": "Añadir avión",
"capacity": "Capacidad",
"deliveryDate": "Fecha de entrega",
"edit": "Editar avión",
"isActive": "Activo",
"lastFlightDate": "Última fecha de vuelo",
"listOf": "Lista de aviones",
"msn": "Msn",
"syncTime": "Tiempo de sincronización",
}
- Open 'src/assets/i18n/app/fr.json' and add:
"app": {
...,
"planes": "Avions"
},
"plane": {
"add": "Ajouter avion",
"capacity": "Capacité",
"deliveryDate": "Date de livraison",
"edit": "Modifier avion",
"isActive": "Actif",
"lastFlightDate": "Date du dernier vol",
"listOf": "Liste des avions",
"msn": "Msn",
"syncTime": "Heure de synchronisation"
}
Test
- Open web navigator on address: http://localhost:4200/ to display front page
- Verify 'Plane' page have the good name
- Open 'Plane' page and verify labels have been replaced too.
- Since you already created an administrator account in the CreateYourFirstCRUD part you should be able to create a new Plane by clicking on the "+" and filling the row.
