public bool Borrow(int bookId, int borrowerId, string borrowerEmail, BorrowerType userType) { var book = bookList.FirstOrDefault(h => h.Id == bookId); if (book.Type == BookType.Fiction && MaxLimitFiction(borrowerId, userType)) { return(false); } if (book.Type == BookType.Reserve && MaxLimitReserved(borrowerId, userType)) { return(false); } if (book.Type != BookType.Reserve && book.Type != BookType.Fiction && MaxLimitOthers(borrowerId, userType)) { return(false); } if (book.Status == BookStatus.Available) { book.Status = BookStatus.Borrowed; book.BorrowerId = borrowerId; book.BorrowerEmail = borrowerEmail; book.Due = GetDueDate(bookId); SaveBooks(); return(true); } else { return(false); } }
public bool MaxLimitFiction(int borrowerId, BorrowerType userType) { int BorrowedFiction = bookList.Where(h => h.BorrowerId == borrowerId && h.Type == BookType.Fiction).Count(); if (BorrowedFiction < 3) { return(false); } else { return(true); } }
public bool MaxLimitOthers(int borrowerId, BorrowerType userType) { int BorrowedOthers = bookList.Where(h => h.BorrowerId == borrowerId && h.Type != BookType.Reserve && h.Type != BookType.Fiction).Count(); if (BorrowedOthers < 5 && userType == BorrowerType.Faculty) { return(false); } else if (BorrowedOthers < 3 && userType != BorrowerType.Faculty) { return(false); } else { return(true); } }
public bool MaxLimitReserved(int borrowerId, BorrowerType userType) { int BorrowedReserved = bookList.Where(h => h.BorrowerId == borrowerId && h.Type == BookType.Reserve).Count(); if (BorrowedReserved < 1 && userType == BorrowerType.Student) { return(false); } else if (BorrowedReserved < 2 && userType != BorrowerType.Student) { return(false); } else { return(true); } }