private List <SelectListItem> BuildPlayListVideoList(string videoguids) { IVideoRepository vidrep = new EntityVideoRepository(); List <SelectListItem> items = new List <SelectListItem>(); // Get the video from the database string[] guids = videoguids.Split('|'); foreach (string guid in guids) { if (!String.IsNullOrEmpty(guid.Trim())) { Video vid = vidrep.GetVideoByGuid(Convert.ToInt32(Session["UserAccountID"]), guid.Trim()); if (vid != null) { SelectListItem item = new SelectListItem(); item.Text = vid.VideoName; item.Value = vid.StoredFilename; items.Add(item); } } } return(items); }
private List <SelectListItem> BuildTimelineMediaList(string mediaguids) { IImageRepository imgrep = new EntityImageRepository(); IVideoRepository vidrep = new EntityVideoRepository(); List <SelectListItem> items = new List <SelectListItem>(); // Get the images and videos from the database string[] guids = mediaguids.Split('|'); foreach (string guid in guids) { if (!String.IsNullOrEmpty(guid.Trim())) { Image img = imgrep.GetImageByGuid(Convert.ToInt32(Session["UserAccountID"]), guid.Trim()); if (img != null) { SelectListItem item = new SelectListItem(); item.Text = img.ImageName + " (Image)"; item.Value = img.StoredFilename; items.Add(item); } else { Video vid = vidrep.GetVideoByGuid(Convert.ToInt32(Session["UserAccountID"]), guid.Trim()); if (vid != null) { SelectListItem item = new SelectListItem(); item.Text = vid.VideoName + " (Video)"; item.Value = vid.StoredFilename; items.Add(item); } } } } return(items); }
public ActionResult Edit(PlayList playlist) { try { if (Session["UserAccountID"] == null) { return(RedirectToAction("Validate", "Login")); } User user = (User)Session["User"]; ViewData["LoginInfo"] = Utility.BuildUserAccountString(user.Username, Convert.ToString(Session["UserAccountName"])); if (user.IsAdmin) { ViewData["txtIsAdmin"] = "true"; } else { ViewData["txtIsAdmin"] = "false"; } if (ModelState.IsValid) { // Set NULLs to Empty Strings playlist = FillNulls(playlist); string validation = ValidateInput(playlist, Request.Form["txtPlayListVideos"].ToString()); if (!String.IsNullOrEmpty(validation)) { ViewData["ValidationMessage"] = validation; ViewData["VideoList"] = new SelectList(BuildVideoList(), "Value", "Text", ""); ViewData["VideoUrl"] = firstfile; ViewData["PlayListVideos"] = Request.Form["txtPlayListVideos"].ToString(); ViewData["PlayListVideoList"] = new SelectList(BuildPlayListVideoList(Request.Form["txtPlayListVideos"].ToString()), "Value", "Text", ""); // Get the account id int accountid = 0; if (Session["UserAccountID"] != null) { accountid = Convert.ToInt32(Session["UserAccountID"]); } ViewData["VideoFolder"] = ConfigurationManager.AppSettings["MediaRootFolder"] + Convert.ToString(Session["UserAccountID"]) + @"/Videos/"; return(View(playlist)); } else { // Update the playlist repository.UpdatePlayList(playlist); CommonMethods.CreateActivityLog((User)Session["User"], "Play List", "Edit", "Edited play list '" + playlist.PlayListName + "' - ID: " + playlist.PlayListID.ToString()); IPlayListVideoXrefRepository xrefrep = new EntityPlayListVideoXrefRepository(); IVideoRepository vidrep = new EntityVideoRepository(); // Delete existing xrefs for the playlist xrefrep.DeletePlayListVideoXrefs(playlist.PlayListID); // Create a xref for each video in the playlist string[] guids = Request.Form["txtPlayListVideos"].ToString().Split('|'); int i = 1; foreach (string guid in guids) { if (!String.IsNullOrEmpty(guid.Trim())) { Video vid = vidrep.GetVideoByGuid(Convert.ToInt32(Session["UserAccountID"]), guid); if (vid != null) { PlayListVideoXref xref = new PlayListVideoXref(); xref.PlayOrder = i; xref.PlayListID = playlist.PlayListID; xref.VideoID = vid.VideoID; xrefrep.CreatePlayListVideoXref(xref); i += 1; } } } return(RedirectToAction("Index")); } } return(View(playlist)); } catch (Exception ex) { Helpers.SetupApplicationError("PlayList", "Edit POST", ex.Message); return(RedirectToAction("Index", "ApplicationError")); } }
private Video CreateExampleVideo(int accountid, string videoname, string originalfilename, string storedfilename, string tags) { try { string sourcevideo = HttpContext.Current.Server.MapPath(@"~/ExampleVideos/" + storedfilename); string newvideo = HttpContext.Current.Server.MapPath(@"~/Media"); if (!newvideo.EndsWith(@"\")) newvideo += @"\"; System.IO.Directory.CreateDirectory(newvideo + Convert.ToString(accountid) + @"\Videos\"); newvideo += Convert.ToString(accountid) + @"\Videos\" + storedfilename; if (!System.IO.File.Exists(newvideo)) System.IO.File.Copy(sourcevideo, newvideo); IVideoRepository videorep = new EntityVideoRepository(); Video video = videorep.GetVideoByGuid(accountid, storedfilename); if (video == null || video.VideoID == 0) { video = new Video(); video.AccountID = accountid; video.VideoName = videoname; video.OriginalFilename = originalfilename; video.StoredFilename = storedfilename; video.Tags = tags; video.IsActive = true; videorep.CreateVideo(video); } return video; } catch { return null; } }
public ActionResult Edit(Timeline timeline) { try { if (Session["UserAccountID"] == null) { return(RedirectToAction("Validate", "Login")); } User user = (User)Session["User"]; ViewData["LoginInfo"] = Utility.BuildUserAccountString(user.Username, Convert.ToString(Session["UserAccountName"])); if (user.IsAdmin) { ViewData["txtIsAdmin"] = "true"; } else { ViewData["txtIsAdmin"] = "false"; } if (ModelState.IsValid) { // Set NULLs to Empty Strings timeline = FillNulls(timeline); timeline.AccountID = Convert.ToInt32(Session["UserAccountID"]); string validation = ValidateInput(timeline); if (!String.IsNullOrEmpty(validation)) { ViewData["ValidationMessage"] = validation; ViewData["ImageList"] = new SelectList(BuildImageList(), "Value", "Text", ""); ViewData["MusicList"] = new SelectList(BuildMusicList(), "Value", "Text", ""); ViewData["VideoList"] = new SelectList(BuildVideoList(), "Value", "Text", ""); ViewData["TimelineMediaList"] = new SelectList(BuildTimelineMediaList(Request.Form["txtTimelineMedia"].ToString()), "Value", "Text", ""); ViewData["TimelineMusicList"] = new SelectList(BuildTimelineMusicList(Request.Form["txtTimelineMusic"].ToString()), "Value", "Text", ""); ViewData["TimelineMedia"] = Request.Form["txtTimelineMedia"].ToString();; ViewData["TimelineMusic"] = Request.Form["txtTimelineMusic"].ToString();; ViewData["ImageUrl"] = firstimagefile; ViewData["ImageFolder"] = ConfigurationManager.AppSettings["MediaRootFolder"] + Convert.ToString(Session["UserAccountID"]) + @"/Images/"; ViewData["VideoUrl"] = firstvideofile; ViewData["VideoFolder"] = ConfigurationManager.AppSettings["MediaRootFolder"] + Convert.ToString(Session["UserAccountID"]) + @"/Videos/"; return(View(timeline)); } else { // Update the timeline repository.UpdateTimeline(timeline); CommonMethods.CreateActivityLog((User)Session["User"], "Timeline", "Edit", "Edited timeline '" + timeline.TimelineName + "' - ID: " + timeline.TimelineID.ToString()); string[] guids; int i = 0; // Delete the image, video, and music xrefs, then create new ones ITimelineImageXrefRepository imagexrefrep = new EntityTimelineImageXrefRepository(); ITimelineVideoXrefRepository videoxrefrep = new EntityTimelineVideoXrefRepository(); ITimelineMusicXrefRepository musicxrefrep = new EntityTimelineMusicXrefRepository(); imagexrefrep.DeleteTimelineImageXrefs(timeline.TimelineID); videoxrefrep.DeleteTimelineVideoXrefs(timeline.TimelineID); musicxrefrep.DeleteTimelineMusicXrefs(timeline.TimelineID); // Create the image xrefs IImageRepository imagerep = new EntityImageRepository(); guids = Request.Form["txtTimelineMedia"].ToString().Split('|'); i = 1; foreach (string guid in guids) { if (!String.IsNullOrEmpty(guid.Trim())) { Image image = imagerep.GetImageByGuid(Convert.ToInt32(Session["UserAccountID"]), guid); if (image != null) { TimelineImageXref xref = new TimelineImageXref(); xref.DisplayOrder = i; xref.TimelineID = timeline.TimelineID; xref.ImageID = image.ImageID; imagexrefrep.CreateTimelineImageXref(xref); } i += 1; } } // Create the video xrefs IVideoRepository videorep = new EntityVideoRepository(); guids = Request.Form["txtTimelineMedia"].ToString().Split('|'); i = 1; foreach (string guid in guids) { if (!String.IsNullOrEmpty(guid.Trim())) { Video video = videorep.GetVideoByGuid(Convert.ToInt32(Session["UserAccountID"]), guid); if (video != null) { TimelineVideoXref xref = new TimelineVideoXref(); xref.DisplayOrder = i; xref.TimelineID = timeline.TimelineID; xref.VideoID = video.VideoID; videoxrefrep.CreateTimelineVideoXref(xref); } i += 1; } } // Create the music xrefs IMusicRepository musicrep = new EntityMusicRepository(); guids = Request.Form["txtTimelineMusic"].ToString().Split('|'); i = 1; foreach (string guid in guids) { if (!String.IsNullOrEmpty(guid.Trim())) { Music music = musicrep.GetMusicByGuid(Convert.ToInt32(Session["UserAccountID"]), guid); if (music != null) { TimelineMusicXref xref = new TimelineMusicXref(); xref.PlayOrder = i; xref.TimelineID = timeline.TimelineID; xref.MusicID = music.MusicID; musicxrefrep.CreateTimelineMusicXref(xref); i += 1; } } } return(RedirectToAction("Index")); } } return(View(timeline)); } catch (Exception ex) { Helpers.SetupApplicationError("Timeline", "Edit POST", ex.Message); return(RedirectToAction("Index", "ApplicationError")); } }