Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            MembershipUser mu = MembershipWrapper.GetUser();

            if (mu == null ||
                string.IsNullOrEmpty(Request.QueryString["vidid"])
                ) Response.Redirect("~/account/logon");

            string vidid = Request.QueryString["vidid"];
            string vtype = Request.QueryString["vtype"];

            char vtypeAction = Convert.ToChar(vtype);

            var vid = new Video(vidid.Substring(0, 2), vidid.Substring(3, vidid.Length - 3));

            switch (vtypeAction)
            {
                case 'P':
                    // adding to playlist
                    var plylst = new Playlist();
                    plylst.GetUserPlaylist(Convert.ToInt32(mu.ProviderUserKey));

                    var plyvid = new PlaylistVideo();

                    if (plylst.PlaylistID == 0)
                    {
                        plylst.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                        plylst.UserAccountID = Convert.ToInt32(mu.ProviderUserKey);
                        plylst.Create();
                        plyvid.RankOrder = 1;
                    }
                    else
                    {
                        var plyvids = new PlaylistVideos();
                        plyvids.GetPlaylistVideosForPlaylist(plylst.PlaylistID);

                        if (mu.UserName.ToLower() != GeneralConfigs.AdminUserName.ToLower()
                            && plyvids.Count >= 25)
                        {
                            // cannot have not than 10
                            Response.Redirect("~/account/playlist/" + mu.UserName);
                        }

                        plyvid.RankOrder = plyvids.Count + 1;
                    }

                    plyvid.PlaylistID = plylst.PlaylistID;
                    plyvid.VideoID = vid.VideoID;

                    if (!PlaylistVideo.IsPlaylistVideo(plyvid.PlaylistID, vid.VideoID))
                    {
                        plyvid.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                        plyvid.Create();
                    }

                    Response.Redirect("~/account/playlist/" + mu.UserName);

                    break;
                default:

                    var uav = new UserAccountVideo();

                    uav.UserAccountID = Convert.ToInt32(mu.ProviderUserKey);
                    uav.VideoID = vid.VideoID;
                    uav.VideoType = vtypeAction;

                    uav.Create();

                    Response.Redirect("~/" + mu.UserName);
                    break;
            }
        }
        public ActionResult Playlist()
        {
            ViewBag.VideoHeight = (Request.Browser.IsMobileDevice) ? 100 : 277;
            ViewBag.VideoWidth = (Request.Browser.IsMobileDevice) ? 225 : 400;

            if (_mu != null) _ua = new UserAccount(Convert.ToInt32(_mu.ProviderUserKey));

            ViewBag.UserName = _ua.UserName;

            var plyst = new Playlist();

            plyst.GetUserPlaylist(_ua.UserAccountID);

            ViewBag.AutoPlay = plyst.AutoPlay;

            ViewBag.AutoPlayNumber = (plyst.AutoPlay) ? 1 : 0;

            ViewBag.UserPlaylistID = plyst.PlaylistID;

            var plyvids = new PlaylistVideos();

            plyvids.GetPlaylistVideosForPlaylist(plyst.PlaylistID);

            var vids = new Videos();
            vids.AddRange(plyvids.Select(plv => new Video(plv.VideoID)));

            var sngrcs = new SongRecords();
            sngrcs.AddRange(vids.Select(vi => new SongRecord(vi)));

            ViewBag.PlaylistVideos = sngrcs.VideoPlaylist();

            return View();
        }
        private void GetUserPlaylist()
        {
            // playlist
            var plyst = new Playlist();

            plyst.GetUserPlaylist(_ua.UserAccountID);

            if (plyst.PlaylistID <= 0 || PlaylistVideos.GetCountOfVideosInPlaylist(plyst.PlaylistID) <= 0) return;
            ViewBag.AutoPlay = plyst.AutoPlay;
            ViewBag.AutoPlayNumber = (plyst.AutoPlay) ? 1 : 0;
            ViewBag.UserPlaylistID = plyst.PlaylistID;
        }
        public ActionResult Playlist(NameValueCollection nvc)
        {
            if (nvc == null) throw new ArgumentNullException("nvc");

            if (_mu != null) _ua = new UserAccount(Convert.ToInt32(_mu.ProviderUserKey));
            ViewBag.UserName = _ua.UserName;

            var plyst = new Playlist();

            plyst.GetUserPlaylist(_ua.UserAccountID);

            ViewBag.UserPlaylistID = plyst.PlaylistID;

            var plyvids = new PlaylistVideos();
            plyvids.GetPlaylistVideosForPlaylist(plyst.PlaylistID);

            nvc = Request.Form;

            PlaylistVideo plv = null;

            if (nvc["video_delete_id"] != null)
            {
                foreach (PlaylistVideo plv1 in plyvids)
                {
                    if (plv != null && plv1.RankOrder > plv.RankOrder)
                    {
                        plv1.RankOrder--;
                        plv1.UpdatedByUserID = _ua.UserAccountID;
                        plv1.Update();
                    }

                    if (plv1.PlaylistID != plyst.PlaylistID || Convert.ToInt32(nvc["video_delete_id"]) != plv1.VideoID)
                        continue;
                    plv = new PlaylistVideo(plv1.PlaylistVideoID);

                    if (PlaylistVideo.Delete(plyst.PlaylistID, Convert.ToInt32(nvc["video_delete_id"])))
                    {
                        // deleted
                    }
                }
            }
            else if (nvc["video_down_id"] != null)
            {
                plv = new PlaylistVideo();
                plv.Get(plyst.PlaylistID, Convert.ToInt32(nvc["video_down_id"]));

                foreach (PlaylistVideo plv1 in plyvids.Where(plv1 => plv1.RankOrder == (plv.RankOrder + 1)))
                {
                    plv1.RankOrder--;
                    plv1.UpdatedByUserID = _ua.UserAccountID;
                    plv1.Update();
                }

                plv.RankOrder++;
                plv.UpdatedByUserID = _ua.UserAccountID;
                plv.Update();
            }
            else if (nvc["video_up_id"] != null)
            {
                plv = new PlaylistVideo();
                plv.Get(plyst.PlaylistID, Convert.ToInt32(nvc["video_up_id"]));

                foreach (PlaylistVideo plv1 in plyvids.Where(plv1 => plv1.RankOrder == (plv.RankOrder - 1)))
                {
                    plv1.RankOrder++;
                    plv1.UpdatedByUserID = _ua.UserAccountID;
                    plv1.Update();
                }

                plv.RankOrder--;
                plv.UpdatedByUserID = _ua.UserAccountID;
                plv.Update();
            }
            else
            {
                if (!string.IsNullOrEmpty(nvc["selected_autoplay"]) && nvc["selected_autoplay"] == "on")
                {
                    plyst.AutoPlay = true;
                }
                else plyst.AutoPlay = false;

                plyst.Update();
            }

            Response.Redirect("~/account/playlist");
            return new EmptyResult();
        }