Ejemplo n.º 1
0
        public ActionResult Create(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);
                    playlist.AccountID = Convert.ToInt32(Session["UserAccountID"]);

                    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
                    {
                        // Create the playlist
                        repository.CreatePlayList(playlist);

                        CommonMethods.CreateActivityLog((User)Session["User"], "Play List", "Add",
                                "Added play list '" + playlist.PlayListName + "' - ID: " + playlist.PlayListID.ToString());

                        IPlayListVideoXrefRepository xrefrep = new EntityPlayListVideoXrefRepository();
                        IVideoRepository vidrep = new EntityVideoRepository();

                        // 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(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", "Create POST", ex.Message);
                return RedirectToAction("Index", "ApplicationError");
            }
        }
Ejemplo n.º 2
0
        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(guid.Trim());
                    if (vid != null)
                    {
                        SelectListItem item = new SelectListItem();
                        item.Text = vid.VideoName;
                        item.Value = vid.StoredFilename;

                        items.Add(item);
                    }
                }
            }

            return items;
        }