Пример #1
0
        private LibraryBooksOperationResult validate(InfoRequest infoReq)
        {
            var result = new LibraryBooksOperationResult();
            var book = this._bookRepository.FindBy(x => x.Code == infoReq.BookCode).Result.FirstOrDefault();

            result.Success = !LibraryValidator.isBookAlreadyRegistered(book, ref result);

            return result;
        }
Пример #2
0
        public static bool isBookLoanExceeds30Days(Book book, ref LibraryBooksOperationResult result, InfoRequest infoReq)
        {
            if (book.LoanDate.Value.AddDays(30) < infoReq.ReturnDate)
            {
                result.Message = ValidationMessages.BookLoanExceeds30Days;
                return(true);
            }

            return(false);
        }
Пример #3
0
        public static bool isBookAlreadyRegistered(Book book, ref LibraryBooksOperationResult result)
        {
            if (book != null)
            {
                result.Message = ValidationMessages.BookAlreadyRegistered;
                return(true);
            }

            return(false);
        }
Пример #4
0
        public static bool isUserFined(User user, ref LibraryBooksOperationResult result)
        {
            if (user.isFined.Value)
            {
                result.Message = ValidationMessages.UserFined;
                return(true);
            }

            return(false);
        }
Пример #5
0
        public static bool isMaxLoanReached(IEnumerable <Book> userBookList, ref LibraryBooksOperationResult result)
        {
            if (userBookList.Count() > maxNumberBooks)
            {
                result.Message = ValidationMessages.MaxBookLoanReached;
                return(true);
            }

            return(false);
        }
Пример #6
0
        public static bool isBookLoaned(Book book, ref LibraryBooksOperationResult result)
        {
            if (book != null && book.IsLoaned.HasValue && book.IsLoaned.Value)
            {
                result.Message = ValidationMessages.BookAlreadyLoaned;
                return(true);
            }

            return(false);
        }
Пример #7
0
        public static bool isBookNull(Book book, ref LibraryBooksOperationResult result)
        {
            if (book == null)
            {
                result.Message = ValidationMessages.BookNotExist;
                return(true);
            }

            return(false);
        }
        public static bool isBookLoanExceeds30Days(Book book, ref LibraryBooksOperationResult result, InfoRequest infoReq)
        {
            if (book.LoanDate.Value.AddDays(30) < infoReq.ReturnDate)
            {
                result.Message = ValidationMessages.BookLoanExceeds30Days;
                return true;
            }

            return false;
        }
        public static bool isBookAlreadyRegistered(Book book, ref LibraryBooksOperationResult result)
        {
            if (book != null)
            {
                result.Message = ValidationMessages.BookAlreadyRegistered;
                return true;
            }

            return false;
        }
        public static bool isUserFined(User user, ref LibraryBooksOperationResult result)
        {
            if (user.isFined.Value)
            {
                result.Message = ValidationMessages.UserFined;
                return true;
            }

            return false;
        }
        public static bool isMaxLoanReached(IEnumerable<Book> userBookList, ref LibraryBooksOperationResult result)
        {
            if (userBookList.Count() > maxNumberBooks)
            {
                result.Message = ValidationMessages.MaxBookLoanReached;
                return true;
            }

            return false;
        }
        public static bool isBookLoaned(Book book, ref LibraryBooksOperationResult result)
        {
            if (book != null && book.IsLoaned.HasValue && book.IsLoaned.Value)
            {
                result.Message = ValidationMessages.BookAlreadyLoaned;
                return true;
            }

            return false;
        }
        public static bool isBookNull(Book book, ref LibraryBooksOperationResult result)
        {
            if (book == null)
            {
                result.Message = ValidationMessages.BookNotExist;
                return true;
            }

            return false;
        }
Пример #14
0
        private LibraryBooksOperationResult validate(InfoRequest infoReq, Book book)
        {
            var result = new LibraryBooksOperationResult();
            
            result.Success = !LibraryValidator.isBookNull(book, ref result)
                && LibraryValidator.isBookLoaned(book, ref result)
                && LibraryValidator.isBookLoanExceeds30Days(book, ref result, infoReq);

            return result;
        }
Пример #15
0
        private LibraryBooksOperationResult validate(InfoRequest infoReq)
        {
            var result = new LibraryBooksOperationResult();

            var user = this._usersRepository.GetUserByUsername(infoReq.Username).Result;
            var book = this._bookRepository.FindBy(x => x.Code == infoReq.BookCode).Result.FirstOrDefault();
            var userBookList = this._bookRepository.GetBookListByUsername(infoReq.Username).Result;

            result.Success = !LibraryValidator.isBookNull(book, ref result)
                && !LibraryValidator.isBookLoaned(book, ref result)
                && !LibraryValidator.isMaxLoanReached(userBookList,ref result)
                && !LibraryValidator.isUserFined(user, ref result);

            return result;
        }
Пример #16
0
        private static void Register()
        {
            var infoReq = new InfoRequest();
            AskForValue(Resource.EnterName);
            infoReq.Username = inputValue;
            AskForValue(Resource.EnterBook);
            infoReq.BookCode = inputValue;            

            result = libraryService.ExecuteBookOperation(infoReq).Result;

            if (result.Success)
            {
                PrintMessage(Resource.RegisterBookSuccess);
            }
            else
            {
                PrintMessage(result.Message.ToString());
            }
        }