public void CreateSlideShowMusicXref(SlideShowMusicXref xref)
 {
     db.SlideShowMusicXrefs.Add(xref);
     db.SaveChanges();
 }
        public ActionResult Create(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);
                    slideshow.AccountID = Convert.ToInt32(Session["UserAccountID"]);

                    string validation = ValidateInput(slideshow, Request.Form["txtSlideShowImages"].ToString());
                    if (!String.IsNullOrEmpty(validation))
                    {
                        ViewData["ValidationMessage"] = validation;
                        ViewData["ImageList"] = new SelectList(BuildImageList(), "Value", "Text", "");
                        ViewData["MusicList"] = new SelectList(BuildMusicList(), "Value", "Text", "");
                        ViewData["ImageUrl"] = firstfile;
                        ViewData["SlideShowImages"] = Request.Form["txtSlideShowImages"].ToString();
                        ViewData["MusicImages"] = 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", Request.Form["lstTransitionType"].ToString());

                        // 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
                    {
                        // Create the slideshow
                        slideshow.TransitionType = Request.Form["lstTransitionType"].ToString();
                        repository.CreateSlideShow(slideshow);

                        CommonMethods.CreateActivityLog((User)Session["User"], "Slide Show", "Add",
                            "Added slide show '" + slideshow.SlideShowName + "' - ID: " + slideshow.SlideShowID.ToString());

                        ISlideShowImageXrefRepository xrefrep = new EntitySlideShowImageXrefRepository();
                        ISlideShowMusicXrefRepository musicxrefrep = new EntitySlideShowMusicXrefRepository();
                        IImageRepository imgrep = new EntityImageRepository();
                        IMusicRepository musicrep = new EntityMusicRepository();

                        // 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(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(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", "Create POST", ex.Message);
                return RedirectToAction("Index", "ApplicationError");
            }
        }