Three-layer structure
.NET API + Auth + Angular
\WWWebApp -- .NET Core 5.0 Web API
Back-end / .NET Core API
Add a model using Scaffold-Dbcontext (database first ET)
Open Package Manager Console:
Scaffold-DbContext "Server=.\SQLEXPRESS2019; User ID=sa; Password=mrpresident12; database=SquibWeb;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Tables Flexpoint.Customer, Flexpoint.Driver, Flexpoint.Product, Flexpoint.Product_Warehouse, Flexpoint.Warehouse, Flexpoint.RFID, Flexpoint.Contract, Flexpoint.VehicleType, Flexpoint.Vehicle, Flexpoint.Email, Flexpoint.PermitType, Flexpoint.Settings
Models\Customer -- Company Models\Driver Models\Product Models\Product_Warehouse -- Poduct_Warehouse Models\Warehouse Models\RFID Models\Contract Models\VehicleType Models\Vehicle
Models\Email Models\PermitType Models\Settings
Create model from table: Scaffold-DbContext "Server=.\SQLEXPRESS2019; User ID=sa; Password=mrpresident12; database=SquibWeb;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Tables Flexpoint.BARLEY_PRODUCT_INFO, Flexpoint.CANOLA_PRODUCT_INFO, Flexpoint.WHEAT_PRODUCT_INFO
class SquibWebContext: connect move to class WWWebContext.cs delete class SquibWebContext.cs
Add Base Repository
Web Server->Controller->Repository->Unit of Work(DbContext)->EF database
Add: 1. Repository: BaseRepository and UnitOfWork 2. IRepository: IBaseRepository and IUnitOfWork
Add SampleRepository first, then use refoctory (Ctrl .) to generate ISampleRepository
Add AutoMapProfile
Startup.cs public IServiceProvider ConfigureServices(IServiceCollection services) { builder.RegisterModule(); builder.Populate(services); AutofacContainer = builder.Build(); }
Add Controller
BarleyProductInfo, CanolaProductInfo, WheatProductInfo
New Scaffolded / API / API Controller with read/write actions Add IRepositories
3. Add ViewModel
4. add repository (interface and service)
a. Create DriverRepository.cs in \Repositories\Repository b. Ctrl . Generate a IDriverRepository public interface IDriverRepository : IBaseRepository { } c. move to \IRepository
Add mapping in \MapProfileFormapper\AutoMapProfile.cs
CreateMap<DriverViewModel, Driver>().ReverseMap();
Front-end / Angular
Add (Generate) Service and Model class
---- goto .\src\app ----
Add component and module
---- goto .\src\app\components ----
Add the Component name into [name].module.ts (app.module.ts, it need to delete component)
import { MatDialogModule } from '@angular/material/dialog'; //if use it
declarations: [WeighingComponent]
Add route in the [name]-routing.module.ts
const routes: Routes = [ { path: '', component: WeighingComponent, data: { title: $localize
Weighing
} } ];Add content in model class
export class Weighing { Location!: number; Carrier!: string; }
Add [name]Module in the \app\app-routing.module.ts
Add url and method in the [name].service.ts
url = 'http://localhost:5000/api/'; // url = 'https://localhost:5001/api/';
constructor(private httpClient: HttpClient) { }
getAllWeighings(): Observable<any[]> { var data = this.httpClient.get<Weighing[]>(this.url + 'displayweight'); // .pipe(map((res: Weighing[]) => res)); return data; }
Add method in the [name].components.ts
constructor(private weighingService: WeighingService) {
}
ngOnInit(): void { this.weighingService.getAllWeighings().subscribe((res:any) => { this.WeighingList = res; }, error => { console.log("retrive weighing list error"); }); }
Add routing in app-routing.module.ts
{ path: 'weighing', loadChildren: () => import('./components/weighing/weighing.module').then((m) => m.WeighingModule) },
add Modul in [name].module.ts if using MatDialog
Can't bind to 'formGroup' since it isn't a known property of 'form'
import { MatDialogModule } from '@angular/material/dialog';
[name].service.ts
import { environment } from 'src/environments/environment'; import { Inject, Injectable } from '@angular/core';
rootURL = environment.backEndAPIEndpoint;
add route in \containers_nav.ts
children: [ { name: 'Customer', url: '/customer', },
publish: https://www.c-sharpcorner.com/article/easily-deploy-angular-app-to-azure-from-visual-studio-code/
npm install ngx-toastr --save npm install @angular/animations --save
Last updated