Exemplo n.º 1
0
 public CurrencyRateWrapper(CurrencyRate currencyRate)
     : base(currencyRate.ID)
 {
     FromCurrency = currencyRate.FromCurrency;
     ToCurrency = currencyRate.ToCurrency;
     Rate = currencyRate.Rate;
 }
 private CurrencyRateWrapper ToCurrencyRateWrapper(CurrencyRate currencyRate)
 {
     return new CurrencyRateWrapper(currencyRate);
 }
        public CurrencyRateWrapper CreateCurrencyRate(string fromCurrency, string toCurrency, decimal rate)
        {
            if (string.IsNullOrEmpty(fromCurrency) || string.IsNullOrEmpty(toCurrency) || rate < 0)
                throw new ArgumentException();
            
            var currencyRate = new CurrencyRate
                {
                    FromCurrency = fromCurrency,
                    ToCurrency = toCurrency,
                    Rate = rate
                };

            currencyRate.ID  = DaoFactory.GetCurrencyRateDao().SaveOrUpdate(currencyRate);

            return ToCurrencyRateWrapper(currencyRate);
        }
        public CurrencyRateWrapper UpdateCurrencyRate(int id, string fromCurrency, string toCurrency, decimal rate)
        {
            if (id <= 0 || string.IsNullOrEmpty(fromCurrency) || string.IsNullOrEmpty(toCurrency) || rate < 0)
                throw new ArgumentException();

            var currencyRate = new CurrencyRate
                {
                    ID = id,
                    FromCurrency = fromCurrency,
                    ToCurrency = toCurrency,
                    Rate = rate
                };

            currencyRate.ID = DaoFactory.GetCurrencyRateDao().SaveOrUpdate(currencyRate);
            MessageService.Send(Request, MessageAction.CurrencyRateUpdated, fromCurrency, toCurrency);

            return ToCurrencyRateWrapper(currencyRate);
        }