Beispiel #1
0
    protected void btnAddVideo_Click(object sender, EventArgs e)
    {
        // Check if the validation passed successfully
        if (IsValid == false)
        {
            return;
        }

        try
        {
            // convert from Youtube link to the currect link (https://www.youtube.com/embed/'ID of youtube video')
            string correctLink = "https://www.youtube.com/embed/" +
                                 txtVideoLink.Text.Substring(txtVideoLink.Text.IndexOf("v=") + 2);

            //Add the video to the Database.
            videos.AddVideo(txtVideoName.Text, correctLink);

            //Adding the video to the Cache, checking before if the cache exists!
            if (Cache["Videos"] != null)
            {
                List <ShowVideoControl> list         = Cache["Videos"] as List <ShowVideoControl>;
                ShowVideoControl        videoControl = LoadControl("ShowVideoControl.ascx") as ShowVideoControl;

                // setting VideoID by taking the last VideoID from All
                // videos in the "list" collection and adding +1 because it a new video
                videoControl.VideoID   = list.Last().VideoID + 1;
                videoControl.VideoName = txtVideoName.Text;
                videoControl.VideoLink = correctLink;
                list.Add(videoControl);
            }

            // setting successfully message.
            SetMessageState(State.Success, "הסרטון " + txtVideoName.Text + " נוסף בהצלחה!");
        }
        catch (Exception ex)
        {
            // setting error message.
            SetMessageState(State.Danger, ex.Message);
        }
    }