public async Task <ActionResult <BookCategory> > PostBookCategory(BookCategory item)
        {
            _context.BookCategory.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetBookCategory), new { id = item.Id }, item));
        }
Пример #2
0
        public async Task <ActionResult <Author> > PostAuthor(Author item)
        {
            _context.Author.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetAuthor), new { id = item.Id }, item));
        }
Пример #3
0
        public async Task <ActionResult <Book> > PostBook(Book item)
        {
            item.BookCategory = await _context.BookCategory.FirstOrDefaultAsync(c => c.Id == item.BookCategory.Id);

            item.Author = await _context.Author.FirstOrDefaultAsync(a => a.Id == item.Author.Id);

            _context.Book.Add(item);
            await _context.SaveChangesAsync();

            var newBook = new
            {
                Id             = item.Id,
                Name           = item.Name,
                BookCategoryId = item.BookCategory != null ? (long?)item.BookCategory.Id : null,
                AuthorId       = item.Author != null ? (long?)item.Author.Id : null,
            };

            return(CreatedAtAction(nameof(GetBook), new { id = item.Id }, newBook));
        }
Пример #4
0
 public Task <int> SaveAsync()
 {
     return(_context.SaveChangesAsync());
 }
Пример #5
0
 public async Task <int> SaveChanges(CancellationToken token = default)
 {
     return(await _ctx.SaveChangesAsync(token));
 }