Exemplo n.º 1
0
        private IEnumerable <Dto.TeamCryptoCurrencyBalance> GetTeamCryptoCurrencyBalances(Currency currency, int teamId)
        {
            var teamCryptoCurrencyBalanceBusiness = new TeamCryptoCurrencyBalanceBusiness();

            return(teamCryptoCurrencyBalanceBusiness.GetTeamCryptoCurrencyBalances(teamId, currency));
        }
        /// <summary>
        /// scope= set:balance
        /// cmd= 'set balance @p0 @p1 @p2'.
        /// @p0 parameter for desired currency
        /// @p1 parameter for balance name
        /// @p2 parameter for balance amount
        /// </summary>
        /// <returns></returns>
        public override async Task SetBalance()
        {
            int parameterCount = 3;

            string limitAmountText = string.Empty;

            if (Parameters.Length > 2)
            {
                limitAmountText = Parameters[2];
            }

            var parameterSet = new List <CommandParameter>
            {
                new CommandParameter
                {
                    Depth          = 3,
                    ParameterValue = limitAmountText,
                    IsNumber       = true
                }
            };

            var validateResp = ValidateParameters(parameterSet, parameterCount);

            if (validateResp.ResponseCode != ResponseCode.Success)
            {
                await PostMessage(GetSlackExecutionErrorMessage(validateResp.ResponseData));

                return;
            }

            var currency = Statics.GetCurrency(Parameters[0]);

            if (currency == Currency.Unknown)
            {
                var errorMesssage = GetSlackExecutionErrorMessage(2);

                //post depth=2 message => Given crypto currency either not found or not supported.
                errorMesssage.text = string.Format(errorMesssage.text, Parameters[0]);
                await PostMessage(errorMesssage);

                return;
            }

            decimal balanceAmount = Parameters[2].ToMoneyMarketDecimalFormat();

            //everytihng is fine. add or update balance.
            var teamCryptoCurrencyBalanceBusiness = new TeamCryptoCurrencyBalanceBusiness();

            var balance = new TeamCryptoCurrencyBalance
            {
                TeamId   = Team.Id,
                Currency = currency,
                Name     = Parameters[1].ToLower(),
                Balance  = balanceAmount
            };

            if (balanceAmount == 0)
            {
                teamCryptoCurrencyBalanceBusiness.Delete(balance);

                //balance has been deleted.
                await PostMessage(GetSlackExecutionSuccessMessage(1));

                return;
            }

            teamCryptoCurrencyBalanceBusiness.Add(balance);

            await PostMessage(GetSlackExecutionSuccessMessage());
        }