Customer Application using .
NET and SQL Server
using [Link];
var builder = [Link](args);
// SQL Server connection
[Link]<AppDbContext>(options =>
[Link](
"Server=.;Database=CustomerDB;Trusted_Connection=True;TrustServerCertificate=Tru
e;"
));
[Link]();
[Link]();
var app = [Link]();
// Auto-create database
using (var scope = [Link]())
var db = [Link]<AppDbContext>();
[Link]();
[Link]();
[Link]();
// --------- CRUD ENDPOINTS ---------
Customer Application using .NET and SQL Server
// GET all customers
[Link]("/customers", async (AppDbContext db) =>
await [Link]());
// GET customer by id
[Link]("/customers/{id:int}", async (int id, AppDbContext db) =>
await [Link](id)
is Customer c ? [Link](c) : [Link]());
// CREATE customer
[Link]("/customers", async (Customer customer, AppDbContext db) =>
[Link](customer);
await [Link]();
return [Link]($"/customers/{[Link]}", customer);
});
// UPDATE customer
[Link]("/customers/{id:int}", async (int id, Customer input, AppDbContext db) =>
var customer = await [Link](id);
if (customer is null) return [Link]();
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
Customer Application using .NET and SQL Server
await [Link]();
return [Link]();
});
// DELETE customer
[Link]("/customers/{id:int}", async (int id, AppDbContext db) =>
var customer = await [Link](id);
if (customer is null) return [Link]();
[Link](customer);
await [Link]();
return [Link]();
});
[Link]();
// ---------- MODELS & DB CONTEXT ----------
class Customer
public int CustomerId { get; set; }
public string FullName { get; set; }
public string? Email { get; set; }
public string? Phone { get; set; }
public string? Address { get; set; }
public DateTime CreatedDate { get; set; } = [Link];
}
Customer Application using .NET and SQL Server
class AppDbContext : DbContext
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
public DbSet<Customer> Customers => Set<Customer>();