/// <summary> /// Insert moves info into Moves table of DB. /// </summary> /// <param name="movesInfo">Move related info like rolNumber, colNumber, etc</param> public void InsertMovesInfo(MovesInfo movesInfo) { string query = $@"insert into Moves (GameId, UserId, RowNumber, ColNumber, CreationTime) values (@v_gameId, @v_userId, @v_rowNumber, @v_colNumber, @v_creationTime);"; var dbParams = GetDbParamsFromMovesInfo(movesInfo); using (var connection = new SQLiteConnection(_connString)) { connection.Execute(query, dbParams, commandType: CommandType.Text); } }
private object GetDbParamsFromMovesInfo(MovesInfo movesInfo) { return(new { v_gameId = movesInfo.GameId, v_userId = movesInfo.UserId, v_rowNumber = movesInfo.RowNumber, v_colNumber = movesInfo.ColNumber, v_creationTime = movesInfo.CreationTime }); }
public IHttpActionResult InsertMove(int gameId, [FromBody] MovesInfo movesInfo) { // Validation starts here movesInfo.GameId = gameId; var validator = new MovesInfoValidator(); var results = validator.Validate(movesInfo); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Validation ends here _movesBL.InsertMovesInfo(gameId, movesInfo); return(Ok("Success")); }
/// <summary> /// It simpley insert's move of user in db /// </summary> /// <param name="gameId">Unique id of game</param> /// <param name="movesInfo">Moves info like colNumber, rowNumber and etc.</param> public void InsertMovesInfo(int gameId, MovesInfo movesInfo) { movesInfo.CreationTime = DateTime.Now.ToString(); movesInfo.GameId = gameId; _movesRepository.InsertMovesInfo(movesInfo); }