Ejemplo n.º 1
0
        protected override async Task <string> DataReceived(UserCommandType command)
        {
            try
            {
                command.fundsSpecified = true;
                var msg = await BuyTriggerTimer.StartOrUpdateTimer(command).ConfigureAwait(false);

                if (msg == null)
                {
                    return($"Trigger amount set successfully for stock {command.stockSymbol}");
                }
                return(LogErrorEvent(command, msg));
            }
            catch (Exception ex)
            {
                LogDebugEvent(command, ex.Message);
                return(LogErrorEvent(command, "Error processing command."));
            }
        }
Ejemplo n.º 2
0
        async Task <string> CheckMoney(MySqlCommand cmd, UserCommandType command)
        {
            cmd.CommandText = "get_user_money";

            cmd.Parameters.AddWithValue("@pUserId", command.username);
            cmd.Parameters["@pUserId"].Direction = ParameterDirection.Input;
            cmd.Parameters.Add("@pMoney", DbType.Int32);
            cmd.Parameters["@pMoney"].Direction = ParameterDirection.Output;

            await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);

            if (cmd.Parameters["@pMoney"].Value == DBNull.Value)
            {
                return(LogErrorEvent(command, "User does not exist"));
            }
            if (Convert.ToInt32(cmd.Parameters["@pMoney"].Value) < command.funds)
            {
                return(LogErrorEvent(command, "Insufficient user funds"));
            }

            command.fundsSpecified = false;
            return(await BuyTriggerTimer.StartOrUpdateTimer(command).ConfigureAwait(false));;
        }