예제 #1
0
 //
 // GET: /Songs/Create
 public ActionResult Create()
 {
     var viewModel = new CreateOrEditSongViewModel() {
         Albums = new MultiSelectList(DbContext.Albums.ToArray(), "Id", "MyanmarName"),
         Artists = new MultiSelectList(DbContext.Artists.ToArray(), "Id", "MyanmarName")
     };
     return View(viewModel);
 }
예제 #2
0
        public ActionResult Create(CreateOrEditSongViewModel song)
        {
            if (ModelState.IsValid)
            {
                var newSong = new Song() {
                    Title = song.Title,
                    MyanmarTitle = song.MyanmarTitle,
                    Lyric = song.Lyric
                };

                if (song.AlbumIds != null && song.AlbumIds.Any()) {
                    newSong.Albums = DbContext.Albums.Where(a => song.AlbumIds.Contains(a.Id)).ToArray();
                }
                if (song.ArtistIds != null && song.ArtistIds.Any()) {
                    newSong.Artists = DbContext.Artists.Where(a => song.ArtistIds.Contains(a.Id)).ToArray();
                }

                DbContext.Songs.Add(newSong);
                return RedirectToAction("Index");
            }

            return View(song);
        }
예제 #3
0
 //
 // GET: /Songs/Edit/5
 public ActionResult Edit(int id)
 {
     Song song = DbContext.Songs.Single(x => x.Id == id);
     var viewModel = new CreateOrEditSongViewModel() {
         Albums = new MultiSelectList(DbContext.Albums.ToArray(), "Id", "MyanmarName"),
         Artists = new MultiSelectList(DbContext.Artists.ToArray(), "Id", "MyanmarName"),
         Id = song.Id,
         Title = song.Title,
         MyanmarTitle = song.MyanmarTitle,
         Lyric = song.Lyric
     };
     return View(viewModel);
 }