Пример #1
0
        public async Task <IHttpActionResult> GetAsync(int id)
        {
            var exchangeRate = await _exchangeRateRepository.GetAsync(id);

            if (exchangeRate == null)
            {
                return(NotFound());
            }
            return(Ok(exchangeRate.Map <CurrencyDto>()));
        }
Пример #2
0
        public async Task <Payment> CreateAsync(Guid invoiceId, decimal amountPaid, string paidCurrencyId, Guid exchangeRateId, DateTime payementDate)
        {
            Invoice invoice = await InvoiceRepository.GetAsync(invoiceId);

            if (invoice == null)
            {
                throw new InvoiceNotExisting(invoiceId);
            }
            string pivotCurrency = await SettingProvider.GetOrNullAsync(FacCigoSettings.PivotCurrency);

            if (pivotCurrency != paidCurrencyId)
            {
                var exchange = await ExchangeRateRepository.GetAsync(exchangeRateId);

                if (exchange == null)
                {
                    throw new ExamNotExisting(exchangeRateId);
                }
                decimal converted = Math.Round(invoice.TotalAmount * exchange.Rate, 2);
                if (converted != Math.Round(amountPaid, 2))
                {
                    throw new AmountNotMatchingException();
                }
            }
            Payment result = await PayementRepository.InsertAsync(
                new Payment
                (
                    GuidGenerator.Create(),
                    invoiceId,
                    amountPaid,
                    paidCurrencyId,
                    exchangeRateId,
                    payementDate

                ));

            invoice.ChangeStatus(InvoiceStatus.PAID);
            await InvoiceRepository.UpdateAsync(invoice, autoSave : true);

            return(result);
        }