private List <SelectListItem> BuildPlayerGroupList(bool addAllItem) { // Build the player group list List <SelectListItem> pgitems = new List <SelectListItem>(); // Add an 'All' item at the top if (addAllItem) { SelectListItem all = new SelectListItem(); all.Text = "All Player Groups"; all.Value = "0"; pgitems.Add(all); } IPlayerGroupRepository pgrep = new EntityPlayerGroupRepository(); IEnumerable <PlayerGroup> pgs = pgrep.GetAllPlayerGroups(Convert.ToInt32(Session["UserAccountID"])); foreach (PlayerGroup pg in pgs) { SelectListItem item = new SelectListItem(); item.Text = pg.PlayerGroupName; item.Value = pg.PlayerGroupID.ToString(); pgitems.Add(item); } return(pgitems); }
public ActionResult Validate(FormCollection collection) { try { // Validate the login User user = repository.ValidateLogin(Request.Form["txtUsername"].ToString(), Request.Form["txtPassword"].ToString()); ViewData["FreeLinks"] = ""; if (ConfigurationManager.AppSettings["ShowFreeLinks"] == "true") { ViewData["FreeLinks"] = BuildFreeLinks(); } // Display the system messages, if any ViewData["SystemMessages"] = BuildSystemMessages(); if (user == null) { ViewData["Username"] = Request.Form["txtUsername"].ToString(); ViewData["Password"] = String.Empty; ViewData["ValidationMessage"] = "Invalid Login. Please try again."; ViewData["LoginInfo"] = "Please log in."; return(View()); } else { Session["User"] = user; Session["UserAccountID"] = user.AccountID; IAccountRepository acctrep = new EntityAccountRepository(); Account account = acctrep.GetAccount(user.AccountID); Session["UserAccountName"] = account.AccountName; // Make sure the Account Folders exist string serverpath = Server.MapPath("~/UploadedFiles"); if (!serverpath.EndsWith(@"\")) { serverpath += @"\"; } System.IO.Directory.CreateDirectory(serverpath + user.AccountID.ToString() + @"\Images"); System.IO.Directory.CreateDirectory(serverpath + user.AccountID.ToString() + @"\Videos"); System.IO.Directory.CreateDirectory(serverpath + user.AccountID.ToString() + @"\Music"); serverpath = Server.MapPath("~/Media"); if (!serverpath.EndsWith(@"\")) { serverpath += @"\"; } System.IO.Directory.CreateDirectory(serverpath + user.AccountID.ToString() + @"\Images"); System.IO.Directory.CreateDirectory(serverpath + user.AccountID.ToString() + @"\Videos"); System.IO.Directory.CreateDirectory(serverpath + user.AccountID.ToString() + @"\Music"); // Create example data for the account (if appropriate) IPlayerGroupRepository pgrep = new EntityPlayerGroupRepository(); IEnumerable <PlayerGroup> groups = pgrep.GetAllPlayerGroups(account.AccountID); if (groups == null || groups.Count() == 0) { acctrep.CreateExampleData(account.AccountID); } // Log the login ILoginLogRepository llrep = new EntityLoginLogRepository(); LoginLog loginlog = new LoginLog(); loginlog.AccountID = user.AccountID; loginlog.UserID = user.UserID; loginlog.Username = user.Username; loginlog.LoginDateTime = DateTime.Now.ToUniversalTime(); llrep.CreateLoginLog(loginlog); return(RedirectToAction("Index", "PlayerGroup")); } } catch (Exception ex) { Helpers.SetupApplicationError("Login", "Validate POST", ex.Message); return(RedirectToAction("Index", "ApplicationError")); } }
public ActionResult Edit(PlayerGroupSchedule playergroupschedule) { 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"; } int playergroupid = Convert.ToInt32(Request.Form["txtPlayerGroupID"]); int screenid = Convert.ToInt32(Request.Form["lstScreen"]); int hour = Convert.ToInt32(Request.Form["lstHour"]); int minute = Convert.ToInt32(Request.Form["lstMinute"]); if (!String.IsNullOrEmpty(Request.Form["chkSunday"])) { CreatePlayerGroupSchedule(playergroupid, screenid, 0, hour, minute); } if (!String.IsNullOrEmpty(Request.Form["chkMonday"])) { CreatePlayerGroupSchedule(playergroupid, screenid, 1, hour, minute); } if (!String.IsNullOrEmpty(Request.Form["chkTuesday"])) { CreatePlayerGroupSchedule(playergroupid, screenid, 2, hour, minute); } if (!String.IsNullOrEmpty(Request.Form["chkWednesday"])) { CreatePlayerGroupSchedule(playergroupid, screenid, 3, hour, minute); } if (!String.IsNullOrEmpty(Request.Form["chkThursday"])) { CreatePlayerGroupSchedule(playergroupid, screenid, 4, hour, minute); } if (!String.IsNullOrEmpty(Request.Form["chkFriday"])) { CreatePlayerGroupSchedule(playergroupid, screenid, 5, hour, minute); } if (!String.IsNullOrEmpty(Request.Form["chkSaturday"])) { CreatePlayerGroupSchedule(playergroupid, screenid, 6, hour, minute); } IPlayerGroupRepository pgrep = new EntityPlayerGroupRepository(); PlayerGroup playergroup = pgrep.GetPlayerGroup(playergroupid); ViewData["PlayerGroupID"] = playergroupid; ViewData["PlayerGroupName"] = playergroup.PlayerGroupName; ViewData["ScreenList"] = new SelectList(BuildScreenList(), "Value", "Text", ""); ViewData["HourList"] = new SelectList(BuildHourList(), "Value", "Text", ""); ViewData["MinuteList"] = new SelectList(BuildMinuteList(), "Value", "Text", ""); ViewData["ScheduleHTML"] = BuildScheduleTable(playergroupid); return(View(playergroupschedule)); } catch (Exception ex) { Helpers.SetupApplicationError("PlayerGroupSchedule", "Edit", ex.Message); return(RedirectToAction("Index", "ApplicationError")); } }
// // GET: /Player/ public ActionResult Index() { 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"; } // Initialize or get the page state using session PlayerPageState pagestate = GetPageState(); // Get the account id int accountid = 0; if (Session["UserAccountID"] != null) { accountid = Convert.ToInt32(Session["UserAccountID"]); } // Set and save the page state to the submitted form values if any values are passed if (Request.Form["lstAscDesc"] != null) { pagestate.AccountID = accountid; pagestate.PlayerGroupID = Convert.ToInt32(Request.Form["lstPlayerGroup"].ToString().Trim()); pagestate.PlayerName = Request.Form["txtPlayerName"].ToString().Trim(); if (Request.Form["chkIncludeInactive"].ToLower().StartsWith("true")) { pagestate.IncludeInactive = true; } else { pagestate.IncludeInactive = false; } pagestate.SortBy = Request.Form["lstSortBy"].ToString().Trim(); pagestate.AscDesc = Request.Form["lstAscDesc"].ToString().Trim(); pagestate.PageNumber = Convert.ToInt32(Request.Form["txtPageNumber"].ToString().Trim()); SavePageState(pagestate); } // Add the session values to the view data so they can be populated in the form ViewData["AccountID"] = pagestate.AccountID; ViewData["PlayerGroupID"] = pagestate.PlayerGroupID; ViewData["PlayerName"] = pagestate.PlayerName; ViewData["IncludeInactive"] = pagestate.IncludeInactive; ViewData["SortBy"] = pagestate.SortBy; ViewData["PlayerGroupList"] = new SelectList(BuildPlayerGroupList(true), "Value", "Text", pagestate.PlayerGroupID); ViewData["SortByList"] = new SelectList(BuildSortByList(), "Value", "Text", pagestate.SortBy); ViewData["AscDescList"] = new SelectList(BuildAscDescList(), "Value", "Text", pagestate.AscDesc); // Determine asc/desc bool isdescending = false; if (pagestate.AscDesc.ToLower().StartsWith("d")) { isdescending = true; } // Get a Count of all filtered records int recordcount = repository.GetPlayerRecordCount(pagestate.AccountID, pagestate.PlayerGroupID, pagestate.PlayerName, pagestate.IncludeInactive); // Determine the page count int pagecount = 1; if (recordcount > 0) { pagecount = recordcount / Constants.PageSize; if (recordcount % Constants.PageSize != 0) // Add a page if there are more records { pagecount = pagecount + 1; } } // Make sure the current page is not greater than the page count if (pagestate.PageNumber > pagecount) { pagestate.PageNumber = pagecount; SavePageState(pagestate); } // Set the page number and account in viewdata ViewData["PageNumber"] = Convert.ToString(pagestate.PageNumber); ViewData["PageCount"] = Convert.ToString(pagecount); ViewData["RecordCount"] = Convert.ToString(recordcount); // We need to add the player group name IEnumerable <Player> players = repository.GetPlayerPage(pagestate.AccountID, pagestate.PlayerGroupID, pagestate.PlayerName, pagestate.IncludeInactive, pagestate.SortBy, isdescending, pagestate.PageNumber, pagecount); List <PlayerView> playerviews = new List <PlayerView>(); IPlayerGroupRepository pgrep = new EntityPlayerGroupRepository(); foreach (Player player in players) { PlayerView playerview = new PlayerView(); playerview.PlayerID = player.PlayerID; playerview.AccountID = player.AccountID; playerview.PlayerGroupID = player.PlayerGroupID; playerview.PlayerName = player.PlayerName; playerview.PlayerLocation = player.PlayerLocation; playerview.PlayerDescription = player.PlayerDescription; playerview.IsActive = player.IsActive; PlayerGroup pg = pgrep.GetPlayerGroup(player.PlayerGroupID); playerview.PlayerGroupName = pg.PlayerGroupName; playerviews.Add(playerview); } ViewResult result = View(playerviews); result.ViewName = "Index"; return(result); } catch (Exception ex) { Helpers.SetupApplicationError("Player", "Index", ex.Message); return(RedirectToAction("Index", "ApplicationError")); } }