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

Code WebAPI Bai5

Uploaded by

hoanganh123qwea
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Code WebAPI Bai5

Uploaded by

hoanganh123qwea
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

using TaoWebAPI.

Models;
namespace [Link]
{
public class SanPhamController : ApiController
{
CSDLTestEntities db = new CSDLTestEntities2();

[HttpGet]//Lấy dữ liệu
public List<SanPham> LaySP()
{
return [Link]();
}
[HttpGet]
public List<SanPham> TimSPTheoDanhMuc(int madm)
{
return [Link](x => [Link] == madm).ToList();
}
[HttpGet]
public SanPham TimSPTheoMa(int ma)
{
return [Link](x => [Link] == ma);
}
[HttpPost]//Thêm dữ liệu
public bool ThemMoi(int ma, string ten, int gia, int madm)
{
SanPham sp = [Link](x => [Link]== ma);
if (sp == null)
{
SanPham sp1 = new SanPham();
[Link] = ma;
[Link] = ten;
[Link] = gia;
[Link] = madm;
[Link](sp1);
[Link]();
return true;
}
return false;
}
[HttpPut]//Sửa dữ liệu
public bool CapNhat(int ma, string ten, int gia, int madm)
{
SanPham sp = [Link](x => [Link] == ma);
if (sp != null)
{
[Link] = ma;
[Link] = ten;
[Link] = gia;
[Link] = madm;
[Link]();
return true;
}
return false;
}
[HttpDelete]//Xóa dữ liệu
public bool xoa(int id)
{
SanPham sp = [Link](x => [Link] == id);

1
if (sp != null)
{
[Link](sp);
[Link]();
return true;
}
return false;
}
}
}

using [Link];

namespace [Link]
{
public class DanhMucController : ApiController
{
CSDLTestEntities db = new CSDLTestEntities2();

[HttpGet]//Lấy dữ liệu
public List<DanhMuc> LayDM()
{
return [Link]();
}
}
}

You might also like