Beispiel #1
0
    protected void btnUpdateVideo_Click(object sender, EventArgs e)
    {
        // Validate txtVideoID, txtVideoName, txtVideoLink
        Validate("AddVideoGroup");
        Validate("DeleteVideoGroup");

        if (IsValid == false)
        {
            return;
        }

        try
        {
            string correctLink = "https://www.youtube.com/embed/" +
                                 txtVideoLink.Text.Substring(txtVideoLink.Text.IndexOf("v=") + 2);

            int videoID = Convert.ToInt32(txtVideoID.Text);

            // update the cache
            if (Cache["Videos"] != null)
            {
                List <ShowVideoControl> list = Cache["Videos"] as List <ShowVideoControl>;
                int index = list.FindIndex(v => v.VideoID == videoID);
                list[index].VideoName = txtVideoName.Text;
                list[index].VideoLink = correctLink;
            }

            string oldVideoName = videos.GetVideo(videoID).VideoName;
            string newVideoName = txtVideoName.Text;
            videos.UpdateVideo(videoID, txtVideoName.Text, correctLink);

            SetMessageState(State.Success, string.Format("הסרטון {0} התעדכן בהצלחה, ל- {1}.", oldVideoName, newVideoName));
        }
        catch (Exception ex)
        {
            SetMessageState(State.Danger, ex.Message);
        }
    }