Ejemplo n.º 1
0
        private static async Task RateRBA(string Currency, DateTime date)
        {
            IBank       ibank  = BankFactory.GetBank(BankFactory.SupportedBanks.RBA);
            IBankResult result = await ibank.GetRateAsync(Currency, date);

            PrintReSult(Currency, result);
        }
Ejemplo n.º 2
0
        public override void OnSaved(object sender, EntityAfterEventArgs e)
        {
            base.OnSaved(sender, e);
            Entity entity = (Entity)sender;
            //UserConnection = entity.UserConnection;

            var    amountFC      = entity.GetTypedColumnValue <decimal>("AmountFC");
            var    date          = entity.GetTypedColumnValue <DateTime>("TransactionDate");
            var    currencyId    = entity.GetTypedColumnValue <Guid>("CurrencyId");
            string shortCurrency = entity.FindValueById <string>("Currency", currencyId, "ShortName");

            IBank       ibank  = BankFactory.GetBank(BankFactory.SupportedBanks.BOC);
            IBankResult result = null;

            Task.Run(async() =>
            {
                result = await ibank.GetRateAsync(shortCurrency, date);
            }).Wait();


            entity.SetColumnValue("FxRate", result.ExchangeRate);
            entity.SetColumnValue("AmountHC", amountFC * result.ExchangeRate);
            entity.Save();
            _log.Info($"rate:{result.ExchangeRate} on {result.RateDate:dd-MMM-yyyy}");
        }
Ejemplo n.º 3
0
        private static async Task RateBOMX(string Currency, DateTime date)
        {
            IBank       ibank  = BankFactory.GetBank(BankFactory.SupportedBanks.BOMX, Resources.bmxSecret);
            IBankResult result = await ibank.GetRateAsync(Currency, date);

            PrintReSult(Currency, result);
        }
Ejemplo n.º 4
0
        public async Task BOC_GetRateAsyncShoudReturn(decimal expectedExchangeRate,
                                                      DateTime requestedRateDate, DateTime expectedRateDate, string currency)
        {
            #region Arrange
            IBankResult expected = new BankResult()
            {
                BankName     = "Bank of Canada",
                HomeCurrency = "CAD",
                ExchangeRate = expectedExchangeRate,
                RateDate     = expectedRateDate
            };
            IBank ibank = BankFactory.GetBank(BankFactory.SupportedBanks.BOC);
            #endregion

            #region Act
            IBankResult actual = await ibank.GetRateAsync(currency, requestedRateDate);

            #endregion

            #region Assert
            //Assert.Equal(expected, actual);
            Assert.Equal(expected.RateDate, actual.RateDate);
            Assert.Equal(expected.ExchangeRate, actual.ExchangeRate);
            Assert.Equal(expected.BankName, actual.BankName);
            Assert.Equal(expected.HomeCurrency, actual.HomeCurrency);

            #endregion
        }
Ejemplo n.º 5
0
        public async Task RBA_GetRateAsyncShoudReturn()
        {
            DateTime date = new DateTime(2018, 1, 17);

            #region Arrange
            IBankResult expected = new BankResult()
            {
                BankName     = "Reserve Bank of Australia",
                HomeCurrency = "AUD",
                ExchangeRate = 1.2571M,
                RateDate     = date
            };
            #endregion

            #region Act
            IBank       ibank  = BankFactory.GetBank(BankFactory.SupportedBanks.RBA);
            IBankResult actual = await ibank.GetRateAsync("USD", date);

            #endregion

            #region Assert
            //Assert.Equal(expected, actual);
            Assert.Equal(expected.RateDate, actual.RateDate);
            Assert.Equal(expected.ExchangeRate, actual.ExchangeRate);
            Assert.Equal(expected.BankName, actual.BankName);
            Assert.Equal(expected.HomeCurrency, actual.HomeCurrency);
            #endregion
        }
