public void MuonSach(int id, MuonSachModel model) { var entity = new MuonTraSach() { SachId = id, DocGiaId = model.DocGiaId, // SachId = model.SachId, NgayMuon = model.NgayMuon }; var docGia = _docGiaRepository.Get(model.DocGiaId); _muonTraSachRepository.Insert(entity); docGia.SoSachDangMuon += 1; _docGiaRepository.Update(docGia); }
public IActionResult BorrowBooks(int id, MuonSachModel model) { //var sach = _sachService.GetById(id); //if (sach == null) //{ // return RedirectToAction("Index","Sach"); //} if (ModelState.IsValid) { // model.SachId = id; if (!_sachService.CheckSoSach(model.DocGiaId)) { ModelState.AddModelError("", "Mượn quá số sách quy định.Vui lòng trả sách trước khi mượn"); } else { _sachService.MuonSach(id, model); return(RedirectToAction("Index", "Sach")); } } return(View(model)); }