0% found this document useful (0 votes)
8 views2 pages

Câu 1

The document outlines a web API for managing student records, including functionalities to list all students, filter by class, find a student by ID, add, update, and delete student records. It also configures JSON serialization settings and modifies web server modules. The API routes are defined for each operation, ensuring proper handling of HTTP requests.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Câu 1

The document outlines a web API for managing student records, including functionalities to list all students, filter by class, find a student by ID, add, update, and delete student records. It also configures JSON serialization settings and modifies web server modules. The API routes are defined for each operation, ensuring proper handling of HTTP requests.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

GlobalConfiguration.Configuration.Formatters.

JsonFormatter
.SerializerSettings.ReferenceLoopHandling
= Newtonsoft.Json.ReferenceLoopHandling.Ignore;
GlobalConfiguration.Configuration.Formatters.Remove
(GlobalConfiguration.Configuration.Formatters.XmlFormatter);
------
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/> <!-- ADD THIS -->
</modules>
</system.webServer>

Câu 1
Truonghoc db = new Truonghoc();
-------Hiển thị-----------
[HttpGet]
[Route("api/default/listSV")]
public List<sinhvien> listAll()
{
return db.sinhviens.ToList();
}
-------Hiển thị theo danh sách lớp---------
[HttpGet]
[Route("api/default/danhsachtheolop")]
public List<sinhvien> Danhsachtheolop(int malop)
{
return db.sinhviens.Where(sv => sv.malop == malop).ToList();
}
-------Tìm------------------
[HttpGet]
[Route("api/default/tim")]
public sinhvien Danhsachtheomasv(int masv)
{
return db.sinhviens.SingleOrDefault(sv => sv.masv == masv);
}

-----------Thêm--------------
[HttpPost]
[Route("api/default/themsv")]
public bool themSV([FromBody] sinhvien s)
{
try
{
db.sinhviens.Add(s);
db.SaveChanges();
return true;
}
catch (Exception ex)
{
Console.WriteLine("Lỗi ở đây: " + ex.Message);
return false;
}
}

---------- Sửa--------------
[HttpPut]
[Route("api/default/sua")]
public bool sua([FromBody] sinhvien s)
{
try
{
sinhvien old = db.sinhviens.SingleOrDefault(sv => sv.masv == s.masv);
old.hoten = s.hoten;
old.diachi = s.diachi;
old.dienthoai = s.dienthoai;
old.anh = s.anh;
old.malop = s.malop;
db.SaveChanges();
return true;
}
catch (Exception ex)
{
Console.WriteLine("Lỗi ở đây: " + ex.Message);
return false;
}
}

-----------Xoá-------------
[HttpDelete]
[Route("api/xoa")]
public bool xoa(int masv)
{
sinhvien sv = db.sinhviens.SingleOrDefault(x => x.masv == masv);
if(sv != null)
{
db.sinhviens.Remove(sv);
db.SaveChanges();
return true;
}
return false;
}
----- ds lop--------
[HttpGet]
[Route("api/default/dslop")]
public List<lophoc> DSLop()
{
return db.lophocs.ToList();
}
}

You might also like