Ejemplo n.º 6
0
        private static async Task RateBOE(string Currency, DateTime date)
        {
            IBank       ibank  = BankFactory.GetBank(BankFactory.SupportedBanks.BOE);
            IBankResult result = await ibank.GetRateAsync(Currency, date);

            result.ExchangeRate = Decimal.Round((1 / result.ExchangeRate), 4);
            PrintReSult(Currency, result);
        }
        public Interfaces.IBankResult GetRate(string currencyFrom, DateTime date, string bmxToken = "")
        {
            IBankResult r    = null;
            IBank       bank = null;

            switch (currencyFrom)
            {
            case "CAD":
                bank = BankFactory.GetBank(BankFactory.SupportedBanks.BOC);
                break;

            case "RUB":
                bank = BankFactory.GetBank(BankFactory.SupportedBanks.CBR);
                break;

            case "UAH":
                bank = BankFactory.GetBank(BankFactory.SupportedBanks.NBU);
                break;

            case "EUR":
                bank = BankFactory.GetBank(BankFactory.SupportedBanks.ECB);
                break;

            case "MXN":
                bank = BankFactory.GetBank(BankFactory.SupportedBanks.BOMX, bmxToken);
                break;

            case "AUD":
                bank = BankFactory.GetBank(BankFactory.SupportedBanks.RBA);
                break;

            case "GBP":
                bank = BankFactory.GetBank(BankFactory.SupportedBanks.BOE);
                break;

            default:
                break;
            }

            Task.Run(async() =>
            {
                r = await bank.GetRateAsync("USD", date);
            }).Wait();

            var result = new Result
            {
                BankName     = r.BankName,
                RateDate     = r.RateDate,
                HomeCurrency = r.HomeCurrency
            };

            result.ExchangeRate = (currencyFrom == "GBP")? decimal.Round(1 / r.ExchangeRate, 4): r.ExchangeRate;
            return(result);
        }
Ejemplo n.º 8
0
        DV_10132020_EN_INTERFACES.BankResult IForeignExchangeApi.GetEcbRate(string currency, DateTime date)
        {
            var         ECB       = BankFactory.GetBank(BankFactory.SupportedBanks.ECB);
            IBankResult EcbResult = ECB.GetRateAsync(currency, date).Result;

            DV_10132020_EN_INTERFACES.BankResult result = new DV_10132020_EN_INTERFACES.BankResult();

            result.BankName     = EcbResult.BankName;
            result.ExchangeRate = EcbResult.ExchangeRate;
            result.RateDate     = EcbResult.RateDate;
            result.HomeCurrency = EcbResult.HomeCurrency;
            return(result);
        }
Ejemplo n.º 9
0
        public DV_10132020_EN_INTERFACES.BankResult GetBOCRate(string currency, DateTime date)
        {
            var         BOC       = BankFactory.GetBank(BankFactory.SupportedBanks.BOC);
            IBankResult BocResult = BOC.GetRateAsync(currency, date).Result;

            DV_10132020_EN_INTERFACES.BankResult result = new DV_10132020_EN_INTERFACES.BankResult();

            result.BankName     = BocResult.BankName;
            result.ExchangeRate = BocResult.ExchangeRate;
            result.RateDate     = BocResult.RateDate;
            result.HomeCurrency = BocResult.HomeCurrency;
            return(result);
        }
Ejemplo n.º 10
0
        public BankResult Validate(PrevalidateExpenseReportLineDataContract request)
        {
            //Call: [APP]/0/rest/PrevalidateExpenseReportLine/Validate
            userConnection = UserConnection ?? SystemUserConnection;

            IBank      Bank          = BankFactory.GetBank(BankFactory.SupportedBanks.BOC);
            BankResult result        = new BankResult();
            string     shortCurrency = FindValueById <string>("Currency", request.CurrencyId, "ShortName");

            System.Threading.Tasks.Task.Run(async() =>
            {
                IBankResult response = await Bank.GetRateAsync(shortCurrency, request.TransactionDate);
                result = (BankResult)response;
            }).Wait();
            return(result);
        }
