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"); // If no player groups have been defined, create sample account data IPlayerGroupRepository pgrep = new EntityPlayerGroupRepository(); IEnumerable<PlayerGroup> pgs = pgrep.GetAllPlayerGroups(account.AccountID); if (pgs == null || pgs.Count() == 0) { acctrep.CreateSampleData(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"); } }
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; }