Exemplo n.º 1
0
        public async Task <DataTable> CheckRegistedUser(GameResultRQ gameResultRQ)
        {
            try
            {
                DataSet             dataSet   = new DataSet();
                DataTable           table     = new DataTable();
                List <SqlParameter> sqlParams = new List <SqlParameter>();

                SqlParameter nameParam = new SqlParameter {
                    ParameterName = "@name", SqlDbType = SqlDbType.NVarChar, Value = gameResultRQ.UserName
                };

                sqlParams.Add(nameParam);

                SqlCommand cmd = await ExecuteProcdureAsync(connection, "CheckUser", sqlParams);

                sqlDataAdapter.SelectCommand = cmd;
                sqlDataAdapter.Fill(dataSet);
                table = dataSet.Tables[0];
                return(table);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
        /// <summary>
        /// Function to Insert the GameResult for Registed User
        /// </summary>
        /// <returns></returns>
        public async System.Threading.Tasks.Task <IHttpActionResult> AddScoreAsync(string name, int score)
        {
            GameResultRQ request = new GameResultRQ()
            {
                UserName = name,
                Score    = score
            };

            try
            {
                GameResultRS response = new GameResultRS();

                if (!string.IsNullOrEmpty(name))
                {
                    response = await gameResultRepository.Add(request);
                }
                else
                {
                    response.TransactionStatus = TransactionStatusHelper.CreateTransaction(HttpStatusCode.BadRequest.ToString(), invalidParamters, EndTransactionType.Error, ErrorType.ExternalError);
                }

                return(Ok(response));
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception source: {0}", e.Source);
                return(null);
            }
        }
        public async Task <GameResultRS> Add(GameResultRQ gameResultRQ)
        {
            GameResultRS response = new GameResultRS();
            //check if the User is Registed
            DataTable table = await DBManager.Instance.CheckRegistedUser(gameResultRQ);

            //Rows of table count > 0 that means the User is registed
            if (table != null && table.Rows.Count > 0)
            {
                response.IsAdded = await DBManager.Instance.AddGameResultAsync(table, gameResultRQ);

                response.TransactionStatus.Message = string.Format("{0} has score {1} is reported", gameResultRQ.UserName, gameResultRQ.Score);
                return(response);
            }
            else
            {
                //User in unregisted and the score doesn't save so return false
                response.TransactionStatus.Message = string.Format("{0} is not registed User", gameResultRQ.UserName);
                response.IsAdded = false;
            }
            return(response);
        }
Exemplo n.º 4
0
        public async Task <bool> AddGameResultAsync(DataTable table, GameResultRQ gameResultRQ)
        {
            try
            {
                List <SqlParameter> sqlParams = new List <SqlParameter>();
                int          id      = Convert.ToInt32(table.Rows[0]["ID"].ToString().Trim());
                SqlParameter idParam = new SqlParameter {
                    ParameterName = "@id", SqlDbType = SqlDbType.Int, Value = id
                };
                SqlParameter scoreParam = new SqlParameter {
                    ParameterName = "@score", SqlDbType = SqlDbType.Int, Value = gameResultRQ.Score
                };

                sqlParams.Add(idParam);
                sqlParams.Add(scoreParam);
                sqlDataAdapter.SelectCommand = await ExecuteProcdureAsync(connection, "StoreGameResult", sqlParams);

                return(sqlDataAdapter.SelectCommand != null);
            }
            catch (Exception e)
            {
                return(false);
            }
        }