private List <SelectListItem> BuildSlideShowMusicList(string musicguids) { IMusicRepository musicrep = new EntityMusicRepository(); List <SelectListItem> items = new List <SelectListItem>(); // Get the music from the database string[] guids = musicguids.Split('|'); foreach (string guid in guids) { if (!String.IsNullOrEmpty(guid.Trim())) { Music music = musicrep.GetMusicByGuid(Convert.ToInt32(Session["UserAccountID"]), guid.Trim()); if (music != null) { SelectListItem item = new SelectListItem(); item.Text = music.MusicName; item.Value = music.StoredFilename; items.Add(item); } } } return(items); }
private Music CreateExampleMusic(int accountid, string musicname, string originalfilename, string storedfilename, string tags) { try { string sourcemusic = HttpContext.Current.Server.MapPath(@"~/ExampleMusic/" + storedfilename); string newmusic = HttpContext.Current.Server.MapPath(@"~/Media"); if (!newmusic.EndsWith(@"\")) newmusic += @"\"; System.IO.Directory.CreateDirectory(newmusic + Convert.ToString(accountid) + @"\Music\"); newmusic += Convert.ToString(accountid) + @"\Music\" + storedfilename; if (!System.IO.File.Exists(newmusic)) System.IO.File.Copy(sourcemusic, newmusic); IMusicRepository musicrep = new EntityMusicRepository(); Music music = musicrep.GetMusicByGuid(accountid, storedfilename); if (music == null || music.MusicID == 0) { music = new Music(); music.AccountID = accountid; music.MusicName = musicname; music.OriginalFilename = originalfilename; music.StoredFilename = storedfilename; music.Tags = tags; music.IsActive = true; musicrep.CreateMusic(music); } return music; } catch { return null; } }
public ActionResult Edit(SlideShow slideshow) { 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 slideshow = FillNulls(slideshow); string validation = ValidateInput(slideshow, Request.Form["txtSlideShowImages"].ToString()); if (!String.IsNullOrEmpty(validation)) { ViewData["ValidationMessage"] = validation; ViewData["ImageList"] = new SelectList(BuildImageList(), "Value", "Text", ""); ViewData["ImageUrl"] = firstfile; ViewData["SlideShowImages"] = Request.Form["txtSlideShowImages"].ToString(); ViewData["SlideShowMusic"] = Request.Form["txtSlideShowMusic"].ToString(); ViewData["SlideShowImageList"] = new SelectList(BuildSlideShowImageList(Request.Form["txtSlideShowImages"].ToString()), "Value", "Text", ""); ViewData["SlideShowMusicList"] = new SelectList(BuildSlideShowMusicList(Request.Form["txtSlideShowMusic"].ToString()), "Value", "Text", ""); ViewData["TransitionTypeList"] = new SelectList(BuildTransitionTypeList(), "Value", "Text", slideshow.TransitionType); // Get the account id int accountid = 0; if (Session["UserAccountID"] != null) { accountid = Convert.ToInt32(Session["UserAccountID"]); } ViewData["ImageFolder"] = ConfigurationManager.AppSettings["MediaRootFolder"] + Convert.ToString(Session["UserAccountID"]) + @"/Images/"; return(View(slideshow)); } else { // Update the slideshow slideshow.TransitionType = Request.Form["lstTransitionType"].ToString(); repository.UpdateSlideShow(slideshow); CommonMethods.CreateActivityLog((User)Session["User"], "Slide Show", "Edit", "Edited slide show '" + slideshow.SlideShowName + "' - ID: " + slideshow.SlideShowID.ToString()); ISlideShowImageXrefRepository xrefrep = new EntitySlideShowImageXrefRepository(); ISlideShowMusicXrefRepository musicxrefrep = new EntitySlideShowMusicXrefRepository(); IImageRepository imgrep = new EntityImageRepository(); IMusicRepository musicrep = new EntityMusicRepository(); // Delete existing xrefs for the slideshow xrefrep.DeleteSlideShowImageXrefs(slideshow.SlideShowID); musicxrefrep.DeleteSlideShowMusicXrefs(slideshow.SlideShowID); // Create a xref for each image in the slideshow string[] guids = Request.Form["txtSlideShowImages"].ToString().Split('|'); int i = 1; foreach (string guid in guids) { if (!String.IsNullOrEmpty(guid.Trim())) { Image img = imgrep.GetImageByGuid(Convert.ToInt32(Session["UserAccountID"]), guid); if (img != null) { SlideShowImageXref xref = new SlideShowImageXref(); xref.PlayOrder = i; xref.SlideShowID = slideshow.SlideShowID; xref.ImageID = img.ImageID; xrefrep.CreateSlideShowImageXref(xref); i += 1; } } } // Create a xref for each music file in the slideshow guids = Request.Form["txtSlideShowMusic"].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) { SlideShowMusicXref xref = new SlideShowMusicXref(); xref.PlayOrder = i; xref.SlideShowID = slideshow.SlideShowID; xref.MusicID = music.MusicID; musicxrefrep.CreateSlideShowMusicXref(xref); i += 1; } } } return(RedirectToAction("Index")); } } return(View(slideshow)); } catch (Exception ex) { Helpers.SetupApplicationError("SlideShow", "Edit POST", ex.Message); return(RedirectToAction("Index", "ApplicationError")); } }
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")); } }