/// <summary> /// Get account using id /// </summary> /// <param name="accId">Account id</param> /// <returns>Founded account</returns> public Account.Account GetAccountById(string accId) { using (AccountsStorageContext context = new AccountsStorageContext()) { PersonInfo pi = context.Persons.SingleOrDefault(person => person.Id == accId); if (pi != null) { Account.Account foundedAccount = new Account.Account(pi.Id, pi.Name, pi.SurName, pi.Mail, pi.Bonus); List <PersonToCashLink> links = context.Links.Where(link => link.PersonId == pi.Id).ToList(); foreach (PersonToCashLink link in links) { CashInfo ci = context.Cashes.SingleOrDefault(cashInfo => cashInfo.Id == link.CashId); switch ((CashType)ci.CashType) { case CashType.BaseCash: BaseCash baseCash = new BaseCash(new BonusCalculator(0.05, 0.03), ci.Id); baseCash.Amount = ci.Amount; foundedAccount.AddCash((Currency)ci.Currency, baseCash); break; case CashType.GoldCash: GoldCash goldCash = new GoldCash(new BonusCalculator(0.05, 0.03), ci.Id); goldCash.Amount = ci.Amount; foundedAccount.AddCash((Currency)ci.Currency, goldCash); break; case CashType.PlatinumCash: PlatinumCash platinumCash = new PlatinumCash(new BonusCalculator(0.05, 0.03), ci.Id); platinumCash.Amount = ci.Amount; foundedAccount.AddCash((Currency)ci.Currency, platinumCash); break; } } return(foundedAccount); } else { return(null); } } }
//public CashContext(BaseCash baseCash) //{ // this.m_BaseCash = baseCash; //} //public double Calculate(double amount) //{ // return m_BaseCash.TakeCash(amount); //} public CashContext(string type) { switch (type) { case "正常": m_BaseCash = new NormalCash(); break; case "打8折": m_BaseCash = new DiscountCash("0.8"); break; case "满300, 返100": m_BaseCash = new ReturnCash("300", "100"); break; default: break; } }