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));
        }
        private void CreateNew()
        {
            if (string.IsNullOrEmpty(NewGameCode) || string.IsNullOrEmpty(NewTeamName))
            {
                ErrorMessage = "Must supply Game Code and New Team Name";
                IsValid      = false;
                return;
            }
            BoardSquaresRepository db = new BoardSquaresRepository();
            int result = db.CreateNewTeam(User.UserID, NewTeamName, NewGameCode);

            switch (result)
            {
            case -9:
                ErrorMessage = "Error when creating user. Please try again later.";
                IsValid      = false;
                break;

            case -8:
                ErrorMessage = "An account with specified Email already exists.";
                IsValid      = false;
                break;

            case -7:
                ErrorMessage = "Desired User Name already exists. Please try a different one.";
                IsValid      = false;
                break;

            case -6:
                ErrorMessage = "Error validating user.";
                IsValid      = false;
                break;

            case -5:
                ErrorMessage = "Team Name already exists in game.";
                IsValid      = false;
                break;

            case -4:
                ErrorMessage = "Game exists, but is currently full.";
                IsValid      = false;
                break;

            case -3:
                ErrorMessage = "Game is Closed.";
                IsValid      = false;
                break;

            case -2:
                ErrorMessage = "Game is Inactive.";
                IsValid      = false;
                break;

            case -1:
                ErrorMessage = "Game does not exist.";
                IsValid      = false;
                break;

            case 1:
                ConfirmationMessage = "Successfully Created " + NewTeamName;
                NewGameCode         = "";
                NewTeamName         = "";
                break;

            default:
                ErrorMessage = "Something went wrong. Contact an Admin";
                IsValid      = false;
                break;
            }
        }