Ejemplo n.º 1
0
        public CurrencyViewModel GetCurrency(string code)
        {
            var spec = new CurrencyByCodeSpec(code);
            var curr = currRepository.FindOne(spec);

            return(CurrencyViewModel.MapFromData(curr));
        }
Ejemplo n.º 2
0
        public void AddCurrency(CurrencyViewModel currency)
        {
            var existCurrSpec = new CurrencyByCodeSpec(currency.Code);
            var oldItem       = currRepository.FindOne(existCurrSpec);

            if (oldItem != null)
            {
                throw new ValidationException($"Currency {currency.Code} already exist!");
            }

            var curr = Currency.CreateCurrency(currency.Code, currency.ShortCode, currency.Symbol, currency.Name);

            try
            {
                unitOfWork.BeginTransaction();
                currRepository.Add(curr);
                unitOfWork.Commit();
            }
            catch (Exception)
            {
                unitOfWork.Rollback();
                throw;
            }
        }
Ejemplo n.º 3
0
        public void UpdateCurrency(CurrencyViewModel model)
        {
            var oldItem = currRepository.FindById(model.Id);

            if (oldItem == null)
            {
                throw new ValidationException($"Currency {model.Id} not found.");
            }
            oldItem.Name      = model.Name;
            oldItem.ShortCode = model.ShortCode;
            oldItem.Symbol    = model.Symbol;
            oldItem.Code      = model.Code;
            try
            {
                unitOfWork.BeginTransaction();
                currRepository.Update(oldItem);
                unitOfWork.Commit();
            }
            catch (Exception)
            {
                unitOfWork.Rollback();
                throw;
            }
        }
Ejemplo n.º 4
0
        public async Task <IEnumerable <CurrencyViewModel> > GetCurrencies()
        {
            var currencies = await currRepository.GetAll();

            return(currencies.Select(p => CurrencyViewModel.MapFromData(p)));
        }