Esempio n. 1
0
        public ScoreResponeType Execute(Match match, string score1String, string score2String)
        {
            int score1, score2;

            if (Int32.TryParse(score1String, out score1))
            {
                if (Int32.TryParse(score2String, out score2))
                {
                    if (score1 + score2 > 5)
                    {
                        return(ScoreResponeType.too_big_values);
                    }
                    else
                    {
                        var newGame = new Game(score1, score2);
                        _gameDao.CreateGame(newGame, match);
                        if (score1 > score2)
                        {
                            return(ScoreResponeType.player1_won);
                        }
                        return(ScoreResponeType.player2_won);
                    }
                }
                else
                {
                    return(ScoreResponeType.nonnumeric);
                }
            }
            else
            {
                return(ScoreResponeType.nonnumeric);
            }
        }
Esempio n. 2
0
        public ActionResult CreateGame(GamePO newGame)
        {
            ActionResult response;

            //check for admin
            if (Session["RoleID"] != null && (int)Session["RoleID"] == 6)
            {
                //if the user is an admin, check the model
                if (ModelState.IsValid)
                {
                    //if the model is valid, access the database
                    try
                    {
                        //map to data layer, access database
                        GameDO game = _GameMapper.MapPOtoDO(newGame);
                        _GameDataAccess.CreateGame(game);

                        response = RedirectToAction("Index", "Game");
                    }
                    catch (Exception ex)
                    {
                        //log error
                        _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
                        TempData["GameError"] = "There was an error processing this game, please check the information you entered and try again.";
                        response = View(newGame);
                    }
                    finally { }
                }
                else
                {
                    //if the model is not valid, return to the form
                    response = View(newGame);
                }
            }
            else
            {
                //if the user is not an admin, redirect to the login page
                response = RedirectToAction("Login", "Account");
            }

            return(response);
        }