public RestDTO GetByID(int id)
        {
            try
            {
                GameRecordService service = new GameRecordService();

                GameRecordModel businessLayerResponseModel = service.RetrieveByID(id);

                if (businessLayerResponseModel == null)
                {
                    return(new RestDTO(404, "Game Not Found", null));
                }

                List <Object> data = new List <Object>();

                data.Add(businessLayerResponseModel);

                return(new RestDTO(200, "OK", data));
            }

            catch (Exception)
            {
                return(new RestDTO(500, "System Error", null));
            }
        }
        public RestDTO GetByName(string name)
        {
            try
            {
                GameRecordService service = new GameRecordService();
                List <Object>     data    = service.RetrieveByUser(name);

                if (data.Count == 0)
                {
                    return(new RestDTO(404, "User not found", null));
                }

                return(new RestDTO(200, "OK", data));
            }

            catch (Exception)
            {
                return(new RestDTO(500, "System Error", null));
            }
        }
Пример #3
0
        public ActionResult HandleCellClick(string cell)
        {
            try
            {
                Logger.Info("Entering GameController.HandleCellClick()");
                GameService gameService = new GameService();

                string[] coords = cell.Split(',');

                // determine which cell was clicked
                Bundle.Row    = Convert.ToInt32(coords[0]);
                Bundle.Column = Convert.ToInt32(coords[1]);

                Logger.Info("Values parsed " + Bundle.Row + "," + Bundle.Column);

                if (Bundle.Board.Grid[Bundle.Row, Bundle.Column].isFlagged == false)
                {
                    // update board
                    int result = gameService.Update(Bundle);

                    // if the player won
                    if (result == 2)
                    {
                        // instantiate service
                        GameRecordService archiveService = new GameRecordService();

                        // pass control to service
                        archiveService.Archive(new GameRecordModel(-1, Bundle.User, Bundle.Difficulty, Bundle.Timer.ToString()));

                        Logger.Info("Game Won!");
                        return(View("gameWon", Bundle));
                    }

                    // if the player lost
                    else if (result == 1)
                    {
                        Logger.Info("Game Lost!");
                        return(View("gameLost", Bundle));
                    }

                    // otherwise
                    else
                    {
                        Bundle.Timer = DateTime.Now - Bundle.StartTime;
                        Logger.Info("Game Continues");
                        //return PartialView("_board", Bundle);
                        return(View("gameBoard", Bundle));
                    }
                }

                else
                {
                    Bundle.Timer = DateTime.Now - Bundle.StartTime;
                    Logger.Info("Can't reveal flagged cell");
                    return(View("gameBoard", Bundle));
                    //return PartialView("_board", Bundle);
                }
            }

            // handle exceptions
            catch (Exception e)
            {
                // log error
                Logger.Error("Exception in GameController.HandleCellClick(): " + e.Message);
                // return generic error page
                return(View("Exception"));
            }
        }