/// <summary> /// returns teamInvesment if exists by teamId, currency and name search filter /// if balance bigger than 0, it is a revenue /// </summary> /// <returns></returns> private DataAccess.Models.TeamInvestment GetTeamRevenueByNameAndCurrency(Dto.TeamInvestment teamInvesment) { return(_repository.AsQueryable() .FirstOrDefault(p => p.Currency == teamInvesment.Currency && p.Name == teamInvesment.Name && p.TeamId == teamInvesment.TeamId && p.Balance > 0)); }
/// <summary> /// scope= set:balance /// cmd= 'set rev @p0 @p1 @p2'. /// @p0 parameter for desired currency /// @p1 parameter for revenue name /// @p2 parameter for revenue amount /// </summary> /// <returns></returns> public override async Task SetRevenue() { int parameterCount = 3; string balanceAmountText = string.Empty; if (Parameters.Length > 2) { balanceAmountText = Parameters[2]; } var parameterSet = new List <CommandParameter> { new CommandParameter { Depth = 3, ParameterValue = balanceAmountText, 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 investment. var teamInvestmentBusiness = new TeamInvestmentBusiness(); var revenue = new Dto.TeamInvestment { TeamId = Team.Id, Currency = currency, Name = Parameters[1].ToLower(), Balance = balanceAmount, IsRevenue = true }; if (balanceAmount == 0) { teamInvestmentBusiness.Delete(revenue); //revenue has been deleted. await PostMessage(GetSlackExecutionSuccessMessage(1)); return; } teamInvestmentBusiness.Add(revenue); await PostMessage(GetSlackExecutionSuccessMessage()); }