What is CRUD?
CRUD is an acronym that stands for Create, Read, Update, and Delete. It represents the four basic operations that can be performed on data in most software development applications. These operations are the fundamental building blocks for interacting with persistent data in a database or any data storage system.
- Create (C): This operation refers to the action of adding new data to the system. It involves creating and inserting a new record or entry into the database with the specified information.
- Read (R): The read operation allows developers to retrieve or fetch existing data from the database. It involves querying the database to find and display the data that meets certain criteria or conditions.
- Update (U): With the update operation, you can modify or change the existing data in the database. Developers use this operation to update the attributes or fields of a specific record.
- Delete (D): The delete operation is used to remove data from the database. It involves permanently deleting a record or entry from the database, ensuring it is no longer accessible.
Tools
- Visual Studio Community 2022
- Visual Studio Code
- SQL Server Management Studio
Application Setup
1. Select => ASP.NET CORE WEB API => Click on the next button in the bottom right.

2. Enter the project name PaymentCard.API.

3. I am using dotnet core 7.0 for web api => click on create button.

4. Install nuget packages:
- 1) Microsoft.EntityFrameworkCore
- 2)Microsoft.EntityFrameworkCore.SqServer
- 3)Microsoft.EntityFrameworkCore.Tools
5. Right-click on the project => click on Add => create new folder, "Models".
6. Create a Model class in the Models folder => "PaymentDetail.cs".
public class PaymentDetail
{
[Key]
public int paymentId { get; set; }
[Required]
[Column(TypeName = "nvarchar(100)")]
public string cardOwnerName { get; set; } = "";
[Column(TypeName = "nvarchar(16)")]
public string cardNumber { get; set; } = "";
[Column(TypeName = "nvarchar(5)")]
public string expirationDate { get; set; } = "";
[Column(TypeName = "nvarchar(3)")]
public string securityCode { get; set; } = "";
}
7. Create a data context folder in the project, then create the "PaymentDbContext" class.
public class PaymentDbContext : DbContext
{
public PaymentDbContext(DbContextOptions options) : base(options)
{
}
public DbSet<PaymentDetail> PaymentDetails { get; set; }
}
Open the "appsettings.json" file like below.
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"PaymentConnection": "your connection string"
}
}
Now we going to confirm Paymentdbcontext in the program.cs file.
using Microsoft.EntityFrameworkCore;
using PaymentCard.API.DataContext;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<PaymentDbContext>(o => o.UseSqlServer(builder.Configuration.GetConnectionString("PaymentConnection")));
//services cors
builder.Services.AddCors(p => p.AddPolicy("corsapp", builder =>
{
builder.WithOrigins("*").AllowAnyMethod().AllowAnyHeader();
}));
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseCors("corsapp");
app.UseAuthorization();
app.MapControllers();
app.Run();
Click on Tools in the top menu => click Nuget package manager => click on Package Manager Console
for migration, use two commands.
- Add-Migration "Initial"
- Update-Database
Create Controller class in Controllers folder: PaymentDetailsController.cs.
namespace PaymentCard.API.Controllers;
[Route("api/[controller]")]
[ApiController]
public class PaymentDetailsController : ControllerBase
{
private readonly PaymentDbContext _context;
public PaymentDetailsController(PaymentDbContext context)
{
_context = context;
}
// GET: api/PaymentDetails
[HttpGet]
public async Task<ActionResult<IEnumerable<PaymentDetail>>> GetPaymentDetails()
{
if (_context.PaymentDetails == null)
{
return NotFound();
}
return await _context.PaymentDetails.ToListAsync();
}
// GET: api/PaymentDetails/5
[HttpGet("{id}")]
public async Task<ActionResult<PaymentDetail>> GetPaymentDetail(int id)
{
if (_context.PaymentDetails == null)
{
return NotFound();
}
var paymentDetail = await _context.PaymentDetails.FindAsync(id);
if (paymentDetail == null)
{
return NotFound();
}
return paymentDetail;
}
// PUT: api/PaymentDetails/5
[HttpPut("{id}")]
public async Task<IActionResult> PutPaymentDetail(int id, PaymentDetail paymentDetail)
{
if (id != paymentDetail.paymentId)
{
return BadRequest();
}
_context.Entry(paymentDetail).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!PaymentDetailExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
// POST: api/PaymentDetails
[HttpPost]
public async Task<ActionResult<PaymentDetail>> PostPaymentDetail(PaymentDetail paymentDetail)
{
if (_context.PaymentDetails == null)
{
return Problem("Entity set 'PaymentDbContext.PaymentDetails' is null.");
}
_context.PaymentDetails.Add(paymentDetail);
await _context.SaveChangesAsync();
return Ok(await _context.PaymentDetails.ToListAsync());
}
// DELETE: api/PaymentDetails/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeletePaymentDetail(int id)
{
if (_context.PaymentDetails == null)
{
return NotFound();
}
var paymentDetail = await _context.PaymentDetails.FindAsync(id);
if (paymentDetail == null)
{
return NotFound();
}
_context.PaymentDetails.Remove(paymentDetail);
await _context.SaveChangesAsync();
return NoContent();
}
private bool PaymentDetailExists(int id)
{
return (_context.PaymentDetails?.Any(e => e.paymentId == id)).GetValueOrDefault();
}
}
Finally, we created CRUD of asp.net core web API, now move to Angular application to consume API.
Open the command prompt and run the below command.

Select CSS, then press enter.

Install the toaster notification.
It is installed in the latest version, as we using angular 16.
npm i ngx-toastr
Configure toastr.css in angular.json file and add below code:
Just replace it with your code in the style.css file.
@import 'ngx-toastr/toastr';
Add the below code in your app.module.ts file.
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ToastrModule } from 'ngx-toastr';
@NgModule({
declarations: [
AppComponent,
PaymentDetailsComponent,
PaymentDetailFormComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule, // required animations module
ToastrModule.forRoot(), // ToastrModule added
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
How to Create Components, model classes, env Files, and service classes in Angular?
- ng generate component name-of-component.
- ng generate s service-name
- ng generate class ModelName
- ng generate interface ModelName
Now create a component for the Payment card application.
- ng generate component PaymentDetails
- ng generate component PaymentDetails/PaymentDetailForm
- ng generate service shared/PaymentDetail
- ng generate class shared/PaymentDetail
- ng generate environments
I have created the required files.
Open the Model class inside of the shared folder and paste the below code.
export class PaymentDetail {
paymentId:number=0;
cardOwnerName:string=""
cardNumber:string=""
expirationDate:string=""
securityCode:string=""
}
Open the index.html file and add bootstrap cdn in the head.
Open the app.module.ts file and import the FormsModule.
import { FormsModule } from '@angular/forms';
//inside of import bracketet
imports: [
BrowserModule,
HttpClientModule,
FormsModule, //forms module
],
providers: [],
bootstrap: [AppComponent]
})
Open the app.component.html file and paste the below code into your file.
<div class="container-fluid">
<div class="row">
<div class="col-6 offset-2">
<app-payment-details />
</div>
</div>
</div>
Open payment-detail-form.component.html and paste the below code.




Yogeshwar YaduwanshiPosted Aug 25, 2025, 1:30 PM
Tahir Ansari can you share source code Agular Repo and Asp.net core API
Ninad VaradePosted Dec 27, 2024, 9:43 AM
Code is not proper, it's incomplete.
vishPosted Mar 6, 2024, 10:32 AM
Error: src/app/app.component.html:5:7 - error NG8001: 'app-payment-details' is not a known element:1. If 'app-payment-details' is an Angular component, then verify that it is part of this module. 2. If 'app-payment-details' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.