public bool delete(String id) { using (CellphoneComponentEntities db = new CellphoneComponentEntities()) { ChiTietPhieuDatHang chiTietPhieuDatHang = (from item in db.ChiTietPhieuDatHangs where item.MaChiTietPhieuDat == id select item).SingleOrDefault(); db.ChiTietPhieuDatHangs.Remove(chiTietPhieuDatHang); if (db.SaveChanges() > 0) { return(true); } return(false); } }
public bool insert(DTO_ChiTietPhieuDatHang obj) { using (CellphoneComponentEntities db = new CellphoneComponentEntities()) { var resultMaHangHoa = db.Database .SqlQuery <String>("select MaHangHoa from dbo.HangHoa where TenHangHoa = N'" + obj.TenHangHoa + "'") .FirstOrDefault(); ChiTietPhieuDatHang chiTietPhieuDatHang = new ChiTietPhieuDatHang(); chiTietPhieuDatHang.MaChiTietPhieuDat = obj.MaChiTietPhieuDat; chiTietPhieuDatHang.MaHangHoa = resultMaHangHoa; chiTietPhieuDatHang.MaPhieuDatHang = obj.MaPhieuDatHang; chiTietPhieuDatHang.SoLuong = obj.SoLuong; chiTietPhieuDatHang.Gia = obj.Gia; chiTietPhieuDatHang.ThanhTien = obj.ThanhTien; db.ChiTietPhieuDatHangs.Add(chiTietPhieuDatHang); if (db.SaveChanges() > 0) { return(true); } return(false); } }