コード例 #1
0
        public async Task <IActionResult> Create([Bind("Author,Publisher,Published,ISBN,ProductId,Title,Price,ImageUrl,Category,CreatedDate")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Artist,Label,Released,ProductId,Title,Price,ImageUrl,Category")] MusicCD musicCD)
        {
            if (ModelState.IsValid)
            {
                _context.Add(musicCD);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(musicCD));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Director,Released,ProductId,Title,Price,ImageUrl,Category,CreatedDate")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("Artist,Label,Released,Title,Price,ImageUrl,Category")] MusicCD musicCD)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(musicCD);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DataException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            return(View(musicCD));
        }