public IHttpActionResult getPlaylist(long id)
        {
            var playlist = playlistManager.ReadPlaylist(id);

            if (playlist == null)
            {
                return(NotFound());
            }

            return(Ok(playlist));
        }
        // GET: History/View/1
        public ActionResult View(long id)
        {
            var playlist     = playlistManager.ReadPlaylist(id);
            var comments     = playlistManager.ReadComments(playlist);
            var organisation = organisationManager.ReadOrganisationForPlaylist(playlist.Id);

            var playlistOwners = new List <User>();

            if (organisation != null)
            {
                playlistOwners = userManager.ReadCoOrganiserFromOrganisation(organisation).ToList();
                playlistOwners.Add(userManager.ReadOrganiserFromOrganisation(organisation));
            }
            else
            {
                if (playlist.CreatedById != null)
                {
                    playlistOwners.Add(userManager.ReadUser((long)playlist.CreatedById));
                }
            }

            User user = null;

            if (User != null)
            {
                user = userManager.ReadUser(User.Identity.Name);
            }

            ViewBag.Organisation = organisationManager.ReadOrganisationForPlaylist(playlist.Id);
            ViewBag.CurrentUser  = user;
            ViewBag.Organisers   = playlistOwners;

            ViewBag.CommentCount = comments.Count();
            ViewBag.Comments     = comments;
            ViewBag.TrackCount   = playlist.PlaylistTracks.Count(pt => pt.PlayedAt == null);

            playlist.PlaylistTracks = playlist.PlaylistTracks
                                      .Where(pt => pt.PlayedAt != null)
                                      .OrderBy(pt => pt.PlayedAt)
                                      .ToList();

            return(View(playlist));
        }
        public ActionResult AddTrack(long playlistId, string id)
        {
            if (!ModelState.IsValid)
            {
                return(View("View"));
            }

            var track = trackProvider.LookupTrack(id);

            if (track == null)
            {
                return(new HttpStatusCodeResult(400));
            }

            var albumArtUrl = albumArtProvider.Find(track.Artist + " " + track.Title);

            track.CoverArtUrl = albumArtUrl;

            track = playlistManager.AddTrackToPlaylist(
                playlistId,
                track
                );

            if (track == null)
            {
                return(new HttpStatusCodeResult(400, "You can not add a song that is already in the list"));
            }
            var trackCount = playlistManager.ReadPlaylist(playlistId).PlaylistTracks.Where(p => p.PlayedAt == null).ToList().Count;

            return(Json(trackCount, JsonRequestBehavior.AllowGet));
        }