Customer Application BACKEND — Program.
cs (ALL-IN-ONE)
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
var builder = [Link](args);
// ---------- DB ----------
[Link]<AppDbContext>(o =>
[Link]("Server=.;Database=CustomerDB;Trusted_Connection=True;TrustServ
erCertificate=True;"));
// ---------- JWT ----------
var jwtKey = "SUPER_SECRET_KEY_123456789";
[Link]([Link])
.AddJwtBearer(o =>
[Link] = new TokenValidationParameters
ValidateIssuer = false,
ValidateAudience = false,
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey([Link](jwtKey))
};
});
Customer Application BACKEND — [Link] (ALL-IN-ONE)
[Link]();
[Link]();
[Link]();
[Link]();
var app = [Link]();
// ---------- MIDDLEWARE ----------
[Link]();
[Link]();
[Link](x => [Link]().AllowAnyHeader().AllowAnyMethod());
[Link]();
[Link]();
// ---------- AUTO DB ----------
using (var scope = [Link]())
var db = [Link]<AppDbContext>();
[Link]();
// ---------- USERS (DEMO) ----------
var users = new[]
new AppUser("admin","admin123","Admin"),
new AppUser("user","user123","User")
Customer Application BACKEND — [Link] (ALL-IN-ONE)
};
// ---------- LOGIN ----------
[Link]("/login", (LoginReq req) =>
var u = [Link](x => [Link] == [Link] && [Link] ==
[Link]);
if (u == null) return [Link]();
var claims = new[]
new Claim([Link], [Link]),
new Claim([Link], [Link])
};
var token = new JwtSecurityToken(
claims: claims,
expires: [Link](1),
signingCredentials: new SigningCredentials(
new SymmetricSecurityKey([Link](jwtKey)),
SecurityAlgorithms.HmacSha256)
);
return [Link](new
token = new JwtSecurityTokenHandler().WriteToken(token),
role = [Link]
});
Customer Application BACKEND — [Link] (ALL-IN-ONE)
});
// ---------- CUSTOMER APIs ----------
[Link]("/customers", async (AppDbContext db) =>
await [Link]()
).RequireAuthorization();
[Link]("/customers", async (Customer c, AppDbContext db) =>
[Link](c);
await [Link]();
return [Link](c);
}).RequireAuthorization();
[Link]("/customers/{id:int}", async (int id, AppDbContext db) =>
var c = await [Link](id);
if (c == null) return [Link]();
[Link](c);
await [Link]();
return [Link]();
}).RequireAuthorization("Admin");
[Link]();
// ---------- MODELS ----------
record LoginReq(string Username, string Password);
record AppUser(string Username, string Password, string Role);
Customer Application BACKEND — [Link] (ALL-IN-ONE)
class Customer
public int CustomerId { get; set; }
public string FullName { get; set; }
public string? Email { get; set; }
class AppDbContext : DbContext
public AppDbContext(DbContextOptions<AppDbContext> o) : base(o) { }
public DbSet<Customer> Customers => Set<Customer>();