Example #1
0
        public PlaylistWithTracks PlaylistEditTracks(PlaylistEditTracks newItem)
        {
            var o = ds.Playlists.Include("Tracks").SingleOrDefault(p => p.PlaylistId == newItem.PlaylistId);

            if (o == null)
            {
                return(null);
            }
            else
            {
                o.Tracks.Clear();

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

                ds.SaveChanges();
            }
            return(Mapper.Map <Playlist, PlaylistWithTracks>(o));
        }
        public ActionResult Edit(int?id, PlaylistEditTracks newItem)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("edit", new { id = newItem.PlaylistId }));
            }

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

            var editedItem = m.PlaylistEditTracks(newItem);

            if (editedItem == null)
            {
                return(RedirectToAction("edit", new { id = newItem.PlaylistId }));
            }
            else
            {
                return(RedirectToAction("details", new { id = newItem.PlaylistId }));
            }
        }