Exemplo n.º 1
0
        public ActionResult Edit(int?id, PlaylistEditTrack newItem)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("edit", new
                {
                    id = newItem.Id
                }));
            }

            if (id.GetValueOrDefault() != newItem.Id)
            {
                return(RedirectToAction("index"));
            }

            var editedItem = man.PlaylistEditTracks(newItem);

            if (editedItem == null)
            {
                return(RedirectToAction("edit", new { id = newItem.Id }));
            }
            else
            {
                return(RedirectToAction("details", new { id = newItem.Id }));
            }
        }
Exemplo n.º 2
0
        public PlaylistWithDetail PlaylistEditTracks(PlaylistEditTrack newItem)
        {
            var o = ds.Playlists.Include("Tracks").SingleOrDefault(t => t.PlaylistId == newItem.Id);

            if (o == null)
            {
                return(null);
            }

            else
            {
                o.Tracks.Clear();

                foreach (var track in newItem.TrackIds)
                {
                    var a = ds.Tracks.Find(track);
                    o.Tracks.Add(a);
                }
                ds.SaveChanges();

                return(Mapper.Map <Playlist, PlaylistWithDetail>(o));
            }
        }