private void CreateVideo() { // // Validation // MsgErr(true); //if (String.IsNullOrEmpty(txtName.Text.Trim())) //{ // MsgErr(Resource.Admin_m_ProductVideos_NoName); // return; //} string playercode = txtPlayerCode.Text.Trim(); if (string.IsNullOrEmpty(playercode)) { string error; playercode = ProductVideoService.GetPlayerCodeFromLink(txtVideoLink.Text.Trim(), out error); if (!string.IsNullOrEmpty(error)) { MsgErr(error); return; } } int sortOrder = 0; if (!String.IsNullOrEmpty(txtSortOrder.Text)) { int.TryParse(txtSortOrder.Text, out sortOrder); } try { ProductVideoService.AddProductVideo(new ProductVideo { ProductId = ProductId, Name = txtName.Text.Trim(), PlayerCode = playercode, Description = txtDescription.Text.Trim(), VideoSortOrder = sortOrder }); } catch (Exception ex) { MsgErr(ex.Message + " CreateVideo"); Debug.LogError(ex); } }
private void CreateVideo() { // // Validation // MsgErr(true); if (String.IsNullOrEmpty(txtName.Text.Trim())) { MsgErr(Resource.Admin_m_ProductVideos_NoName); return; } string playercode = txtPlayerCode.Text.Trim(); if (string.IsNullOrEmpty(playercode)) { try { string videoLink = txtVideoLink.Text.Trim(); if (!String.IsNullOrEmpty(videoLink)) { if (videoLink.Contains("youtu.be")) { playercode = String.Format("<iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/{0}\" frameborder=\"0\" allowfullscreen></iframe>", videoLink.Split(new[] { "youtu.be/" }, StringSplitOptions.None).Last()); } else if (videoLink.Contains("youtube.com")) { videoLink = videoLink.StartsWith("http://") ? videoLink : "http://" + videoLink; if (!Uri.IsWellFormedUriString(videoLink, UriKind.Absolute)) { MsgErr(Resource.Admin_m_ProductVideos_WrongLink); return; } var url = new Uri(videoLink); string param = HttpUtility.ParseQueryString(url.Query).Get("v"); playercode = String.Format("<iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/{0}\" frameborder=\"0\" allowfullscreen></iframe>", param); } else if (videoLink.Contains("vimeo.com")) { playercode = String.Format("<iframe src=\"http://player.vimeo.com/video/{0}?title=0&byline=0&portrait=0\" width=\"560\" height=\"315\" frameborder=\"0\" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>", videoLink.Split(new[] { "vimeo.com/" }, StringSplitOptions.None).Last()); } else { MsgErr(Resource.Admin_m_ProductVideos_WrongLink); return; } } else { MsgErr(Resource.Admin_m_ProductVideos_NoPlayerCode); return; } } catch (Exception ex) { MsgErr(Resource.Admin_m_ProductVideos_WrongLink); Debug.LogError(ex); return; } } int sortOrder = 0; if (!String.IsNullOrEmpty(txtSortOrder.Text)) { int.TryParse(txtSortOrder.Text, out sortOrder); } try { ProductVideoService.AddProductVideo(new ProductVideo { ProductId = ProductId, Name = txtName.Text.Trim(), PlayerCode = playercode, Description = txtDescription.Text.Trim(), VideoSortOrder = sortOrder }); } catch (Exception ex) { MsgErr(ex.Message + " CreateVideo"); Debug.LogError(ex); } }