public async Task <GetBookDetailsResponse> AddBook(PostBookCreate bookToAdd)
        {
            // add it to the db context. (we need to make it a book)
            var book = _mapper.Map <Book>(bookToAdd); // PostBookCreate -> Book

            _context.Books.Add(book);                 // book.Id = 0;
                                                      // save the changes to the database.
            await _context.SaveChangesAsync();

            // book.Id = 8;
            var response = _mapper.Map <GetBookDetailsResponse>(book); // Book -> GetBookDetailsResponse

            return(response);
        }
Exemplo n.º 2
0
        public async Task <GetBookDetailsResponse> AddBook(PostBookCreate bookToAdd)
        {
            // add it to the db context. (we need to make it a book)
            var book = _mapper.Map <Book>(bookToAdd); // PostBookCreate -> Book

            _context.Books.Add(book);                 // book.Id = 0;
                                                      // save the changes to the database.
            await _context.SaveChangesAsync();

            // book.Id = 8;
            var response = _mapper.Map <GetBookDetailsResponse>(book); // Book -> GetBookDetailsResponse

            // return a 201, with location header, with a copy of what they'd get from that location
            return(response);
        }
Exemplo n.º 3
0
        public async Task RemoveBookFromInventory(int id)
        {
            var storedBook = await _context.GetBooksInInventory().SingleOrDefaultAsync(b => b.Id == id);

            if (storedBook != null)
            {
                storedBook.IsInInventory = false;
                await _context.SaveChangesAsync();
            }
        }
        public async Task RemoveBookAsync(int id)
        {
            var book = await _context.AvailableBooks.SingleOrDefaultAsync(b => b.Id == id);

            if (book != null)
            {
                //_context.Books.Remove(book);
                book.IsAvailable = false;
                _ = await _context.SaveChangesAsync();
            }
        }
        public async Task <GetReservationsSummaryResponseItem> AddReservationAsync(PostReservationRequest request)
        {
            var reservation = new BookReservation
            {
                For     = request.For,
                BookIds = request.Books,
                Status  = ReservationStatus.Pending
            };

            _context.Reservations.Add(reservation);
            await _context.SaveChangesAsync();

            await _reservationProcessor.AddWorkAsync(reservation);

            return(_mapper.Map <GetReservationsSummaryResponseItem>(reservation));
        }