I. Add code in EnquiryModel.ts
VIII. Add code in project.component.html
<nav class="navbar">
<div class="container-fluid">
<h2>Project Enquiry Demo</h2>
<table class="table">
<thead>
<tr class="trBackground">
<th><button class="btn btn-info" type="button"
data-bs-toggle="modal" data-bs-target="#addProjectModal">Add Project</button>
<button class="btn btn-info" type="button"
data-bs-toggle="modal" data-bs-target="#addEnquiryModal">Add Enquiry</button>
</th>
</tr>
</thead>
</table>
<div>
<form [formGroup]="formValue">
<h2>Show Enquiry based on Project</h2>
<label for="Email" class="form-label">Select Project Id:</label>
<select class="form-control" #t (change)="storeChangePid(t.value)" formControlName="pid">
<!-- <option value="0">--Select--</option> -->
<option *ngFor="let proj of allProjectDetails"
value={{proj.ProjID}}>{{proj.ProjName}}
</option>
</select>
<br/>
<button type="button" class="btn btn-success" (click)="showEnquiries()">Show Enquiries</button>
<br/>
<table class="table">
<thead>
<tr class="trBackground">
<th scope="col">Name</th>
<th scope="col">Mobile No</th>
<th scope="col">Email Id</th>
<th scope="col">Project Id</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let data of EnquiryDetails">
<td>{{data.Name}}</td>
<td>{{data.MobileNo}}</td>
<td>{{data.EmailID}}</td>
<td>{{data.ProjID}}</td>
</tr>
</tbody>
</table>
</form>
</div>
<!-- Add Project Modal -->
<div class="modal fade" id="addProjectModal" tabindex="-1" aria-labelledby="projectModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="projectModalLabel">Add new Project</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form [formGroup]="formValue">
<div class="mb-3">
<label for="FName" class="form-label">Enter Project Id</label>
<input type="email" class="form-control" required formControlName="pid" id="pid" placeholder="Enter Project Id"/>
</div>
<div class="mb-3">
<label for="FName" class="form-label">Enter Project Name</label>
<input type="email" class="form-control" required formControlName="pname" id="pname" placeholder="Enter Project Name"/>
</div>
<div class="mb-3">
<label for="FName" class="form-label">Enter Project Type </label>
<input type="radio" id="ptypeo" name="ptype" value="On Going" formControlName="ptype"/>On Going
<input type="radio" id="ptypec" name="ptype" value="Comming Soon" formControlName="ptype"/>Comming Soon
</div>
</form>
{{formValue.value|json}}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-success" data-bs-dismiss="modal" (click)="addProject()">Add Project</button>
</div>
</div>
</div>
</div>
<!-- Add Enquiry Modal -->
<div class="modal fade" id="addEnquiryModal" tabindex="-1" aria-labelledby="enquiryModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="enquiryModalLabel">Add new Enquiry</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form [formGroup]="formValue">
<div class="mb-3">
<label for="EID" class="form-label">Enquiry Id</label>
<input type="number" class="form-control" required formControlName="eid" id="eid" placeholder="Enter Enquiry Id"/>
</div>
<div class="mb-3">
<label for="EName" class="form-label">Enter Name</label>
<input type="text" class="form-control" required formControlName="ename" id="ename" placeholder="Enter Name"/>
</div>
<div class="mb-3">
<label for="Mob" class="form-label">Enter Mobile No</label>
<input type="number" class="form-control" required formControlName="mob" id="mob" placeholder="Enter Mobile No"/>
</div>
<div class="mb-3">
<label for="Email" class="form-label">Enter Email No</label>
<input type="email" class="form-control" required formControlName="email" id="email" placeholder="Enter Email Id"/>
</div>
<div class="mb-3">
<label for="Email" class="form-label">Select Project Id</label>
<select id="pid" formControlName="pid">
<option value="0">--Select--</option>
<option *ngFor="let proj of allProjectDetails"
value={{proj.ProjID}}>{{proj.ProjName}}
</option>
</select>
</div>
</form>
{{formValue.value|json}}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-success" data-bs-dismiss="modal" (click)="addEnquiry()">Add Project</button>
</div>
</div>
</div>
</div>
</div>
</nav>
IX. Add code in project.component.ts
Code Snippet:-
import { Component,OnInit } from '@angular/core';
import {FormBuilder, FormGroup } from '@angular/forms';
import { ProjectModel } from 'src/ProjectModel';
import { EnquiryModel } from 'src/EnquiryModel';
import { ApiService } from '../shared/api.service';
@Component({
selector: 'app-project',
templateUrl: './project.component.html',
styleUrls: ['./project.component.scss']
})
export class ProjectComponent implements OnInit {
formValue!:FormGroup;
projectModelObject:ProjectModel=new ProjectModel();
enquiryModelObject:EnquiryModel=new EnquiryModel();
allProjectDetails:any;
EnquiryDetails:any;
constructor(private _formBuilder:FormBuilder,private _apiService:ApiService){}
ngOnInit():void{
this.formValue=this._formBuilder.group({
pid:[''],
pname:[''],
ptype:[''],
eid:[''],
ename:[''],
mob:[''],
email:[''],
});
this.getAllProject();
}
addProject(){
this.projectModelObject.ProjID=this.formValue.value.pid;
this.projectModelObject.ProjName=this.formValue.value.pname;
this.projectModelObject.ProjType=this.formValue.value.ptype;
console.log(this.projectModelObject);
this._apiService.AddNewProject(this.projectModelObject).subscribe({
next:(res)=>{console.log(res),alert('Project added successfully!'),
this.formValue.reset()},
error:(e)=>{console.log(e),alert("Error occured!")}
})
}
getAllProject(){
this._apiService.GetProjectDetails().subscribe({
next:(res)=>{this.allProjectDetails=res},
error:(e)=>{console.log(e),alert("Error occured!")}
})
}
addEnquiry(){
this.enquiryModelObject.EnquiryId=this.formValue.value.eid;
this.enquiryModelObject.Name=this.formValue.value.ename;
this.enquiryModelObject.MobileNo=this.formValue.value.mob;
this.enquiryModelObject.EmailID=this.formValue.value.email;
this.enquiryModelObject.ProjID=this.formValue.value.pid;
console.log(this.enquiryModelObject);
this._apiService.AddNewEnquiry(this.enquiryModelObject).subscribe({
next:(res)=>{console.log(res),alert('Enquiry added successfully!'),
this.formValue.reset()},
error:(e)=>{console.log(e),alert("Error occured!")}
})
}
storeChangePid(data:string){
console.log(parseInt(data));
this.enquiryModelObject.ProjID=parseInt(data);
}
showEnquiries(){
console.log(this.enquiryModelObject.ProjID);
this._apiService.GetEnquiryDetailsByPID(this.enquiryModelObject.ProjID).subscribe({
next:(res)=>{this.EnquiryDetails=res},
error:(e)=>{console.log(e),alert("Error occured!")}
})
console.log(this.EnquiryDetails);
}
}
Now we can add below data and check in MongoDB if data are saving
--To check in MongoDB
To open MongoDB
>cd C:\Users\subas.patel\Documents\Subas\Softwares\mongosh-1.6.2-win32-x64\mongosh-1.6.2-win32-x64\bin>mongosh
> use ABCBuilders
> db.ProjectInfo.find()
> db.EnquiryInfo.find()