Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("CategoryID,CategoryName")] Category category)
        {
            if (id != category.CategoryID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.CategoryID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("SongID,NameSong,Singer,Author")] Song song)
        {
            if (id != song.SongID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    Category     cate         = _context.Category.Find(2);
                    SongCategory songCategory = new SongCategory
                    {
                        Category = cate,
                        Song     = song
                    };
                    _context.Update(song);
                    _context.Add(songCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SongExists(song.SongID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(song));
        }