



Preview text:
lOMoAR cPSD| 58675420 LẬP TRÌNH WEB API TRÊN C# 1. Tạo project Chú ý:
Khi tạo project sẽ có sẵn swagger. Nếu không có thì thực hiện theo đường link
sau https://www.c-sharpcorner.com/article/implement-swagger-ui-with-web- api/ 2. Tạo Controller lOMoAR cPSD| 58675420
3. Khai báo chuỗi kết nối cơ sở dữ liệu lOMoAR cPSD| 58675420
Lưu ý: File cấu hình của .NET Core sử dụng định dạng json thay thế xml
Thêm chuỗi kết nối như sau: "ConnectionStrings": {
"Northwind_conn": "Data Source=DESKTOP-BJVCGJB\\SQLEXPRESS;Initial Catalog=Northwind;User
ID=sa;Password=12345678;TrustServerCertificate=True;Trusted_Connection=true" },
Viết 1 class Global.cs để viết một số method dùng chung
public static String getConnectString() {
var builder = WebApplication.CreateBuilder();
string conStr = builder.Configuration.GetConnectionString("Northwind_conn"); return conStr; } Tạo các class models lOMoAR cPSD| 58675420 public class Products { [Key]
public int ProductID { get; set; } public String
ProductName { get; set; } public int? SupplierID { get;
set; } public int? CategoryID { get; set; } public
String? QuantityPerUnit { get; set; } public decimal?
UnitPrice { get; set; } public Int16? UnitsInStock { get;
set; } public Int16? UnitsOnOrder { get; set; }
public Int16? ReorderLevel { get; set; }
public bool Discontinued { get; set; } } } public class Categories { [Key]
public int CategoryID { get; set; } public String
CategoryName { get; set; } public String? Description
{ get; set; } public byte[] Picture { get; set; } lOMoAR cPSD| 58675420 }
Mở Nuget cài các gói EntityCore Framework Tạo class DataContext
