private async Task LoadGenresAsync(string fileName, CancellationToken cancellationToken) { using (GenresReader reader = new GenresReader(fileName)) { reader.Fb2Only = true; foreach (GenreRecord record in reader.ReadGenres(cancellationToken)) { Genre genre = await _genresCache.GetAsync(record.Fb2Code); if (genre != null) { continue; } genre = new Genre() { Fb2Code = record.Fb2Code, Name = record.Name, Search = record.Name.ToUpper(), }; await _db.AddAsync(genre); _genresCache.Add(genre); } await _db.SaveChangesAsync(); } }
public void AddBook(Book book) { if (book == null) { throw new ArgumentNullException(nameof(book)); } _context.AddAsync(book); }
public async Task <ActionResult <Book> > PostBook(BookDetailDto bookDetailDto) { await _booksContext.AddAsync(_mapper.Map <Book>(bookDetailDto)); await _booksContext.SaveChangesAsync(); int lastId = _booksContext.Books.ToList().Max(x => x.BookId); return(_booksContext.Books.Find(lastId)); }