示例#1
0
        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"));
            }
        }