コード例 #1
0
        // GET: Movies
        public async Task <IActionResult> Index(string musicGenre, string searchString)
        {
            // Use LINQ to get list of genres.
            IQueryable <string> genreQuery = from m in _context.Music
                                             orderby m.Genre
                                             select m.Genre;

            var musics = from m in _context.Music
                         select m;

            if (!string.IsNullOrEmpty(searchString))
            {
                musics = musics.Where(s => s.Title.Contains(searchString));
            }

            if (!string.IsNullOrEmpty(musicGenre))
            {
                musics = musics.Where(x => x.Genre == musicGenre);
            }

            var musicGenreVM = new MusicGenreViewModel
            {
                Genres = new SelectList(await genreQuery.Distinct().ToListAsync()),
                Musics = await musics.ToListAsync()
            };

            return(View(musicGenreVM));
        }
コード例 #2
0
 public async Task <IActionResult> Create(MusicGenreViewModel model)
 {
     if (ModelState.IsValid)
     {
         _context.Add(new MusicGenre()
         {
             Naam = model.Naam, MusicID = model.MusicID
         });
         await _context.SaveChangesAsync();
     }
     ViewData["MusicsID"] = new SelectList(_context.Musics, "ID", "Titel");
     return(RedirectToAction(nameof(Index)));
 }
コード例 #3
0
        public async Task <IActionResult> Edit(MusicGenreViewModel model)
        {
            if (ModelState.IsValid)
            {
                var genre = await _context.MusicGenres.FindAsync(model.ID);

                genre.Naam    = model.Naam;
                genre.MusicID = model.MusicID;
                _context.Update(genre);
                await _context.SaveChangesAsync();
            }
            ViewData["MusicsID"] = new SelectList(_context.Musics, "ID", "Titel");
            return(RedirectToAction(nameof(Index)));
        }
コード例 #4
0
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var genre = _context.MusicGenres.Include(m => m.Musics).FirstOrDefault(m => m.ID == id);
            var model = new MusicGenreViewModel()
            {
                Music   = genre.Musics.Titel,
                Naam    = genre.Naam,
                MusicID = genre.MusicID,
                ID      = genre.ID
            };

            if (genre == null)
            {
                return(NotFound());
            }
            ViewData["MusicID"] = new SelectList(_context.Musics, "ID", "Titel");
            return(View(model));
        }
コード例 #5
0
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var genre = await _context.MusicGenres
                        .Include(m => m.Musics)
                        .FirstOrDefaultAsync(m => m.ID == id);

            if (genre == null)
            {
                return(NotFound());
            }
            var model = new MusicGenreViewModel()
            {
                Music = genre.Musics.Titel,
                Naam  = genre.Naam,
                ID    = genre.ID
            };

            return(View(model));
        }