public async Task<ActionResult> Index() { try { using (ScoutDB db = new ScoutDB()) { List<SchoolDashboardModel> schools = new List<SchoolDashboardModel>(); if (this.HttpContext.Profile != null && this.HttpContext.Profile.Context != null) { Person p = this.HttpContext.Profile.Context["Person"].Deserialize<Person>(); schools = await (from x in db.ScoutAssignments join y in db.Schools on x.SchoolId equals y.SchoolId where x.ScoutId == p.PersonId && !y.Deleted select new SchoolDashboardModel() { SchoolCode = y.SchoolCode, GreenBookName = y.GreenBookName }).ToListAsync(); } if (schools.Count == 0) schools = new List<SchoolDashboardModel>(); return View(schools); } } catch (DataException dex) { ModelState.AddModelError(string.Empty, "Unable to load school list. Try again, and if the problem persists see your system administrator."); return RedirectToAction("List"); } }
/// <summary> /// Loads a list of schools from the database. /// </summary> /// <returns> /// Returns a list of schools from the database. /// </returns> public async Task<ActionResult> List() { try { using (ScoutDB db = new ScoutDB()) { List<SchoolListModel> schools = await (from x in db.vwSchoolPartialLists select new SchoolListModel() { SchoolCode = x.SchoolCode, ScoutArea = x.ScoutArea, School = x.School, SchoolShortName = x.SchoolShortName, GreenBookName = x.GreenBookName, NickName = x.NickName, Association = x.Association, Division = x.Division, Conference = x.Conference, QuestionaireFileName = x.QuestionaireFileName, SchoolAddress = x.SchoolAddress, FootballAddress = x.FootballAddress, HeadCoachName = x.HeadCoachName, AssistantCoaches = x.AssistantCoaches, VideoDirector = x.VideoDirector, AthleticDir = x.AthleticDir, SportsInfoDir = x.SportsInfoDir, ProLiaison = x.ProLiaison, NationalGradedPlayers = x.NationalGradedPlayers, FalconsGradedPlayers = x.FalconsGradedPlayers, WorkoutDate = x.WorkoutDate, WorkoutDate2 = x.WorkoutDate2, PrimaryScoutID = x.PrimaryScoutID, SecondaryScoutID = x.SecondaryScoutID, PrimaryAreaScoutID = x.PrimaryAreaScoutID, RegionalScoutID = x.RegionalScoutID, FBWebsite = x.FBWebsite, RivalsURL = x.RivalsURL, RivalsAltURL = x.RivalsAltURL, NFLSchoolID = x.NFLSchoolID, ESPN_ID = x.ESPN_ID }).ToListAsync(); if (schools == null || schools.Count == 0) schools = new List<SchoolListModel>(); return View(schools); } } catch (DataException dex) { ModelState.AddModelError(string.Empty, "Unable to load school list. Try again, and if the problem persists see your system administrator."); return RedirectToAction("List"); } }
/// <summary> /// Displays the details page for the specified player. /// </summary> /// <param name="code">The PlayerId of the player to display.</param> /// <returns> /// Returns all of the data associated with the specified player if successful; otherwise returns the /// user to the List view with an error message. /// </returns> public async Task<ActionResult> Details(int? code) { var z = this.HttpContext; try { if (code == null || code == 0) { ModelState.AddModelError(string.Empty, "Unable to find player. Try again, and if the problem persists see your system administrator."); return RedirectToAction("List"); } using (ScoutDB db = new ScoutDB()) { PlayerModel player = await (from x in db.vwSchoolPlayerLists where x.PlayerId == code select new PlayerModel() { SchoolId = x.SchoolId, PersonId = x.PersonId, PlayerId = x.PlayerId, SchoolCode = x.SchoolCode, ScoutArea = x.ScoutArea, SchoolName = x.SchoolName, GreenBookName = x.GreenBookName, Prefix = x.Prefix, FirstName = x.FirstName, MiddleName = x.MiddleName, LastName = x.LastName, Suffix = x.Suffix, FullName = x.FullName, Phone = x.Phone, Fax = x.Fax, Email = x.Email, Jersey = x.Jersey, Eligibility = x.Eligibility, HometownCity = x.HometownCity, HometownState = x.HometownState, Height = x.Height, Weight = x.Weight, Speed = x.Speed, Position = x.Position, PlayerDateModified = x.PlayerDateModified, PersonDateModified = x.PersonDateModified }).FirstOrDefaultAsync(); if (player == null) { ModelState.AddModelError(string.Empty, "Unable to find player. Try again, and if the problem persists see your system administrator."); return RedirectToAction("List"); } return View(player); } } catch (DataException dex) { ModelState.AddModelError(string.Empty, "Unable to find player to display. Try again, and if the problem persists see your system administrator."); return RedirectToAction("List"); } }
/// <summary> /// Loads a list of players from the database. /// </summary> /// <param name="code">The SchoolCode of the school's players to display.</param> /// <returns> /// Returns a list of players from the database. /// </returns> public async Task<ActionResult> List(string code) { try { using (ScoutDB db = new ScoutDB()) { List<PlayerModel> players; if (string.IsNullOrWhiteSpace(code)) { ViewBag.Title = "All Players List"; players = await (from x in db.vwSchoolPlayerLists orderby x.PlayerId select new PlayerModel() { SchoolId = x.SchoolId, PersonId = x.PersonId, PlayerId = x.PlayerId, SchoolCode = x.SchoolCode, ScoutArea = x.ScoutArea, SchoolName = x.SchoolName, GreenBookName = x.GreenBookName, Prefix = x.Prefix, FirstName = x.FirstName, MiddleName = x.MiddleName, LastName = x.LastName, Suffix = x.Suffix, FullName = x.FullName, Phone = x.Phone, Fax = x.Fax, Email = x.Email, Jersey = x.Jersey, Eligibility = x.Eligibility, HometownCity = x.HometownCity, HometownState = x.HometownState, Height = x.Height, Weight = x.Weight, Speed = x.Speed, Position = x.Position, PlayerDateModified = x.PlayerDateModified, PersonDateModified = x.PersonDateModified }).ToListAsync(); } else { ViewBag.Title = string.Format("{0} Players List", code); players = await (from x in db.vwSchoolPlayerLists where x.SchoolCode == code orderby x.PlayerId select new PlayerModel() { SchoolId = x.SchoolId, PersonId = x.PersonId, PlayerId = x.PlayerId, SchoolCode = x.SchoolCode, ScoutArea = x.ScoutArea, SchoolName = x.SchoolName, GreenBookName = x.GreenBookName, Prefix = x.Prefix, FirstName = x.FirstName, MiddleName = x.MiddleName, LastName = x.LastName, Suffix = x.Suffix, FullName = x.FullName, Phone = x.Phone, Fax = x.Fax, Email = x.Email, Jersey = x.Jersey, Eligibility = x.Eligibility, HometownCity = x.HometownCity, HometownState = x.HometownState, Height = x.Height, Weight = x.Weight, Speed = x.Speed, Position = x.Position, PlayerDateModified = x.PlayerDateModified, PersonDateModified = x.PersonDateModified }).ToListAsync(); } if (players == null || players.Count == 0) players = new List<PlayerModel>(); return View(players); } } catch (DataException dex) { ModelState.AddModelError(string.Empty, "Unable to load player list. Try again, and if the problem persists see your system administrator."); return RedirectToAction("List"); } }
public async Task<ActionResult> Edit(int code, [Bind(Include = "PlayerId, PersonId, Prefix, FirstName, MiddleName, LastName, Suffix, HometownCity, HometownState, Position, PersonDateModified, PlayerDateModified")] PlayerModel player) { try { if (code == 0) { ModelState.AddModelError(string.Empty, "Unable to find player. Try again, and if the problem persists see your system administrator."); return RedirectToAction("List"); } if (!ModelState.IsValid) { ModelState.AddModelError(string.Empty, "Unable to edit player. Try again, and if the problem persists see your system administrator."); return View(player); } using (ScoutDB db = new ScoutDB()) { vwSchoolPlayerList p = await db.vwSchoolPlayerLists.FirstOrDefaultAsync(x => x.PlayerId == code); if (p == null) { ModelState.AddModelError(string.Empty, "Unable to edit player. Try again, and if the problem persists see your system administrator."); return View(player); } if ((p.PlayerDateModified.ToString() != player.PlayerDateModified.ToString()) || (p.PersonDateModified.ToString() != player.PersonDateModified.ToString())) { if (p.Prefix != player.Prefix) ModelState.AddModelError("Prefix", string.Format("New: {0}", p.Prefix)); if (p.FirstName != player.FirstName) ModelState.AddModelError("FirstName", string.Format("New: {0}", p.FirstName)); if (p.MiddleName != player.MiddleName) ModelState.AddModelError("MiddleName", string.Format("New: {0}", p.MiddleName)); if (p.LastName != player.LastName) ModelState.AddModelError("LastName", string.Format("New: {0}", p.LastName)); if (p.Suffix != player.Suffix) ModelState.AddModelError("Suffix", string.Format("New: {0}", p.Suffix)); if (p.HometownCity != player.HometownCity) ModelState.AddModelError("HometownCity", string.Format("New: {0}", p.HometownCity)); if (p.HometownState != player.HometownState) ModelState.AddModelError("HometownState", string.Format("New: {0}", p.HometownState)); if (p.Position != player.Position) ModelState.AddModelError("Position", string.Format("New: {0}", p.Position.ToString())); ModelState.AddModelError(string.Empty, "The player you attempted to edit was successfully edited by another user after you had already loaded the Edit page.<br>The new values are displayed in red under their field for your review.<br>You have the following options:<br><br>1) Click the 'Cancel' button to keep the values entered by the other user<br>2) Click the 'Save Player' button to overwrite the values entered by the other user with the ones you provided."); player.PlayerDateModified = p.PlayerDateModified; player.PersonDateModified = p.PersonDateModified; return View(player); } List<string> changed = new List<string>(); Player NewPlayer = await db.Players.FirstOrDefaultAsync(x => x.PlayerId == p.PlayerId); Person NewPerson = await db.Persons.FirstOrDefaultAsync(x => x.PersonId == p.PersonId); if (p.Prefix != player.Prefix) { changed.Add("Prefix: '" + p.Prefix + "' => '" + player.Prefix + "'"); NewPerson.Prefix = player.Prefix; } if (p.FirstName != player.FirstName) { changed.Add("FirstName: '" + p.FirstName + "' => '" + player.FirstName + "'"); NewPerson.FirstName = player.FirstName; } if (p.MiddleName != player.MiddleName) { changed.Add("MiddleName: '" + p.MiddleName + "' => '" + player.MiddleName + "'"); NewPerson.MiddleName = player.MiddleName; } if (p.LastName != player.LastName) { changed.Add("LastName: '" + p.LastName + "' => '" + player.LastName + "'"); NewPerson.LastName = player.LastName; } if (p.Suffix != player.Suffix) { changed.Add("Suffix: '" + p.Suffix + "' => '" + player.Suffix + "'"); NewPerson.Suffix = player.Suffix; } if (p.HometownCity != player.HometownCity) { changed.Add("HometownCity: '" + p.HometownCity + "' => '" + player.HometownCity + "'"); NewPlayer.HometownCity = player.HometownCity; } if (p.HometownState != player.HometownState) { changed.Add("HometownState: '" + p.HometownState + "' => '" + player.HometownState + "'"); NewPlayer.HometownState = player.HometownState; } if (p.Position != player.Position) { changed.Add("Position: '" + p.Position.ToString() + "' => '" + player.Position.ToString() + "'"); NewPlayer.Position = player.Position; } if (changed.Count == 0) { ModelState.AddModelError(string.Empty, "Unable to edit player. You did not appear to make any changes."); return View(player); } NewPlayer.DateModified = DateTime.Now; NewPerson.DateModified = DateTime.Now; await db.SaveChangesAsync(); return RedirectToAction("List"); } } catch (DataException dex) { ModelState.AddModelError(string.Empty, "Unable to edit player. Try again, and if the problem persists see your system administrator."); return View(player); } }
public async Task<ActionResult> Login(LoginModel model, string returnUrl) { if (!ModelState.IsValid) return View(model); string pwd = model.Password; model.Password = model.Password.ToSHA256(); ApplicationUser f = await UserManager.FindAsync(model.Username, model.Password); if (f == null) { ApplicationUser user = new ApplicationUser { UserName = model.Username, Email = "" }; IdentityResult r = await UserManager.CreateAsync(user, model.Password); if (!r.Succeeded) { ModelState.AddModelError(string.Empty, r.Errors.ToString()); return View(model); } } using (ScoutDB db = new ScoutDB()) { Scout s = db.Scouts.FirstOrDefault(x => x.Username == model.Username && x.Password == model.Password && !x.Deleted); if (s != null) { SignInStatus result = await SignInManager.PasswordSignInAsync(model.Username, model.Password, model.RememberMe, shouldLockout: false); switch (result) { case SignInStatus.Success: ControllerContext.HttpContext.Profile.Initialize(model.Username, true); ControllerContext.HttpContext.Profile.Context.Add("Person", db.Persons.FirstOrDefault(x => x.PersonId == s.PersonId && !x.Deleted).Serialize()); return RedirectToLocal(returnUrl); case SignInStatus.LockedOut: return View("Lockout"); case SignInStatus.RequiresVerification: return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); model.Password = pwd; return View(model); } } else { ModelState.AddModelError("", "Invalid login attempt."); return View(model); } } }
/// <summary> /// Displays the details page for the specified school. /// </summary> /// <param name="code">The SchoolCode of the school to display.</param> /// <returns> /// Returns all of the data associated with the specified school if successful; otherwise returns the /// user to the List view with an error message. /// </returns> public async Task<ActionResult> Details(string code) { try { if (string.IsNullOrWhiteSpace(code)) { ModelState.AddModelError(string.Empty, "Unable to find school. Try again, and if the problem persists see your system administrator."); return RedirectToAction("List"); } using (ScoutDB db = new ScoutDB()) { SchoolDetailsModel school = await (from x in db.vwSchoolFullLists where x.SchoolCode == code select new SchoolDetailsModel() { SchoolCode = x.SchoolCode, ScoutArea = x.ScoutArea, School = x.School, ESPN_ID = x.ESPN_ID, SchoolShortName = x.SchoolShortName, GreenBookName = x.GreenBookName, NickName = x.NickName, Association = x.Association, Division = x.Division, Conference = x.Conference, QuestionaireFileName = x.QuestionaireFileName, AddressLine1 = x.AddressLine1, City = x.City, State = x.State, ZipCode = x.ZipCode, Country = x.Country, HeadCoachName = x.HeadCoachName, HeadCoachPhone = x.HeadCoachPhone, HeadCoachEmail = x.HeadCoachEmail, AssistantCoaches = x.AssistantCoaches, AssistantPhone = x.AssistantPhone, VideoDirector = x.VideoDirector, VideoDirPhone = x.VideoDirPhone, AthleticDir = x.AthleticDir, AthleticDirPhone = x.AthleticDirPhone, AthleticDirEmail = x.AthleticDirEmail, AthleticDirFax = x.AthleticDirFax, SportsInfoDir = x.SportsInfoDir, SIDPhone = x.SIDPhone, SIDFax = x.SIDFax, SIDEmail = x.SIDEmail, Trainer = x.Trainer, TrainerPhone = x.TrainerPhone, StrengthCoach = x.StrengthCoach, StrCoachPhone = x.StrCoachPhone, EquipManager = x.EquipManager, EquipManagerPhone = x.EquipManagerPhone, PressBoxPhone = x.PressBoxPhone, NationalGradedPlayers = x.NationalGradedPlayers, FalconsGradedPlayers = x.FalconsGradedPlayers, PrimaryScoutID = x.PrimaryScoutID, SecondaryScoutID = x.SecondaryScoutID, BowlGame = x.BowlGame, GradDate = x.GradDate, HomeField = x.HomeField, Capacity = x.Capacity, Surface = x.Surface, SchoolColors = x.SchoolColors, FBWebsite = x.FBWebsite, TransmitFlag = x.TransmitFlag, BowlGameDate = x.BowlGameDate, BowlGameText = x.BowlGameText, BowlGameOpponent = x.BowlGameOpponent, BowlGameTV = x.BowlGameTV, IsNew = x.IsNew, WorkoutDate = x.WorkoutDate, WorkoutDate2 = x.WorkoutDate2, ProLiaison = x.ProLiaison, ProLiaisonPhone = x.ProLiaisonPhone, Secretary = x.Secretary, SecretaryPhone = x.SecretaryPhone, PrimaryAreaScoutID = x.PrimaryAreaScoutID, RegionalScoutID = x.RegionalScoutID, Misc1 = x.Misc1, Misc2 = x.Misc2, Misc3 = x.Misc3, RivalsURL = x.RivalsURL, RivalsAltURL = x.RivalsAltURL, Comments = x.Comments, InstitutionID = x.InstitutionID, BCSSchool = x.BCSSchool, HideBirthdate = x.HideBirthdate, NFLSchoolID = x.NFLSchoolID, Notes = x.Notes, Restrictions = x.Restrictions, ClosedDates = x.ClosedDates, InSeasonSchedule = x.InSeasonSchedule, RestrictionsCompleted = x.RestrictionsCompleted, RestrictionsCompletedBy = x.RestrictionsCompletedBy, FootballAddress = x.FootballAddress, isAPT = x.isAPT, APTClub = x.APTClub, Latitude = x.Latitude, Longitude = x.Longitude, HBCU = x.HBCU }).FirstOrDefaultAsync(); if (school == null) { ModelState.AddModelError(string.Empty, "Unable to find school. Try again, and if the problem persists see your system administrator."); return RedirectToAction("List"); } return View(school); } } catch (DataException dex) { ModelState.AddModelError(string.Empty, "Unable to find school to display. Try again, and if the problem persists see your system administrator."); return RedirectToAction("List"); } }