public IActionResult UpdateVideoLink(VideoBackgroundWidgetViewModel model) { if (ModelState.IsValid) { // If the full URL is entered, then extract just the video id. if (model.VideoSourceType == VideoSourceTypes.YouTube) { model.VimeoVideoId = null; model.YoutubeVideoId = ExtractYouTubeIdFromUrl(model.YoutubeVideoId); model.SourceUri = "https://www.youtube.com/embed/" + model.YoutubeVideoId; } if (model.VideoSourceType == VideoSourceTypes.Vimeo) { model.YoutubeVideoId = null; model.VimeoVideoId = ExtractVimeoIdFromUrl(model.VimeoVideoId); model.SourceUri = "https://player.vimeo.com/video/" + model.VimeoVideoId; } model.Autoplay = true; model.ShowPlayerControls = false; _videoService.UpdateModel(model); return(Ok(model)); } return(BadRequest(ModelState)); }
public IActionResult DeleteVideoLink(VideoBackgroundWidgetViewModel model) { if (model.Id != null) { _videoService.DeleteModel(model.Id); return(Ok()); } return(BadRequest()); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { VideoBackgroundWidgetViewModel videoBackground = (VideoBackgroundWidgetViewModel)validationContext.ObjectInstance; if ((videoBackground.VideoSourceType == VideoSourceTypes.Vimeo && String.IsNullOrEmpty(videoBackground.VimeoVideoId)) || (videoBackground.VideoSourceType == VideoSourceTypes.YouTube && String.IsNullOrEmpty(videoBackground.YoutubeVideoId))) { return(new ValidationResult("Video ID must not be empty.")); } return(ValidationResult.Success); }
public async Task <IViewComponentResult> InvokeAsync(VideoBackgroundWidgetViewModel model) { var positionList = new List <SelectListItem>(); positionList.Add(new SelectListItem() { Value = "fixed", Text = "Fixed", Selected = false }); positionList.Add(new SelectListItem() { Value = "static", Text = "Static", Selected = true }); ViewBag.PositioningOptions = positionList; var sourceList = new List <SelectListItem>(); sourceList.Add(new SelectListItem() { Value = "vimeo", Text = "Vimeo", Selected = true }); ViewBag.VideoSourceTypes = sourceList; sourceList.Add(new SelectListItem() { Value = "youtube", Text = "Youtube", Selected = false }); return(await Task.Run(() => View(model))); }