public async Task <bool> Add(CheckoutDto newCheckoutDto)
        {
            var checkoutEntity = _mapper.Map <Data.Models.Checkout>(newCheckoutDto);

            try {
                await _context.AddAsync(checkoutEntity);

                await _context.SaveChangesAsync();

                return(true);
            } catch (Exception ex) {
                throw new LibraryServiceException(Reason.UncaughtError);
            }
        }
Exemple #2
0
        public async Task <bool> PlaceHold(Guid assetId, int libraryCardId)
        {
            var now = DateTime.UtcNow;

            var asset = await _context.LibraryAssets
                        .Include(a => a.AvailabilityStatus)
                        .FirstAsync(a => a.Id == assetId);

            var card = await _context.LibraryCards
                       .FirstAsync(a => a.Id == libraryCardId);

            _context.Update(asset);

            if (asset.AvailabilityStatus.Name == "Available")
            {
                asset.AvailabilityStatus = await _context.Statuses
                                           .FirstAsync(a => a.Name == "On Hold");
            }

            var hold = new Hold {
                HoldPlaced  = now,
                Asset       = asset,
                LibraryCard = card
            };

            await _context.AddAsync(hold);

            await _context.SaveChangesAsync();

            return(true);
        }
        public async Task <bool> Add(StatusDto statusDto)
        {
            var status = _mapper.Map <AvailabilityStatus>(statusDto);
            await _context.AddAsync(status);

            await _context.SaveChangesAsync();

            return(true);
        }
        public async Task <bool> Add(LibraryBranchDto newBranchDto)
        {
            var newBranch = _mapper.Map <LibraryBranch>(newBranchDto);
            await _context.AddAsync(newBranch);

            await _context.SaveChangesAsync();

            return(true);
        }
Exemple #5
0
        public async Task <bool> Add(PatronDto newPatronDto)
        {
            var newPatron = _mapper.Map <Patron>(newPatronDto);
            await _context.AddAsync(newPatron);

            await _context.SaveChangesAsync();

            return(true);
        }
Exemple #6
0
        public async Task <bool> Add(LibraryCardDto libraryCardDto)
        {
            var newLibraryCard = _mapper.Map <LibraryCard>(libraryCardDto);
            await _context.AddAsync(newLibraryCard);

            await _context.SaveChangesAsync();

            return(true);
        }
Exemple #7
0
        public async Task <bool> Add(LibraryAssetDto assetDto)
        {
            var newAsset = _mapper.Map <Asset>(assetDto);
            await _context.AddAsync(newAsset);

            await _context.SaveChangesAsync();

            return(true);
        }
        public async Task <BookDto> AddBookAsync(BookDto bookDto, UserDto userDto)
        {
            ValidateBookTitle(bookDto.Title);
            ValidateDateOfPublishing(bookDto.DateOfPublishing);
            ValidateIsbn(bookDto.Isbn);
            ValidateSummary(bookDto.Summary);
            ValidateAvailableCount(bookDto.CountAvailable);

            await CheckAuthorInDbAsync(_db, _mapper, bookDto);
            await CheckPublisherInDbAsync(_db, _mapper, bookDto);

            var book = _mapper.Map <BookDto, Book>(bookDto);

            await _db.AddAsync(book);

            await _db.SaveChangesAsync();

            _logger.LogInformation(AddBookToLibraryLogMessage(book, userDto));

            return(_mapper.Map <Book, BookDto>(book));
        }