public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = BoardSquaresRepository.AttemptRegister(model);
                switch (result)
                {
                case -9:
                    ViewBag.ErrorMessage = "Error when creating user. Please try again later.";
                    return(View(model));

                case -8:
                    ViewBag.ErrorMessage = "An account with specified Email already exists.";
                    return(View(model));

                case -7:
                    ViewBag.ErrorMessage = "Desired User Name already exists. Please try a different one.";
                    return(View(model));

                case -6:
                    ViewBag.ErrorMessage = "Error validating user.";
                    return(View(model));

                case -5:
                    ViewBag.ErrorMessage = "Account Created, but Team Name already exists in game. Please Log in to create a team";
                    return(View(model));

                case -4:
                    ViewBag.ErrorMessage = "Game exists, but is currently full.";
                    return(View(model));

                case -3:
                    ViewBag.ErrorMessage = "Game is Closed.";
                    return(View(model));

                case -2:
                    ViewBag.ErrorMessage = "Game is Inactive.";
                    return(View(model));

                case -1:
                    ViewBag.ErrorMessage = "Game does not exist.";
                    return(View(model));

                default:
                    var user = BoardSquaresRepository.GetAllUsers().FirstOrDefault(u => u.UserName == model.UserName && u.Email == model.Email);
                    BoardSquaresRepository.CreateNewTeam(user.UserID, model.TeamName, model.GameNumber);
                    return(RedirectToAction("Games", "Home"));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public void GetUsers()
        {
            BoardSquaresRepository db = new BoardSquaresRepository();

            UserList = db.GetAllUsers();
            var userTeamList = db.Context.UserTeams.Where(g => g.Balance > 0).ToList();

            foreach (var user in UserList)
            {
                user.BalDue = 0;
                var teams = userTeamList.Where(g => g.UserID == user.UserID).Select(r => r.Balance).ToList();
                if (teams.Any())
                {
                    user.BalDue = Decimal.Round(teams.Sum(r => r), 2);
                }
            }
            UserList = UserList.OrderByDescending(r => r.BalDue).ThenBy(r => r.UserName).ToList();
        }