public bool AddPhieuDatHangNCC(PhieuDatHang_NCCViewModel model) { var tongTien = model.ChiTietPhieuDats.Sum(t => t.SL * t.GiaNhap); var phieuDat = new PHIEUDATHANG_NCC() { MANCC = model.MaNCC, NGAYDAT = DateTime.Now, NGUOIDAT = HttpContext.Current.User.Identity.Name, TONGTIEN = tongTien, TRANGTHAI = 1, }; context.PHIEUDATHANG_NCCs.Add(phieuDat); context.SaveChanges(); foreach (var detail in model.ChiTietPhieuDats) { var chiTiet = new CT_PHIEUDATNCC() { MAPHIEUDAT = phieuDat.MAPHIEUDAT, MASANPHAM = detail.MaSP, SOLUONG = detail.SL, GIANHAP = detail.GiaNhap, THANHTIEN = detail.SL * detail.GiaNhap, TRANGTHAI = 1, }; context.CT_PHIEUDATNCCs.Add(chiTiet); } context.SaveChanges(); return(true); }
// Xóa đơn đặt hàng public bool DeleteDatHangNCC(int maDatHang) { PHIEUDATHANG_NCC datHangExist = context.PHIEUDATHANG_NCCs.FirstOrDefault(t => t.TRANGTHAI == 1 && t.MAPHIEUDAT == maDatHang); if (datHangExist == null) { return(false); } datHangExist.TRANGTHAI = 0; context.SaveChanges(); return(true); }
// Không sử dụng public bool Update(PhieuDatHang_NCCViewModel model) { PHIEUDATHANG_NCC pdh = context.PHIEUDATHANG_NCCs.FirstOrDefault(t => t.MAPHIEUDAT == model.MaPhieuDat); if (pdh == null) { return(false); } pdh.MANCC = model.MaNCC; context.SaveChanges(); return(true); }
public void UpdateTrangThaiDonHang(int maDatHang) { PHIEUDATHANG_NCC datHang = context.PHIEUDATHANG_NCCs. FirstOrDefault(t => t.MAPHIEUDAT == maDatHang && t.TRANGTHAI == 3); if (datHang == null) { return; } datHang.TRANGTHAI = 2; datHang.NGAYDAT = DateTime.Now; context.SaveChanges(); }