Пример #1
0
        public async Task <List <BookLoan.Models.BookStatusViewModel> > OnLoanReportV1(string currentuser = null)
        {
            List <BookLoan.Models.BookStatusViewModel> loanstats = new List <Models.BookStatusViewModel>();

            var books = await _bookService.GetBooks();

            foreach (Models.BookViewModel book in books)
            {
                BookLoan.Models.BookStatusViewModel bsvm = await _loanService.GetBookLoanStatus(book.ID);

                if (((currentuser != null) && (bsvm.Borrower == currentuser)) ||
                    (currentuser == null))
                {
                    loanstats.Add(new Models.BookStatusViewModel()
                    {
                        ID            = book.ID,
                        Author        = book.Author,
                        Title         = book.Title,
                        Genre         = book.Genre,
                        ISBN          = book.ISBN,
                        Edition       = book.Edition,
                        Location      = book.Location,
                        YearPublished = book.YearPublished,
                        OnShelf       = bsvm.OnShelf,
                        DateLoaned    = bsvm.DateLoaned,
                        DateReturn    = bsvm.DateReturn,
                        DateDue       = bsvm.DateDue,
                        Status        = bsvm.Status,
                        Borrower      = bsvm.Borrower
                    });
                }
            }
            return(loanstats);
        }
Пример #2
0
        public async Task <IActionResult> GetBookLoanStatus(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            try
            {
                BookLoan.Models.BookStatusViewModel blvStat =
                    new BookLoan.Models.BookStatusViewModel();
                blvStat = await _loanService.GetBookLoanStatus((int)id);

                if (blvStat == null)
                {
                    return(NotFound());
                }

                // Return loaned book status.
                return(Ok(blvStat));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { ex.Message }));
            }
        }
Пример #3
0
        private LoanReportDto BookToBookLoanStatus(BookViewModel input)
        {
            BookLoan.Models.BookStatusViewModel bookStatus = _loanService.GetBookLoanStatus(input.ID).GetAwaiter().GetResult();
            bookStatus.Title = input.Title;

            var loanReport = _mapper.Map <LoanReportDto>(bookStatus);

            return(loanReport);
        }