public MoneyGiftViewModel(WalletMoney money)
        {
            var currency = Persistent.Currencies.GetById(money.CurrencyID);

            MoneyImage = Images.GetCountryCurrency(currency).VM;
            Amount     = (double)money.Amount;
            Symbol     = currency.Symbol;
            CurrencyID = currency.ID;
        }
        public void AddMoney(int walletID, Money money)
        {
            var wallet        = walletRepository.GetById(walletID);
            var existingMoney = wallet.WalletMoneys.FirstOrDefault(wm => wm.CurrencyID == money.Currency.ID);

            if (existingMoney == null)
            {
                WalletMoney walletMoney = createWalletMoney(walletID, money);
                wallet.WalletMoneys.Add(walletMoney);
            }
            else
            {
                existingMoney.Amount += money.Amount;
            }
            ConditionalSaveChanges(walletRepository);
        }
        public WalletMoney GetWalletMoney(int walletID, int currencyID)
        {
            var wallet = walletRepository.FirstOrDefault(w => w.ID == walletID);

            WalletMoney money = wallet.WalletMoneys.FirstOrDefault(wm => wm.CurrencyID == currencyID);

            if (money == null)
            {
                var currency = currencyRepository.First(c => c.ID == currencyID);
                return(new WalletMoney()
                {
                    Amount = 0,
                    Currency = currency,
                    CurrencyID = currency.ID,
                    Wallet = wallet,
                    WalletID = walletID
                });
            }
            return(money);
        }
        public bool HaveMoney(int walletID, params Money[] moneys)
        {
            var wallet = walletRepository.FirstOrDefault(w => w.ID == walletID);

            foreach (var money in moneys)
            {
                if (money.Amount <= 0)
                {
                    continue;
                }

                WalletMoney walletMoney = wallet.WalletMoneys.FirstOrDefault(wm => wm.CurrencyID == money.Currency.ID);

                if (walletMoney == null)
                {
                    return(false);
                }
                else if (walletMoney.Amount < money.Amount)
                {
                    return(false);
                }
            }
            return(true);
        }
 public MoneyTradeViewModel(WalletMoney money) : base(money)
 {
 }
Exemple #6
0
 public MoneyViewModel(WalletMoney vm)
     : this(Persistent.Currencies.GetById(vm.CurrencyID)
            , vm.Amount)
 {
 }
 public WalletMoneyViewModel(WalletMoney money)
 {
     Amount        = (double)money.Amount;
     CurrencyImage = Images.GetCountryCurrency(Persistent.Currencies.GetById(money.CurrencyID)).VM;
 }