public ActionResult Add(Media model)
        {
            if(User.Identity.IsAuthenticated) {
                OneMusicDBEntities db = new OneMusicDBEntities();
                Song n = new Song();
                n.track_id = model.Track_Id;
                n.track_title = model.Track_Title;
                n.status = 0;
                n.url = model.Url;
                n.date_added = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
                n.submitted_by = db.Users.FirstOrDefault(u => u.user_name == User.Identity.Name).user_id;

                db.Songs.Add(n);
                db.SaveChanges();
            }

            return RedirectToAction("Play");
        }
        /// <summary>
        /// broadcast -> sync media (or get current if only connected user) and initiate play on given client
        /// </summary>
        /// <param name="media">media -> updated Media object</param>
        /// <param name="id">id -> clientId of user who sent request</param>
        public void broadcast(Media media, string id)
        {
            if (media.Track_Id != null) {
                media = Sync(media);
            } else {
                OneMusicDBEntities db = new OneMusicDBEntities();
                Song current = db.Songs.FirstOrDefault(s => s.status == 1);

                if (current == null)
                    current = db.Songs.FirstOrDefault(s => s.status == 0);

                if (current == null)
                    current = db.Songs.FirstOrDefault();

                current.status = 1;
                db.SaveChanges();

                media = new Media(current);

                Thread.Sleep(2000); //wait 2s to allow for other users to contact first
            }

            Clients.Client(id).play(media);
        }
        public Media Sync(Media m = null)
        {
            OneMusicDBEntities db = new OneMusicDBEntities();
            Song current = db.Songs.FirstOrDefault(s => s.status == 1);

            if (m != null)
            {
                //if (m.Id > current.id)
                //{
                //    current.current = false;
                //    db.Songs.FirstOrDefault(s => s.id == m.Id).current = true;
                //}
                //else
                //{
                if (m.Id == current.id && (!current.position.HasValue || m.Position > current.position))
                    {
                        current.position = m.Position;
                        db.SaveChanges();
                    }
                //}
            }

            Media media = new Media(current);
            media.ReturnTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")).Second;

            return media;
        }
        /// <summary>
        /// next -> initiate client play of next song in queue; update database if client is leader
        /// </summary>
        /// <param name="id">id -> current song id (for db)</param>
        public void next(int id)
        {
            OneMusicDBEntities db = new OneMusicDBEntities();

            Song current = db.Songs.FirstOrDefault(s => s.status == 1);
            Song next = new Song();

            if (current.id == id)
            {
                next = db.Songs.FirstOrDefault(s => s.status == 0); // && s.channel == current.channel);

                if (next == null)
                    next = db.Songs.FirstOrDefault(s => s.id > id);

                if (next == null)
                    next = db.Songs.FirstOrDefault();

                current.status = 2;
                current.position = null;
                next.status = 1;

                db.SaveChanges();
            }
            else
            {
                next = current;
            }

            Media output = new Media(next);
            output.Position = 0;

            Clients.Caller.play(output);
        }
 /// <summary>
 /// update -> update media (current and position), called on sync and stop
 /// </summary>
 /// <param name="media">media -> Media object (id, track_id, url, position) to update</param>
 public void update(Media media)
 {
     Sync(media);
 }