If you are new to Angular 5 and ASP.NET Core, then kindly read my previous article.
In my previous article, I learned how to get started with Angular 5 and ASP.NET Core. Now, in this article, let's see in depth how to work with WEB API, EF, and perform a CRUD operation for Angular 5 and ASP.NET Core applications.
For performing CRUD operation here, I have taken the concept as an inventory Management priority Reorder level system.
Inventory management and reorder Level
Inventory management is very important to maintain and manage the stocks in small shops or a warehouse. For example, let’s consider a small shop where they sell items like toothpaste Soap, Shampoo, etc. For all the items in the shop, they will make a list with the item name and they will add the total available stock quantity for each item, Total the Sales quantity per item, and T, the total Quantity received to be added to the stock. If the items are small in number, it will be easy to find the items needed to be purchased again to maintain the stock quantity, consider if it’s a big factory and needs to maintain all the stock quantity. Using Inventory Management software, the end user can easily track Inventory items, Total available Stock Quantity, Total Arrived and Issued Stock Quantity, Reorder Level for each item, Reorder Date for each Item, and priority-based r for the items which to be stocked immediately.
Reorder level
In Inventory Management Reorder Level or Point is an important part that is used to indicate to the customer that Stock is going to be finished and needs tneeds purchased produced for sale or delivered to the end user.
Inventory Management has many processes to be taken care of to maintain the software. In this article, we will make a simple project to display the web ba web-base during the system for indicating the prior priority-based story Management Reorder System.
For Reordethe r Level, there has to be some formula for displaying the indicator on each item that is to be stocked. In our simple project, I have used the type of Priority-based indication to the customer as manual and automatic.
Note. In Inventory Management we will be having Item Man aster table, Item Detail Table, Inventory tables, and e, etc this simple project, I have used only one table as Inventan ory table and added the Item Name directly with Stock Qty, Reorder Qty and P, priority Status, Using the Priority status user can add or edit the priority for each item that to be stocked immediately. Here priority Status is to manually add or edit the priority for each item that is to be stocked.
Manual priority setting for reorder level
When customers add/edit each Inventory item they can set manually priority for reordering the stock. If you ask me what this means, Consider a case where we have 1000 stock in Samsung S7 Edge Item and let's consider this stock can be used for two months. But there is a high demand for the Samsung S7 Edge phone and the price will be increased after a week and no need to immediately increase the stock quantity . We have many branches around the world by editing the stock priority all our branches can view this from our web application and add the stock to the priority item; or let’s consider one more example as we have 1000 quantity stock and our customer makes a phone call and asks us to deliver 5000 stock quantity within a couple of days, in this case, the manual priority will be more useful. Like this, in many scenarios it's, good to have a manual priority for maintaining each item stock. This is a simple demo project so I didn’t add many field examples. We can also add the file reorder date until we need to increase the stock quantity and notes for priority etc.
Now let’s add a new Item to our Inventory and click Save. Here we didn’t check the Priority Status while adding a new Item, which means this item has good stock Quantity and it's not required for now to add more stock quantity.
We can see the Priority Status Column with red and green colors with Checked and unchecked boxes. When we add or edit the item if we have checked the Priority Status and saved then the item column will be displayed in green along with the the checkbox image. If the Item is not saved with priority status then it displays with red color. Here we used the green color to indicate the customer as this item has high priority and stock item needs to be increased with new Reorder Qty.
Now let’s edit the item and set the item with priority status.
When we save the same item with Priority Status checked, we can see the indicator with Green Color along with Checkethe d image.
Automatic priority status for reorder level
As I already told you, for reorder level we will be using the formula to indicate the customer for increasing the stock quantity with new reorder quantities.
Here we can see the Required Priority Status Column with Sky Blue and Light Green Color. Light Blue color indicates the Item is not needed for reorder and the Green color indicates the Item needs to be reordered.
For the automatic display I have,e set the formula as if StockQty>ReorderQty+50 then set the Required Priority Status as Light Blue Color which indicates the customer as the item is not needed for reorder and the ifckQty<=ReorderQty+50 then set the Required Priority Status as Light Green Color which indicates the customer as the item needed for immediate stock maintenance.
From the above image for the newly added Samsung S7 Edge Item Stock Qty is 750 and Reorder Qty is 50 so the Required Priority Status is displayed in blue color.
Now let’s edit the item like below and see the Reorder Quantity as 700 and save to check the changes.
Here now we can see the Required Priority Status color has been automatically changed as the Stock Qty is 750 and the Reorder Qty is 700.
Now let's see how to create this web application using Angular5,ASP.NET Core using EF and Web API.
Prerequisites
Make sure you have installed all the prerequisites on your computer. If not, then download and install all, one by one.
- First, download and install Visual Studio 2017 from this link.
- Download and install .NET Core 2.0
- Download and install Node.js v9.0 or above. I have installed V9.1.0 (Download link).
Code Part
Now, it’s time to create our first Angular5 and ASP.NET Core application.
Step 1. Create a database and a table
We will be using our SQL Server database for our WEB API and EF. First, we create a database named InventoryPDB and a table as InventoryMaster. Here is the SQL script to create a database table and sample record insert query in our table. Run the query given below in your local SQL Server to create a database and a table to be used in our project.
USE MASTER
GO
-- 1) Check for the Database Exists .If the database is exist then drop and create new DB
IF EXISTS (SELECT [name] FROM sys.databases WHERE [name] = 'InventoryPDB')
DROP DATABASE InventoryPDB
GO
CREATE DATABASE InventoryPDB
GO
USE InventoryPDB
GO
-- 1) //////////// StudentMasters
IF EXISTS ( SELECT [name] FROM sys.tables WHERE [name] = 'InventoryMaster' )
DROP TABLE InventoryMaster
GO
CREATE TABLE [dbo].[InventoryMaster](
[InventoryID] INT IDENTITY PRIMARY KEY,
[ItemName] [varchar](100) NOT NULL,
[StockQty] int NOT NULL,
[ReorderQty] int NOT NULL,
[PriorityStatus] int NOT NULL -- 0 for low and 1 for High
)
-- insert sample data to Student Master table
INSERT INTO [InventoryMaster] ([ItemName],[StockQty],[ReorderQty],[PriorityStatus])
VALUES ('HardDisk',500,300,0)
INSERT INTO [InventoryMaster] ([ItemName],[StockQty],[ReorderQty],[PriorityStatus])
VALUES ('Mouse',600,550,1)
INSERT INTO [InventoryMaster] ([ItemName],[StockQty],[ReorderQty],[PriorityStatus])
VALUES ('USB',3500,3000,0)
SELECT * FROM InventoryMaster
Step 2. Create Angular5 template core
After installing all the prerequisites listed above and Angular5TemplateCore, click Start >> Programs >> Visual Studio 2017 >> Visual Studio 2017, on your desktop.
Click New >> Project. Select Visual C# >> Select Angular5Core2. Enter your project name and click OK.
Once our project is created we can see in Solution Explorer with Angular5 sample components, HTML aHTMLpp in Clientthe App Folder along with Asp.NET Core Controllers and view folder.
Here these files and folders are very similar to our ASP.NET Core Template Pack for Angular2.
Package.json file
If we open the package.Json file we can see all the dependencies needed for Angular5 and Angular CLI have already been added by default.
Adding web pack in package.json
For Angular5 Application we need to install a web pack in our application. If the wepack is by default not added in our package.json file then we need to add it manually. Webpack is an open-source JavaScript module bundler. Webpack takes modules with dependencies and generates static assets representing those modules.to know more about Webpack click here.
Open our package.json file and add the below line under scripts
"post-install": "webpack --config webpack.config.vendor.js"
Step 3. Working with model and context class
Adding connection string
To add the connection string with our SQL connection, open the “appsettings.json” file . Yes, this is a JSON file and this file looks as shown below.
In this appsettings.json file, I have added the connection string
"ConnectionStrings": {
"DefaultConnection": "Server=SQLSERVERNAME;Database=InventoryPDB;user id=SQLID;password=SQLPWD;Trusted_Connection=True;MultipleActiveResultSets=true;"
}
Note. Change the SQL connection string, as per your local connection.
Next, she is to create a folder named Data to create our model and DBContext class.
Creating model c-class for inventory
We can create a model by adding a new class file in our Data folder. Right-click the Data folder and click Add>Click Class. Enter the class name as InventoryMasters and click Add. Now, in this class, we first create a property variable and add Inand ventoryMaster. We will be using this in our WEB API controller. Note that here we will be adding the filed name same as our Database table column names.
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
namespace Angular5Core2.Data
{
public class InventoryMaster
{
[Key]
public int InventoryID { get; set; }
[Required]
[Display(Name = "ItemName")]
public string ItemName { get; set; }
[Required]
[Display(Name = "StockQty")]
public int StockQty { get; set; }
[Required]
[Display(Name = "ReorderQty")]
public int ReorderQty { get; set; }
public int PriorityStatus { get; set; }
}
}
Creating database context
DBContext is an Entity Framework class to establish a connection to the database
We can create a DBContext class by adding a new class file in our Data folder. Right-click the Data folder and click Add>Click Class. Enter the class name as InventroyContext and click Add. In this class, we inherited text and created a Dbset for our students.
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Angular5Core2.Data
{
public class InventoryContext : DbContext
{
public InventoryContext(DbContextOptions<InventoryContext> options)
: base(options) { }
public InventoryContext() { }
public DbSet<InventoryMaster> InventoryMaster { get; set; }
}
}
Startup.cs
Now, we need to add our database connection string and provider as SQL SERVER. To add this, we add the code given below in Startup.cs file under the ConfigureServices method.
public void ConfigureServices(IServiceCollection services)
{
// Add Entity framework.
services.AddDbContext<InventoryContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddMvc();
}
Step 4. Creating web API for crud operation
To create our WEB API Controller, right right-clickers folder. Click Add >> Click Controller. Select API Controller Empty and click on the Add button to create our Web API.
Enter the name as “InventoryMasterAPI.cs” and click Add.
As we all know, Web API is a simple and easy way to build HTTP Services for Browsers and Mobiles.
Web API has four methods given below Getst/Put and Delete.
- Getis to request for the data. (Select)
- The post is to create data. (Insert)
- Putis to update the data.
- Deleteis to delete data.
First, we create the object for DBContext in our Web API class.
[Produces("application/json")]
[Route("api/InventoryMasterAPI")]
public class InventoryMasterAPIController : Controller
{
private readonly InventoryContext _context;
public InventoryMasterAPIController(InventoryContext context)
{
_context = context;
}
}
Get method (select operation)
Get Method is to request a single item or list of items from our selected database. Here, we will get all Inventory information from the Inventthe or Masters table.
// GET: api/InventoryMasterAPI
[HttpGet]
[Route("Inventory")]
public IEnumerable<InventoryMaster> GetInventoryMaster()
{
return _context.InventoryMaster;
}
Post method (insert operation)
Post Method will be used to insert the data into our database.In the Post Mthe method, we will also check if the Inventthe ory ID is already created and return the message. We will pass all inventory Master Column parameters to be inserted in to the Inventory Master table.
// POST: api/InventoryMasterAPI
[HttpPost]
public async Task<IActionResult> PostInventoryMaster([FromBody] InventoryMaster InventoryMaster)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_context.InventoryMaster.Add(InventoryMaster);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (InventoryMasterExists(InventoryMaster.InventoryID))
{
return new StatusCodeResult(StatusCodes.Status409Conflict);
}
else
{
throw;
}
}
return CreatedAtAction("GetInventoryMaster", new { id = InventoryMaster.InventoryID }, InventoryMaster);
}
private bool InventoryMasterExists(int id)
{
return _context.InventoryMaster.Any(e => e.InventoryID == id);
}
Put method (update operation)
Put MeThe that will be used to update the selected Inventory data to our database. In the Put Method, we will pass InventoryID along with all other parameters for update. We pass the InventoryID to update the InventoryMaster Table by InventoryID.
// PUT: api/InventoryMasterAPI/2
[HttpPut("{id}")]
public async Task<IActionResult> PutInventoryMaster([FromRoute] int id, [FromBody] InventoryMaster InventoryMaster)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (id != InventoryMaster.InventoryID)
{
return BadRequest();
}
_context.Entry(InventoryMaster).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!InventoryMasterExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
Delete method (delete operation)
Delete Method will be used to delete the selected inventory data from our database. In the Delete Method, we will pass InventoryID to delete the record.
// DELETE: api/InventoryMasterAPI/2
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteInventoryMaster([FromRoute] int id)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
InventoryMaster InventoryMaster = await _context.InventoryMaster.SingleOrDefaultAsync(m => m.InventoryID == id);
if (InventoryMaster == null)
{
return NotFound();
}
_context.InventoryMaster.Remove(InventoryMaster);
await _context.SaveChangesAsync();
return Ok(InventoryMaster);
}
To test the Get Methe method, we can run our project and copy the GET method API path. Here, we can see our API path to get api/InventoryMasterAPI/Inventory/
Run the program and paste the API path to test our output.
Step 5. Working with Angular5
We create all AngulaAngular5-related Modules, Services, Components, and HTML templates under the ClientApp/App folder.
Here I’m using the existing Home Component and html performingour Inventory CRUD operations. It will be always good to create a separate Services, Component, and HTMLfile for each action. For the demo of the project here, I’m using the existing home component and HTML.
Home.component
From the existing home component Type Script file, I have added all the functions to perform our CRUD operation for Inventory management.
First in the,e import section ha, ve added the HTTP and FormsModule for working with WEB API Get/Post/Put/Delete and Forms to get and set input from the users.
In the HomeComponent Class, I have declared all the variables needed and created the separate function for the Get/Post/Put and Delete methodmethodset method I have passed the WEB API URL to get all the data from the database se and the result JSON data to be bound in our total page. In the Post, the, and Put methods I passed all the arguments by the user entered in the form to the WEB API to perform Update and Insert in database. The same like tawse also created the delete method for deleting the inventory list from database se by passing the Inventory ID as para me ter to our Web API.
import { Component, Input, Inject } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { FormsModule } from '@angular/forms';
@Component({
selector: 'home',
templateUrl: './home.component.html'
})
export class HomeComponent {
// to get the Student Details
public Inventory: InventoryMaster[] = [];
// to hide and Show Insert/Edit
AddTable: Boolean = false;
// To stored Student Informations for insert/Update and Delete
public sInventoryID : number = 0;
public sItemName = "";
public sStockQty : number = 0;
public sReorderQty : number = 0;
public sPriorityStatus: boolean = false;
//For display Edit and Delete Images
public imgchk = require("./Images/chk.png");
public imgunChk = require("./Images/unchk.png");
public bseUrl: string = "";
public schkName: string = "";
myName: string;
constructor(public http: Http, @Inject('BASE_URL') baseUrl: string) {
this.myName = "Shanu";
this.AddTable = false;
this.bseUrl = baseUrl;
this.getData();
}
//to get all the Inventory data from Web API
getData() {
this.http.get(this.bseUrl + 'api/InventoryMasterAPI/Inventory').subscribe(result => {
this.Inventory = result.json();
}, error => console.error(error));
}
// to show form for add new Student Information
AddInventory() {
this.AddTable = true;
// To stored Student Informations for insert/Update and Delete
this.sInventoryID = 0;
this.sItemName = "";
this.sStockQty = 50;
this.sReorderQty = 50;
this.sPriorityStatus = false;
}
// to show form for edit Inventory Information
editInventoryDetails(inventoryIDs : number, itemNames : string, stockQtys : number, reorderQtys : number , priorityStatus : number) {
this.AddTable = true;
this.sInventoryID = inventoryIDs;
this.sItemName = itemNames;
this.sStockQty = stockQtys;
this.sReorderQty = reorderQtys;
if (priorityStatus == 0)
{
this.sPriorityStatus = false;
}
else {
this.sPriorityStatus = true;
}
}
// If the InventoryId is 0 then insert the Inventory infromation using post and if the Inventory id is greater than 0 then edit using put mehod
addInventoryDetails(inventoryIDs: number, itemNames: string, stockQtys: number, reorderQtys: number, priorityStatus: boolean) {
var pStatus: number = 0;
this.schkName = priorityStatus.toString();
if (this.schkName == "true") {
pStatus = 1;
}
var headers = new Headers();
headers.append('Content-Type', 'application/json; charset=utf-8');
if (inventoryIDs == 0) {
this.http.post(this.bseUrl + 'api/InventoryMasterAPI/', JSON.stringify({ InventoryID: inventoryIDs, ItemName: itemNames, StockQty: stockQtys, ReorderQty: reorderQtys, PriorityStatus: pStatus }),
{ headers: headers }).subscribe(
response => {
this.getData();
}, error => {
}
);
}
else {
this.http.put(this.bseUrl + 'api/InventoryMasterAPI/' + inventoryIDs, JSON.stringify({ InventoryID: inventoryIDs, ItemName: itemNames, StockQty: stockQtys, ReorderQty: reorderQtys, PriorityStatus: pStatus }), { headers: headers })
.subscribe(response => {
this.getData();
}, error => {
}
);
}
this.AddTable = false;
//
//
//this.http.get(this.bseUrl + 'api/InventoryMasterAPI/Inventory').subscribe(result => {
// this.Inventory = result.json();
//}, error => console.error(error));
}
//to Delete the selected Inventory detail from database.
deleteinventoryDetails(inventoryIDs: number) {
var headers = new Headers();
headers.append('Content-Type', 'application/json; charset=utf-8');
this.http.delete(this.bseUrl + 'api/InventoryMasterAPI/' + inventoryIDs, { headers: headers }).subscribe(response => {
this.getData();
}, error => {
}
);
//this.http.get(this.bseUrl + 'api/InventoryMasterAPI/Inventory').subscribe(result => {
// this.Inventory = result.json();
//}, error => console.error(error));
}
closeEdits() {
this.AddTable = false;
// To stored Student Informations for insert/Update and Delete
this.sInventoryID = 0;
this.sItemName = "";
this.sStockQty = 50;
this.sReorderQty = 50;
this.sPriorityStatus = false;
}
}
export interface InventoryMaster {
inventoryID: number;
itemName: string;
stockQty: number;
reorderQty: number;
priorityStatus: number;
}
HTML template file
Here we are using the home.component.html file to perform our CRUD operation for Inventory Management.
<div align="center">
<h1> ASP.NET Core,Angular5 CRUD for Invetory Management Priority based Reorder Level System, WEB API and EF </h1>
</div>
<div class="column">
<h2>Created by : {{myName}}</h2>
</div>
<hr style="height: 1px;color: #123455;background-color: #d55500;border: none;color: #d55500;" />
<p *ngIf="!Inventory"><em>Loading Inventory Details please Wait ! ...</em></p>
<table id="tblContainer" style='width: 99%;table-layout:fixed;'>
<tr>
<td>
<table style="background-color:#FFFFFF; border: dashed 3px #FFFFFF; padding: 5px;width: 99%;table-layout:fixed;" cellpadding="2"
cellspacing="2">
<tr style="height: 30px; color:#123455 ;border: solid 1px #659EC7;">
<td width="40px"> </td>
<td width="50%">
<h1> Add New Inventory Information <strong style="color:#0094ff"> </strong></h1>
</td>
<td align="right">
<button (click)=AddInventory() style="background-color:#f83500;color:#FFFFFF;font-size:large;width:260px;height:50px;
border-color:#a2aabe;border-style:dashed;border-width:2px;">
Add New Inventory Info
</button>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<hr style="height: 1px;color: #123455;background-color: #d55500;border: none;color: #d55500;" />
</td>
</tr>
<tr *ngIf="AddTable">
<td >
<table>
<tr>
<td>
<table style="background-color:#FFFFFF; border: dashed 3px #6D7B8D; padding :5px;width :99%;table-layout:fixed;" cellpadding="2" cellspacing="2">
<tr style="height: 30px; background-color:#336699 ; color:#FFFFFF ;border: solid 1px #659EC7;">
<td width="40">
</td>
<td>
<h2>Insert/Edit Inventory Details : </h2>
</td>
</tr>
<tr>
<td width="100">
</td>
<td>
<table style="color:#9F000F;font-size:large; padding :5px;" cellpadding="12" cellspacing="16">
<tr>
<td><b>Inventory ID: </b> </td>
<td>
<input type="number" #InventoryID (ngModel)="sInventoryID" value="{{sInventoryID}}" style="background-color:tan" readonly>
</td>
<td width="20"> </td>
<td><b>Item Name: </b> </td>
<td>
<input type="text" #ItemName (ngModel)="sItemName" value="{{sItemName}}" required>
</td>
<td></td>
</tr>
<tr>
<td><b>Stock Quantity: </b> </td>
<td>
<input type="number" #StockQty (ngModel)="sStockQty" value="{{sStockQty}}" min="50" required>
</td>
<td width="20"> </td>
<td><b>Reorder Quantity: </b> </td>
<td>
<input type="number" #ReorderQty (ngModel)="sReorderQty" value="{{sReorderQty}}" min="50" required>
</td>
<td></td>
</tr>
<tr>
<td><b>Priority Status: </b> </td>
<td>
<input type="checkbox" #PriorityStatus (ngModel)="sPriorityStatus" value="{{sPriorityStatus}}" [checked]="sPriorityStatus"
(change)="sPriorityStatus = !sPriorityStatus" >
<!--<input type="text" #chkName (ngModel)="schkName" value="{{schkName}}">-->
</td>
<td width="20"> </td>
<td align="right" colspan="2">
<button (click)=addInventoryDetails(InventoryID.value,ItemName.value,StockQty.value,ReorderQty.value,PriorityStatus.value) style="background-color:#428d28;color:#FFFFFF;font-size:large;width:220px;
border-color:#a2aabe;border-style:dashed;border-width:2px;">
Save
</button>
</td>
<td>
<button (click)=closeEdits() style="background-color:#334668;color:#FFFFFF;font-size:large;width:180px;
border-color:#a2aabe;border-style:dashed;border-width:2px;">
Close
</button>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">
<hr style="height: 1px;color: #123455;background-color: #d55500;border: none;color: #d55500;" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table class='table' style="background-color:#FFFFFF; border:2px #6D7B8D; padding:5px;width:99%;table-layout:fixed;" cellpadding="2" cellspacing="2" *ngIf="Inventory">
<tr style="height: 30px; background-color:#336699 ; color:#FFFFFF ;border: solid 1px #659EC7;">
<td width="70" align="center">Edit</td>
<td width="70" align="center">Delete</td>
<td width="70" align="center">Inventory ID</td>
<td width="120" align="center">Item Name</td>
<td width="120" align="center">StockQty</td>
<td width="120" align="center">ReorderQty</td>
<td width="120" align="center">Priority Status</td>
<td width="120" align="center">Required Priority Status</td>
</tr>
<tbody *ngFor="let INVY of Inventory">
<tr>
<td align="center" style="border: solid 1px #659EC7; padding: 5px;table-layout:fixed;">
<span style="color:#9F000F">
<button (click)=editInventoryDetails(INVY.inventoryID,INVY.itemName,INVY.stockQty,INVY.reorderQty,INVY.priorityStatus)
style="background-color:#0d254f;color:#FFFFFF;font-size:large;width:80px;
border-color:#a2aabe;border-style:dashed;border-width:2px;">
Edit
</button>
<!-- <img src="{{imgEdit}}" style="height:32px;width:32px" (click)=editStudentsDetails(StudentMasters.stdID,StudentMasters.stdName,StudentMasters.email,StudentMasters.phone,StudentMasters.address)>-->
</span>
</td>
<td align="center" style="border: solid 1px #659EC7; padding: 5px;table-layout:fixed;">
<span style="color:#9F000F">
<button (click)=deleteinventoryDetails(INVY.inventoryID)
style="background-color:#0d254f;color:#FFFFFF;font-size:large;width:80px;
border-color:#a2aabe;border-style:dashed;border-width:2px;">
Delete
</button>
<!-- <img src="{{imgDelete}}" style="height:32px;width:32px" (click)=deleteStudentsDetails(StudentMasters.stdID)>-->
</span>
</td>
<td align="center" style="border: solid 1px #659EC7; padding: 5px;table-layout:fixed;">
<span style="color:#9F000F">{{INVY.inventoryID}}</span>
</td>
<td align="left" style="border: solid 1px #659EC7; padding: 5px;table-layout:fixed;">
<span style="color:#9F000F">{{INVY.itemName}}</span>
</td>
<td align="right" style="border: solid 1px #659EC7; padding: 5px;table-layout:fixed;">
<span style="color:#9F000F">{{INVY.stockQty}}</span>
</td>
<td align="right" style="border: solid 1px #659EC7; padding: 5px;table-layout:fixed;">
<span style="color:#9F000F">{{INVY.reorderQty}}</span>
</td>
<td align="center" [ngStyle]="INVY.priorityStatus==1 && {'background-color': 'green'} || INVY.priorityStatus==0 && {'background-color': 'red'} " style="height:42px;width:42px">
<!--<span style="color:#FFFFFF">{{INVY.priorityStatus}}</span>-->
<div [ngStyle]="INVY.priorityStatus==1 && {'background-image': 'url(' + imgchk + ')'} || INVY.priorityStatus==0 && {'background-image': 'url(' + imgunChk + ')'} " style="background-repeat: no-repeat;height:38px;width:38px" >
</div>
</td>
<td align="left" [ngStyle]="INVY.stockQty>INVY.reorderQty+50 && {'background-color': '#0094ff'} || INVY.stockQty<=INVY.reorderQty+50 && {'background-color': '#e5e800'} " style="border: solid 1px #ffffff; padding: 5px;table-layout:fixed;">
<!--<span style="color:#FFFFFF">{{INVY.priorityStatus}}</span>-->
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
Manual priority setting for reorder level logic
When the user aa dds or edits the Inventory Master if the Priority Status is checked then I will insert the status as 1 in databathe se and if the Priority Status is unchecked then I will save the status as 0. In our HTML design, I will check for this PriorityStatus value and if the value is returned as 1 then I will set the table and cell background color as Green and set the image as Checked image.
<td align="center"
[ngStyle]="INVY.priorityStatus==1 && {'background-color': 'green'} || INVY.priorityStatus==0 && {'background-color': 'red'}"
style="height: 42px; width: 42px">
<!--<span style="color:#FFFFFF">{{INVY.priorityStatus}}</span>-->
<div [ngStyle]="INVY.priorityStatus==1 && {'background-image': 'url(' + imgchk + ')'} || INVY.priorityStatus==0 && {'background-image': 'url(' + imgunChk + ')'}"
style="background-repeat: no-repeat; height: 38px; width: 38px">
</div>
</td>
Automatic priority status for reorder level logic
In the Required Priority Status column, I checked for the stockQty>reorderQty+50 and if it’s true then I set the td background color as LightBlue else set the color as LightGreen.
<td align="left"
[ngStyle]="INVY.stockQty > INVY.reorderQty + 50 && {'background-color': '#0094ff'} || INVY.stockQty <= INVY.reorderQty + 50 && {'background-color': '#e5e800'}"
style="border: solid 1px #ffffff; padding: 5px; table-layout: fixed;">
<!--<span style="color:#FFFFFF">{{INVY.priorityStatus}}</span>-->
</td>
Build and run the application
Build and run the application and you can see the Home page with Inventory Management CRUD page.
Note.First, create a database and table in your SQL Server. You can run use above table creation script to create Databaa se and tables with sample Insert. Don’t forget to change the database connection string from “appsettings.json”.