public BookCheckInVIewModel GetCheckInViewModel(int bookID) { var bookEntity = unitOfWork.BookRepository.GetByID(bookID); var lastBookAssignation = unitOfWork.BookAssignationRepository.Get(null, null, "AssignedPerson") .Where(x => x.BookID == bookID) .OrderByDescending(x => x.CheckOutDate).FirstOrDefault(); BookCheckInVIewModel model = new BookCheckInVIewModel() { BoookID = bookID, AssinationID = lastBookAssignation.ID, ActualReturnDate = DateTime.Now, AssignedPerson = new AssignedPersonViewModel() { MobileNumber = lastBookAssignation.AssignedPerson.MobileNumber, NationalID = lastBookAssignation.AssignedPerson.NationalID, PersonName = lastBookAssignation.AssignedPerson.PersonName }, RequiredReturnDate = lastBookAssignation.CheckOutDate, Penality = calculatePanelity(lastBookAssignation.CheckOutDate) }; return(model); }
public ActionResult CheckIn(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BookCheckInVIewModel checkin = bookBusinessProvider.GetCheckInViewModel(id.Value); if (checkin == null) { return(HttpNotFound()); } return(View(checkin)); }
public void AddCheckIn(BookCheckInVIewModel model) { var bookEntity = unitOfWork.BookRepository.GetByID(model.BoookID); var lastBookAssignation = unitOfWork.BookAssignationRepository.GetByID(model.AssinationID); if (bookEntity.CheckInCheckOut == Common.Enum.CheckInOutStatus.CheckedIn) { throw new Exception("Book is already checked in."); } bookEntity.CheckInCheckOut = Common.Enum.CheckInOutStatus.CheckedIn; lastBookAssignation.CheckInDate = model.ActualReturnDate; unitOfWork.BookRepository.Update(bookEntity); unitOfWork.BookAssignationRepository.Update(lastBookAssignation); unitOfWork.Save(); }
public ActionResult CheckIn(BookCheckInVIewModel model) { try { if (ModelState.IsValid) { bookBusinessProvider.AddCheckIn(model); return(RedirectToAction("Index", "Home")); } } catch (DataException) { ModelState.AddModelError("", "Unable to check-in the book"); } return(CheckIn(model.BoookID)); }