コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Author,Publisher,Published,ISBN,ProductId,Title,Price,ImageUrl,Category,CreatedDate")] Book book)
        {
            if (id != book.ProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(book);
                    _context.Entry <Book>(book).Property(x => x.CreatedDate).IsModified = false;
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookExists(book.ProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Artist,Label,Released,ProductId,Title,Price,ImageUrl,Category")] MusicCD musicCD)
        {
            if (id != musicCD.ProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(musicCD);
                    _context.Entry <MusicCD>(musicCD).Property(x => x.CreatedDate).IsModified = false;
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MusicCDExists(musicCD.ProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(musicCD));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Director,Released,ProductId,Title,Price,ImageUrl,Category,CreatedDate")] Movie movie)
        {
            if (id != movie.ProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(movie);
                    _context.Entry <Movie>(movie).Property(x => x.CreatedDate).IsModified = false;
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieExists(movie.ProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("Artist,Label,Released,ProductId,Title,Price,ImageUrl,Category")] MusicCD musicCD)
        {
            if (id != musicCD.ProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(musicCD);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MusicCDExists(musicCD.ProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(musicCD));
        }