Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,TrackId,ArtistId")] ArtistsTracks artistsTracks)
        {
            if (id != artistsTracks.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(artistsTracks);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ArtistsTracksExists(artistsTracks.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ArtistId"] = new SelectList(_context.Artists, "Id", "Fullname", artistsTracks.ArtistId);
            ViewData["TrackId"]  = new SelectList(_context.Tracks, "Id", "Name", artistsTracks.TrackId);
            return(View(artistsTracks));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("Id,TrackId,ArtistId")] ArtistsTracks artistsTracks)
        {
            if (ModelState.IsValid)
            {
                _context.Add(artistsTracks);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ArtistId"] = new SelectList(_context.Artists, "Id", "Fullname", artistsTracks.ArtistId);
            ViewData["TrackId"]  = new SelectList(_context.Tracks, "Id", "Name", artistsTracks.TrackId);
            return(View(artistsTracks));
        }