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));
            }
        }
示例#2
0
        public ActionResult Index()
        {
            //Get CostData
            //CostSettingModel costSet = new CostSettingModel();
            //string path =  AppDomain.CurrentDomain.BaseDirectory + "Files/cost_setting.json";
            //string content = Library.FileLib.ReadFile(path);
            //costSet = JsonConvert.DeserializeObject<CostSettingModel>(content);

            //Get gameData
            //List<GameRecordModel> grecord = new List<GameRecordModel>();
            //string path = AppDomain.CurrentDomain.BaseDirectory + "Record/demo.json";
            //string content = Library.FileLib.ReadFile(path);
            //grecord = JsonConvert.DeserializeObject<List<GameRecordModel>>(content);

            ////WriteToJson txt
            //string newFilePath = AppDomain.CurrentDomain.BaseDirectory + "Record/201709060236_1111.json";
            //Library.FileLib.WriteOverFile(newFilePath, JsonConvert.SerializeObject(grecord));
            GameRecordModel _record = new GameRecordModel()
            {
                RoomId = "123",
                month  = 10,
                week   = 1,
            };

            return(View());
        }
示例#3
0
 private async Task StoreGameRecord(bool isGameWin)
 {
     GameRecordModel gameRecordModel = new GameRecordModel
     {
         IsWin             = isGameWin,
         Date              = DateTime.Now,
         Duration          = TimeSpan.FromSeconds(gameBar.TimerTicks),
         DurationInSeconds = gameBar.TimerTicks
     };
     await HttpClient.PostAsJsonAsync($"api/statistic/{GameSesstings.CurrentLevel}", gameRecordModel);
 }
        public async Task AddGameRecord(string level, GameRecordModel gameRecordModel)
        {
            GameRecord gameRecord = _mapper.Map <GameRecord>(gameRecordModel);

            gameRecord.Duration = TimeSpan.FromSeconds(gameRecordModel.DurationInSeconds);
            var userId  = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            int levelId = (await _levelsRepository.GetAllAsync()).Where(r => r.Complexity.ToLower() == level.ToLower()).Single().Id;

            gameRecord.ComplexityLevelId = levelId;
            gameRecord.PlayerId          = userId;
            await _statisticService.AddGameRecordAsync(gameRecord);
        }
示例#5
0
        public bool Archive(GameRecordModel game)
        {
            string connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=MinesweeperDatabase;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";

            bool success = false;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                GameRecordDAO dao = new GameRecordDAO(connection);

                connection.Open();
                success = dao.Create(game);
                connection.Close();
            }
            return(success);
        }
示例#6
0
        public bool Create(GameRecordModel game)
        {
            String query = "INSERT INTO dbo.GAME_RECORD (ACCOUNT, TIME, DIFFICULTY) VALUES (@user, @time, @difficulty)";

            using (SqlCommand command = new SqlCommand(query, Connection))
            {
                command.Parameters.Add("@user", SqlDbType.NVarChar).Value  = game.User;
                command.Parameters.Add("@time", SqlDbType.NVarChar).Value  = game.Time;
                command.Parameters.Add("@difficulty", SqlDbType.Int).Value = game.Difficulty;

                int rowsAffected = command.ExecuteNonQuery();

                if (rowsAffected > 0)
                {
                    return(true);
                }

                else
                {
                    return(false);
                }
            }
        }
 public void AddRecord(GameRecordModel record)
 {
     _records.Add(record);
 }