Ejemplo n.º 11
0
        public BankResult ExecuteGet(int bankId, string date, string currency)
        {
            //http://k_krylov_nb:8060/0/rest/ExchangeRate_WS/ExecuteGet?bankId=0&date=2019-11-20&currency="RUB"

            DateTime.TryParse(date, out DateTime dt);
            IBank bank = BankFactory.GetBank((BankFactory.SupportedBanks)bankId);

            IBankResult bankResult = Task.Run(() => bank.GetRateAsync(currency.ToUpper(), dt)).Result;
            BankResult  result     = new BankResult
            {
                ExchangeRate = bankResult.ExchangeRate,
                RateDate     = bankResult.RateDate,
                HomeCurrency = bankResult.HomeCurrency,
                BankName     = bankResult.BankName
            };

            return(result);
        }
        public override void OnSaved(object sender, EntityAfterEventArgs e)
        {
            base.OnSaved(sender, e);
            Entity entity = (Entity)sender;

            userConnection = entity.UserConnection;

            string[] ObservableColumns   = { "AmountHC", "AmountFC", "Currency" };
            bool     isChangeInteresting = false;

            foreach (EntityColumnValue mc in e.ModifiedColumnValues)
            {
                if (Array.IndexOf(ObservableColumns, mc.Column.Name) > -1)
                {
                    isChangeInteresting = true;
                }
            }

            if (!isChangeInteresting)
            {
                return;
            }


            Guid   currencyId   = entity.GetTypedColumnValue <Guid>("CurrencyId");
            string currencyName = GetCurrencyName(currencyId);

            IBank       bank       = BankFactory.GetBank(BankFactory.SupportedBanks.BOC);
            IBankResult bankResult = Task.Run(() => bank.GetRateAsync(currencyName, DateTime.Today)).Result;

            decimal rate = bankResult.ExchangeRate;

            decimal amountFC = entity.GetTypedColumnValue <decimal>("AmountFC");
            decimal amountHC = rate * amountFC;

            entity.SetColumnValue("AmountHC", amountHC);
            entity.Save();

            Guid expenseReportId = entity.GetTypedColumnValue <Guid>("ExpenseReportId");

            UpdateExpenseReport(entity.UserConnection, expenseReportId);

            MsgChannelUtilities.PostMessage(userConnection, GetType().Name, "UpdatedExpenseReportLine");
        }
Ejemplo n.º 13
0
        protected override bool InternalExecute(ProcessExecutingContext context)
        {
            IForeignExchange foreignExchange = Factories.ClassFactory.Get <IForeignExchange>();

            string currencyCode = GetShortCurrencyCode(Currency);

            IBankResult result = default;

            if (currencyCode == "MXN" && SysSettings.TryGetValue(UserConnection, "bmxToken", out object value))
            {
                string token = value.ToString();
                result = foreignExchange.GetRate(currencyCode, Date, value.ToString());
            }
            else
            {
                result = foreignExchange.GetRate(currencyCode, Date);
            }

            ExchangeRate    = result.ExchangeRate;
            ObservationDate = result.RateDate;
            BankName        = result.BankName;
            return(true);
        }
Ejemplo n.º 14
0
        public BankResult ExchangeRate(Guid bank, DateTime transactionDate, Guid currency)
        {
            //
            //Available at [Application Address]/0/rest/ExchangeRateWS/ExchangeRate

            UserConnection userConnection = UserConnection ?? SystemUserConnection;

            BankFactory.SupportedBanks selectedBank = BankFactory.SupportedBanks.BOC;
            switch (bank.ToString())
            {
            case "c64cb3d6-3c87-4eb6-88ec-13d03ef5391e":
                selectedBank = BankFactory.SupportedBanks.BOC;
                break;

            case "2cb64ddc-1e80-4a92-a647-843746968206":
                selectedBank = BankFactory.SupportedBanks.CBR;
                break;

            case "82966eac-b7fa-4a5f-b205-f03724c09226":
                selectedBank = BankFactory.SupportedBanks.NBU;
                break;

            case "3444ff4e-7f8f-4695-a0bb-21a3b2c6536a":
                selectedBank = BankFactory.SupportedBanks.ECB;
                break;

            default:
                selectedBank = BankFactory.SupportedBanks.BOC;
                break;
            }

            IBank       cbr = BankFactory.GetBank(selectedBank);
            string      cur = GetCurrencyNameById(userConnection, currency);
            IBankResult res = cbr.GetRateAsync(cur, transactionDate).Result;

            return((BankResult)res);
        }
Ejemplo n.º 15
0
        private static void PrintReSult(string Currency, IBankResult result)
        {
            string resString = $"1 {Currency} = {result.ExchangeRate}\t{result.HomeCurrency} on {result.RateDate:dd-MMM-yyyy} provided by the {result.BankName}";

            Console.WriteLine(resString);
        }