public ActionResult Create() { var name = User.Identity.Name; UserPrincipal user; using (var pc = new PrincipalContext(ContextType.Domain, "smausa")) { user = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, name); } if (user == null) { throw new Exception("Active Directory user not found!"); } var player = new Player { Username = name, FirstName = user.GivenName, Surname = user.Surname, Email = user.EmailAddress, Notifications = !string.IsNullOrWhiteSpace(user.EmailAddress) }; return View(player); }
public static int UpdateImage(Player player) { using (var connection = ConnectionFactory.GetConnection()) { return connection.Execute(UpdateImageSql, player); } }
public PlayerDetail(Player player) { _player = player; Name = string.Format("{0} {1}", player.FirstName, player.Surname); FullName = string.IsNullOrWhiteSpace(player.Nickname) ? string.Format("{0} {1}", player.FirstName, player.Surname) : string.Format("{0} \"{1}\" {2}", player.FirstName, player.Nickname, player.Surname); var matches = new List<PlayerMatch>(); Records = new List<PlayerRecord>(); foreach (var match in Global.Matches.Where(m => m.PlayerOneId == player.Id || m.PlayerTwoId == player.Id)) { var playerMatch = new PlayerMatch(player.Id, match); matches.Add(playerMatch); var r = Records.SingleOrDefault(record => record.OpponentId == playerMatch.OpponentId); if (r != null) { if (playerMatch.WinningPlayerId == player.Id) { r.Wins++; } else { r.Losses++; } r.Games++; r.CalculatePercentage(); } else { r = playerMatch.WinningPlayerId == player.Id ? new PlayerRecord(playerMatch.OpponentId, playerMatch.Opponent, 1, 0) : new PlayerRecord(playerMatch.OpponentId, playerMatch.Opponent, 0, 1); Records.Add(r); } } Matches = matches.OrderByDescending(m => m.MatchDate).ToList(); OverallRecord = new Record(Matches.Count(m => m.WinningPlayerId == player.Id), Matches.Count(m => m.WinningPlayerId != player.Id)); Records = Records.OrderByDescending(r => r.Games).ToList(); var lastMatch = Matches.FirstOrDefault(match => match.MatchDate == Matches.Max(m => m.MatchDate)); Pending = (lastMatch != null && lastMatch.PostDate == null) ? string.Format("{1}{0:0.0000}", lastMatch.Mu - player.Mu, (lastMatch.Mu - player.Mu) > 0 ? "+" : string.Empty) : string.Empty; }