Esempio n. 1
0
 public JsonResult Get(string id)
 {
     var album = _albumStore.Get(id);
     var tracks = album.Tracks.Select(x => new TrackViewModel { Name = x.Name, TrackLength = x.Length, TrackNo = x.TrackNo });
     var model = new AlbumViewModel { Id = album.Id, Name = album.Name, Genre = album.Genre.ToString(), Tracks = tracks };
     return Json(model);
 }
Esempio n. 2
0
        public ActionResult Edit(string id)
        {
            AlbumViewModel model;
            if(id != string.Empty)
            {
                var album = _albumStore.Get(id);
                model = new AlbumViewModel { Id = album.Id, Name = album.Name };
            }
            else
            {
                model = new AlbumViewModel();
            }

            return View(model);
        }
Esempio n. 3
0
        public ActionResult Edit(AlbumViewModel model)
        {
            if(model.Id != string.Empty)
            {
                var Album = _albumStore.Get(model.Id);
                Album.ChangeName(model.Name);

                Genre parsedGenre;
                Enum.TryParse(model.Genre, out parsedGenre);
                Album.ChangeGenre(parsedGenre);
            }
            else
            {
                Genre parsedGenre;
                Enum.TryParse(model.Genre, out parsedGenre);
                _albumStore.Add(model.Name, model.ArtistId, parsedGenre);
            }

            return RedirectToAction("Index");
        }