public bool LendBook(IAccount user, IBook book) { char bookLetter = book.Title.ToUpper()[0]; foreach (var rack in this.Racks) { if (rack.Letters.Contains(bookLetter)) { var bookItem = rack.BookItems.FirstOrDefault(bI => bI.Book == book); if (bookItem == null) { return(false); } var bookLending = new BookLending() { BookItem = bookItem, User = user, Date = DateTime.Now }; this.SystemService.BookLendings.Add(bookLending); rack.BookItems.Remove(bookItem); break; } } return(true); }
public ResultDTO CloseLending(string barcode) { int returnTime = (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds(); Hardbook hardbook = bookRepository.GetHardbook(barcode); BookLending lending = lendingRepository.GetLendingByHardbookId(hardbook.Id); BookReservation reservation = reservationRepository.GetReservationWithId(lending.Id); reservation.Status = "Returned"; hardbook.CanBorrowed = true; lending.ReturnDate = returnTime; bookRepository.UpdateHardbook(hardbook); reservationRepository.UpdateReservations(reservation); lendingRepository.UpdateLending(lending); string message; if (lending.DueDate > returnTime) { message = "Trả đúng hạn"; } else { TimeSpan t = TimeSpan.FromSeconds(returnTime - lending.DueDate); message = "Trả muộn " + t.Days + " ngày, " + t.Hours + " giờ, " + t.Minutes + " phút"; } return(new ResultDTO() { Success = true, Message = message }); }
public bool LendBook(Account user, Book book) { char bookLetter = book.Title.ToUpper()[0]; foreach (var rack in dbContext.Racks) { if (rack.Letters.Any(rackLetter => rackLetter.Letter == bookLetter)) { var bookItem = rack.BookItems .FirstOrDefault(bItem => bItem.Book.Id == book.Id && !dbContext.BookLendings.Any(bLending => bLending.BookItemId == bItem.Id)); if (bookItem == null) { return(false); } var bookLending = new BookLending() { BookItemId = bookItem.Id, AccountId = user.Id, Date = DateTime.Now }; dbContext.BookLendings.Add(bookLending); break; } } dbContext.SaveChanges(); return(true); }
public async Task LendBookAsync(BaseTitleDto baseTitleDto) { var book = await this.dbContext.Books .FirstOrDefaultAsync(bTitle => bTitle.Title == baseTitleDto.Title); var user = await this.dbContext.Users .Include(uLend => uLend.BookLendings) .SingleOrDefaultAsync(uId => uId.Id == baseTitleDto.UserId); if (book == null) { throw new BookException("The book was not found!"); } if (user.CountLendBooks < minLendedBooks) { throw new Exception("You cannot take more than 3 books!"); } var bookLending = await this.dbContext.BookLendings .FirstOrDefaultAsync(bLending => bLending.BookId == book.Id && !bLending.ReturnDate.HasValue && bLending.Date.AddDays(10) > DateTime.Now); // This is enshures automatic return after 10 days if (bookLending != null) { throw new BookException("The book has already been lended!"); } bookLending = new BookLending() { Book = book, User = user, Date = DateTime.Now }; user.CountLendBooks -= 1; var bookReservation = await this.dbContext.BookReservations .Include(item => item.Notification) .FirstOrDefaultAsync(item => item.BookId == book.Id && item.UserId == user.Id && item.Active); if (bookReservation != null) { bookReservation.Active = false; bookReservation.Notification.Seen = true; } await this.dbContext.BookLendings.AddAsync(bookLending); await this.dbContext.SaveChangesAsync(); }
public void UpdateLending(BookLending lending) { try { DbContext.BookLending.Update(lending); DbContext.SaveChanges(); } catch (Exception) { } }
public bool AddLending(BookLending lending) { try { DbContext.BookLending.Add(lending); DbContext.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public boolean checkout(String memberId) { if (bookItem.getIsReferenceOnly()) { ShowError("This book is Reference only and can't be issued"); return(false); } if (!BookLending.lendBook(this.getBarCode(), memberId)) { return(false); } this.updateBookItemStatus(BookStatus.LOANED); return(true); }
private void checkForFine(String bookItemBarcode) { BookLending bookLending = BookLending.fetchLendingDetails(bookItemBarcode); Date dueDate = bookLending.getDueDate(); Date today = new Date(); // check if the book has been returned within the due date if (today.compareTo(dueDate) > 0) { long diff = todayDate.getTime() - dueDate.getTime(); long diffDays = diff / (24 * 60 * 60 * 1000); Fine.collectFine(memberId, diffDays); } }
public IActionResult Borrow(int id) { var userId = _context.Users.Where(x => x.Email == User.Identity.Name).First().Id; var newLending = new BookLending { BookId = id, DateFrom = DateTime.Now, DateTo = null, UserId = userId }; _context.BookLendings.Add(newLending); _context.SaveChanges(); return(RedirectToAction("Index")); }
public bool renewBookItem(BookItem bookItem) { this.checkForFine(bookItem.getBarcode()); BookReservation bookReservation = BookReservation.fetchReservationDetails(bookItem.getBarcode()); // check if this book item has a pending reservation from another member if (bookReservation != null && bookReservation.getMemberId() != this.getMemberId()) { ShowError("This book is reserved by another member"); member.decrementTotalBooksCheckedout(); bookItem.updateBookItemState(BookStatus.RESERVED); bookReservation.sendBookAvailableNotification(); return(false); } else if (bookReservation != null) { // book item has a pending reservation from this member bookReservation.updateStatus(ReservationStatus.COMPLETED); } BookLending.lendBook(bookItem.getBarCode(), this.getMemberId()); bookItem.updateDueDate(LocalDate.now().plusDays(Constants.MAX_LENDING_DAYS)); return(true); }
public decimal CalculateFine(BookLending bookLending) { var result = DateTime.Now - bookLending.Date.AddDays(10); return(result.Days * 1.30m); }
public bool ValidateLendPeriod(BookLending bookLending) { return(bookLending.Date.AddDays(10) >= DateTime.Now); }
public void ReturnBook(BookLending bookLanding) { dbContext.BookLendings.Remove(bookLanding); dbContext.SaveChanges(); }
public void ReturnBook(BookLending bookLanding) { this.System.BookLendings.Remove(bookLanding); bookLanding.BookItem.Rack.BookItems.Add(bookLanding.BookItem); }