コード例 #1
0
        public async Task <IActionResult> UpdateBookItem(long id, BookItemDTO bookItemDTO)
        {
            if (id != bookItemDTO.Id)
            {
                return(BadRequest());
            }

            var bookItem = await _context.BookItems.FindAsync(id);

            if (bookItem == null)
            {
                return(NotFound());
            }

            bookItem.Name     = bookItemDTO.Name;
            bookItem.Author   = bookItemDTO.Author;
            bookItem.Language = bookItemDTO.Language;
            bookItem.Year     = bookItemDTO.Year;
            bookItem.Pages    = bookItemDTO.Pages;
            bookItem.Synopsis = bookItemDTO.Synopsis;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException) when(!BookItemExists(id))
            {
                return(NotFound());
            }

            return(NoContent());
        }
コード例 #2
0
ファイル: bookController.cs プロジェクト: bosski92/Zadanie-3
        public async Task <ActionResult <BookItemDTO> > UpdateBookItem(BookItemDTO BookItemDTO)
        {
            var BookItem = await _context.BookItems.FindAsync(BookItemDTO.Id);

            if (BookItem == null)
            {
                return(NotFound());
            }
            BookItem.Bookname = BookItemDTO.Bookname;
            BookItem.Author   = BookItemDTO.Author;
            BookItem.Rating   = BookItemDTO.Rating;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException) when(!BookItemExists(BookItemDTO.Id))
            {
                return(NotFound());
            }

            return(CreatedAtAction(
                       nameof(UpdateBookItem),
                       new { id = BookItem.Id },
                       ItemToDTO(BookItem)));
        }
コード例 #3
0
ファイル: bookController.cs プロジェクト: bosski92/Zadanie-3
        public async Task <ActionResult <BookItemDTO> > CreateBookItem(BookItemDTO BookItemDTO)
        {
            var BookItem = new BookItem
            {
                Bookname = BookItemDTO.Bookname,
                Author   = BookItemDTO.Author,
                Rating   = BookItemDTO.Rating
            };

            _context.BookItems.Add(BookItem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(
                       nameof(GetBookItem),
                       new { id = BookItem.Id },
                       ItemToDTO(BookItem)));
        }
コード例 #4
0
        public async Task <ActionResult <BookItemDTO> > CreateBookItem(BookItemDTO bookItemDTO)
        {
            var bookItem = new BookItem
            {
                Name     = bookItemDTO.Name,
                Author   = bookItemDTO.Author,
                Language = bookItemDTO.Language,
                Year     = bookItemDTO.Year,
                Pages    = bookItemDTO.Pages,
                Synopsis = bookItemDTO.Synopsis
            };

            _context.BookItems.Add(bookItem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetBookItem),
                                   new { id = bookItem.Id },
                                   ItemToDTO(bookItem)));
        }