Exemplo n.º 1
0
        public ActionResult NewSongCreate(AlbumViewModel album)
        {
            //In case the user submits the album without adding a genre, don't assing a genrename.
            if (album.GenreID != 0)
            {
                album.GenreName = db.genres.Where(x => x.id == album.GenreID).First().genreName;
            }
            album al = album.FromModel();

            if (ModelState.IsValid)
            {
                db.albums.Add(al);
                db.SaveChanges();
                //If an artist isn't passed in from the new song page, then redirect to the new album in the song Index.
                if (album.importedArtist == true)
                {
                    return(RedirectToAction("Create", "songs", new { ArtistID = album.ArtistID, AlbumID = al.id }));
                }
                else
                {
                    return(RedirectToAction("AlbumIndex", "songs", new { AlbumID = al.id, ArtistID = album.ArtistID }));
                }
            }

            AlbumViewModel av = new AlbumViewModel();

            av.ArtistNames = new SelectList(db.artists.OrderBy(x => x.artistName), "id", "artistName");
            av.GenreNames  = new SelectList(db.genres.OrderBy(x => x.genreName), "id", "genreName");
            return(View(av));
        }
Exemplo n.º 2
0
        public ActionResult Edit(AlbumViewModel album)
        {
            album.GenreName = db.genres.Where(x => x.id == album.GenreID).First().genreName;
            album al = album.FromModel();

            if (ModelState.IsValid)
            {
                db.Entry(al).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            album.ArtistNames = new SelectList(db.artists.OrderBy(x => x.artistName), "id", "artistName", al.id);
            album.GenreNames  = new SelectList(db.genres.OrderBy(x => x.genreName), "id", "genreName", al.genre_id);
            return(View(album));
        }
Exemplo n.º 3
0
        public ActionResult Create(AlbumViewModel album)
        {
            album.GenreName = db.genres.Where(x => x.id == album.GenreID).First().genreName;
            album al = album.FromModel();

            if (ModelState.IsValid)
            {
                db.albums.Add(al);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            AlbumViewModel av = new AlbumViewModel();

            av.ArtistNames = new SelectList(db.artists.OrderBy(x => x.artistName), "id", "artistName");
            av.GenreNames  = new SelectList(db.genres.OrderBy(x => x.genreName), "id", "genreName");
            return(View(av));
        }