Beispiel #1
0
        public async Task <ActionResult <Book> > Create(CreateBookRequest request)
        {
            var book = new Book
            {
                Img          = request.Img,
                Name         = request.Name,
                Author       = request.Author,
                Year         = request.Year,
                Price        = request.Price,
                DownloadLink = request.DownloadLink,
                Text         = request.Text
            };

            _context.Add(book);
            await _context.SaveChangesAsync();

            return(book);
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("Img,Name,Author,Year,Price,DownloadLink,Text")] CreateBookRequest request)
        {
            if (ModelState.IsValid)
            {
                var book = new Book
                {
                    Img          = request.Img,
                    Name         = request.Name,
                    Author       = request.Author,
                    Year         = request.Year,
                    Price        = request.Price,
                    DownloadLink = request.DownloadLink,
                    Text         = request.Text
                };

                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(BookIndex)));
            }

            return(View("Error"));
        }