public static BookIssuedViewModel MapToViewModel(this ReservedBook book)
        {
            var selectItems = new List <SelectListItem>();

            for (int i = 1; i <= 10; i++)
            {
                selectItems.Add(new SelectListItem {
                    Text = i.ToString(), Value = i.ToString()
                });
            }

            var vm = new BookIssuedViewModel();

            vm.BookId     = book.BookId.ToString();
            vm.Author     = book.Book.Author;
            vm.StartDate  = book.ReservationDate;
            vm.EndDate    = book.ReservationDueDate;
            vm.ISBN       = book.Book.ISBN;
            vm.Title      = book.Book.Title;
            vm.Status     = book.Book.Status.ToString();
            vm.IsReserved = true;
            vm.RatingList = selectItems;

            return(vm);
        }
        public async Task AddBookToReservedBooksAsync(string isbn, string userName)
        {
            var user = await _accountManager.GetUserByUsernameAsync(userName);

            var bookToReserve = await this.ReserveTheMostSuitableBookAsync(isbn);

            if (bookToReserve is null)
            {
                throw new ArgumentException(Constants.BookToBeDeleted);
            }

            var newBook = new ReservedBook()
            {
                BookId             = bookToReserve.Id,
                UserId             = user.Id,
                ReservationDate    = null,
                ReservationDueDate = null
            };

            await this.ChangeBookStatusAsync(bookToReserve.Id.ToString(), BookStatus.Reserved);

            _context.ReservedBooks.Add(newBook);
            await _context.SaveChangesAsync().ConfigureAwait(false);

            var message = string.Format(Constants.ReserveBookNotification, user.Username, bookToReserve.Title, bookToReserve.Id);

            await this.AddNotificationAsync(message, await _accountManager.GetAdminAccountAsync());
        }
Esempio n. 3
0
        public void Update(ReservedBook entity)
        {
            var result = Find(entity.Id);

            result.IdBook       = entity.IdBook;
            result.IdSubscriber = entity.IdSubscriber;
            reservedBookContext.SaveChanges();
        }
Esempio n. 4
0
        public void Add(ReservedBook entity)
        {
            var response = reservedBookContext.Add(entity);

            reservedBookContext.SaveChanges();
        }
 public void AddReservedBook(ReservedBook reservedBook)
 {
     reservedBookRepository.Add(reservedBook);
 }