public static void UpdateCtPhieuNhap(this CtPhieuNhap ctPhieuNhap, CtPhieuNhapViewModel ctPhieuNhapVm) { ctPhieuNhap.Id = ctPhieuNhapVm.Id; ctPhieuNhap.IdPhieuNhap = ctPhieuNhapVm.IdPhieuNhap; ctPhieuNhap.IdSach = ctPhieuNhapVm.IdSach; ctPhieuNhap.SoLuongNhap = ctPhieuNhapVm.SoLuongNhap; ctPhieuNhap.ThanhTien = ctPhieuNhapVm.ThanhTien; ctPhieuNhap.DonGiaNhap = ctPhieuNhapVm.DonGiaNhap; }
public ActionResult ThemChiTietPhieuNhap(PhieuNhapViewModel pnViewModel, string TenSach) { if (ModelState.IsValid) { var sach = sachService.GetSingleByName(TenSach); if (sach == null) { ModelState.AddModelError("", "Thông tin sách không tồn tại."); } else { var dsSachCuaNXB = sachService.GetAllByIdNXB(pnViewModel.IdNXB).ToList(); var tonTaiSachNXB = dsSachCuaNXB.Find(X => X.Id == sach.Id); if (tonTaiSachNXB == null) { ModelState.AddModelError("", "Thông tin sách không thuộc nhà xuất bản hiện tại."); } else { // Set Id was found into IdSach of ctPhieuNhap pnViewModel.ctPhieuNhap.IdSach = sach.Id; // Create a entity model and insert into db var newCtPhieuNhapVm = new CtPhieuNhapViewModel(); newCtPhieuNhapVm = pnViewModel.ctPhieuNhap; newCtPhieuNhapVm.ThanhTien = newCtPhieuNhapVm.SoLuongNhap * newCtPhieuNhapVm.DonGiaNhap; newCtPhieuNhapVm.Sach = Mapper.Map <Sach, SachViewModel>(sach); var sachDaNhap = ((List <CtPhieuNhapViewModel>)Session["dsCtPhieuNhap"]).Find(x => x.IdSach == newCtPhieuNhapVm.IdSach); if (sachDaNhap == null) { pnViewModel.ctPhieuNhap = null; ((PhieuNhapViewModel)Session["PhieuNhap"]).TongTien += newCtPhieuNhapVm.ThanhTien; ((PhieuNhapViewModel)Session["PhieuNhap"]).TongSoLuong += newCtPhieuNhapVm.SoLuongNhap; ((List <CtPhieuNhapViewModel>)Session["dsCtPhieuNhap"]).Add(newCtPhieuNhapVm); TempData["Success"] = "Đã lưu thành công một chi tiết."; return(Redirect("them-chi-tiet/")); } else { ModelState.AddModelError("", "Mã sách đã được thêm vào danh sách chi tiết rồi."); } } } } return(View(pnViewModel)); }