public StateCapitalRepository() { _assembly = Assembly.GetExecutingAssembly(); _textStreamReader = new StreamReader(_assembly.GetManifestResourceStream("AlexaLambda.Infrastructure.DataAccess.StateCapitals.Data.USStateCapitals.json")); _capitals = new Capitals(); _capitals.StateCapitals = JsonConvert.DeserializeObject <List <Capital> >(_textStreamReader.ReadToEnd()); }
/// <summary> /// 充值(充值指定类型的资金费用,如果没有该类型资金则创建该类型资金并充值) /// </summary> /// <param name="amount">金额</param> /// <param name="payType">支付类型</param> /// <param name="capitalType">资金类型</param> /// <param name="desc"></param> public void Recharge(decimal amount, string payType, string capitalType) { var capital = Capitals.SingleOrDefault(s => s.CapitalType == capitalType); if (capital == null) { capital = new Capital(Id, capitalType); Capitals.Add(capital); } capital.ChangeBalance(amount, BillingType.Recharge, payType); }
/// <summary> /// 获取余额 /// </summary> /// <param name="capitalType"></param> /// <returns></returns> public decimal GetBalance(string capitalType = null) { decimal balance = 0; var generalCapital = GetGeneralCapital(); var capital = Capitals.SingleOrDefault(s => s.CapitalType == capitalType); balance += generalCapital == null ? 0 : generalCapital.Balance; balance += capital == null ? 0 : capital.Balance; return(balance); }
private Capital GetCapital(string capitalType) { var capital = Capitals.SingleOrDefault(s => s.CapitalType == capitalType); if (capital == null) { capital = GetGeneralCapital(); } if (capital == null) { throw new CustomHttpException("没有资金,扣费失败"); } return(capital); }
/// <summary> /// 获取通用资金 /// </summary> /// <returns></returns> private Capital GetGeneralCapital() { return(Capitals.SingleOrDefault(s => s.CapitalType == null)); }
string ApplyCaps(StringBuilder stringBuilder, Capitals capitals) { capitals.Apply(stringBuilder); return(stringBuilder.ToString()); }