public ExchangeRate FindLatestExchangeRate(DateTime pDate, Currency pCurrency)
        {
            ExchangeRate exchangeRate = null;
            Currency     pivot        = new CurrencyServices(_user).GetPivot();

            if (!pivot.Equals(pCurrency))
            {
                if (new CurrencyServices(_user).FindAllCurrencies().Count > 1)
                {
                    double rate = _exchangeRateServices.GetMostRecentlyRate(pDate, pCurrency);

                    exchangeRate = new ExchangeRate
                    {
                        Currency = pCurrency,
                        Date     = pDate,
                        Rate     = rate
                    };
                }
            }
            else
            {
                exchangeRate = new ExchangeRate
                {
                    Currency = pCurrency,
                    Date     = pDate,
                    Rate     = 1
                };
            }
            return(exchangeRate);
        }
示例#2
0
        public async Task ReturnAllCurrencies()
        {
            //Arrange
            var currency1 = new Currency {
                CurrencyName = "USD"
            };
            var currency2 = new Currency {
                CurrencyName = "BGN"
            };
            var currency3 = new Currency {
                CurrencyName = "EUR"
            };
            var currencyRepoMock = new Mock <IRepository <Currency> >();

            currencyRepoMock
            .Setup(crm => crm.All())
            .Returns(new List <Currency> {
                currency1, currency2, currency3
            }
                     .AsQueryable()
                     .BuildMock()
                     .Object);

            var sut = new CurrencyServices(currencyRepoMock.Object);
            //Act
            var currencyNames = await sut.GetCurrenciesAsync();

            //Assert
            Assert.IsTrue(currencyNames.Contains(currency1.CurrencyName));
            Assert.IsTrue(currencyNames.Contains(currency2.CurrencyName));
            Assert.IsTrue(currencyNames.Contains(currency3.CurrencyName));
        }
        public ExchangeRate FindExchangeRate(DateTime pDate, Currency pCurrency)
        {
            ExchangeRate exchangeRate = null;
            Currency     pivot        = new CurrencyServices(_user).GetPivot();

            if (!pivot.Equals(pCurrency))
            {
                if (new CurrencyServices(_user).FindAllCurrencies().Count > 1)
                {
                    exchangeRate = _exchangeRateServices.SelectExchangeRate(pDate.Date, pCurrency);
                    if (exchangeRate == null)
                    {
                        throw new OpenCbsExchangeRateException(OpenCbsExchangeRateExceptionEnum.ExchangeRateIsNull);
                    }
                }
            }
            else
            {
                exchangeRate = new ExchangeRate
                {
                    Currency = pCurrency,
                    Date     = pDate,
                    Rate     = 1
                };
            }
            return(exchangeRate);
        }
示例#4
0
        public ActionResult DeleteCurrency(long id)
        {
            var gVal = new GenericValidator();

            try
            {
                if (id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = message_Feedback.Invalid_Selection;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var k = new CurrencyServices().DeleteCurrency(id);
                if (k)
                {
                    gVal.Code  = 5;
                    gVal.Error = message_Feedback.Delete_Success;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Delete_Failure;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                gVal.Code  = 5;
                gVal.Error = message_Feedback.Process_Failed;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
        public List <string> CreateCurrencies()
        {
            var createcurrencies = new CurrencyServices(_dataContext);
            var result           = createcurrencies.LoadCurrency();

            return(result);
        }
示例#6
0
        public ActionResult EditCurrency(CurrencyObject currency)
        {
            var gVal = new GenericValidator();

            try
            {
                if (ModelState.IsValid)
                {
                    var valStatus = ValidateCurrency(currency);
                    if (valStatus.Code < 1)
                    {
                        gVal.Code  = -1;
                        gVal.Error = valStatus.Error;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    if (Session["_currency"] == null)
                    {
                        gVal.Code  = -5;
                        gVal.Error = message_Feedback.Session_Time_Out;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    var oldCurrency = Session["_currency"] as CurrencyObject;
                    if (oldCurrency == null || oldCurrency.CurrencyId < 1)
                    {
                        gVal.Code  = -5;
                        gVal.Error = message_Feedback.Session_Time_Out;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }
                    oldCurrency.Name      = currency.Name.Trim();
                    oldCurrency.Symbol    = currency.Symbol.Trim();
                    oldCurrency.CountryId = currency.CountryId;
                    var k = new CurrencyServices().UpdateCurrency(oldCurrency);
                    if (k < 1)
                    {
                        gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Update_Failure;
                        gVal.Code  = -1;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }
                    gVal.Code  = 5;
                    gVal.Error = message_Feedback.Update_Success;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = -5;
                gVal.Error = message_Feedback.Model_State_Error;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                gVal.Code  = 0;
                gVal.Error = message_Feedback.Process_Failed;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
        public List <Currencies> GetAllCurrencies()
        {
            var load = new CurrencyServices(_dataContext);


            var ipremote      = HttpContext.Connection.RemoteIpAddress;
            var resultMessage = $"Consulto Currencies { ipremote}";

            _logger.Information(resultMessage);
            return(load.GetAllCurrency());
        }
示例#8
0
        public ActionResult GetCurrencyObjects(JQueryDataTableParamModel param)
        {
            try
            {
                IEnumerable <CurrencyObject> filteredCurrencyObjects;
                var countG = new CurrencyServices().GetObjectCount();

                var pagedCurrencyObjects = GetCities(param.iDisplayLength, param.iDisplayStart);

                if (!string.IsNullOrEmpty(param.sSearch))
                {
                    filteredCurrencyObjects = new CurrencyServices().Search(param.sSearch);
                }
                else
                {
                    filteredCurrencyObjects = pagedCurrencyObjects;
                }

                if (!filteredCurrencyObjects.Any())
                {
                    return(Json(new List <CurrencyObject>(), JsonRequestBehavior.AllowGet));
                }

                var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
                Func <CurrencyObject, string> orderingFunction = (c => sortColumnIndex == 1 ? c.Name : sortColumnIndex == 2 ? c.Symbol : c.CountryName
                                                                  );

                var sortDirection = Request["sSortDir_0"]; // asc or desc
                filteredCurrencyObjects = sortDirection == "asc" ? filteredCurrencyObjects.OrderBy(orderingFunction) : filteredCurrencyObjects.OrderByDescending(orderingFunction);

                var displayedUserProfilenels = filteredCurrencyObjects;

                var result = from c in displayedUserProfilenels
                             select new[] { Convert.ToString(c.CurrencyId), c.Name, c.Symbol, c.CountryName };
                return(Json(new
                {
                    param.sEcho,
                    iTotalRecords = countG,
                    iTotalDisplayRecords = filteredCurrencyObjects.Count(),
                    aaData = result
                },
                            JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new List <CurrencyObject>(), JsonRequestBehavior.AllowGet));
            }
        }
示例#9
0
        private void guna2Button2_Click(object sender, EventArgs e)
        {
            Form1.Instance.pnlContainer.Controls.RemoveByKey("CurrencyTable");
            // if (!Form1.Instance.pnlContainer.Controls.ContainsKey("CurrencyTable"))
            //    {
            CurrencyServices currencyServices = new CurrencyServices();
            List <Currency>  _currencies      = currencyServices.GetAllCurrencies(DateTimePicker.Value);
            CurrencyTable    ct = new CurrencyTable(_currencies);

            ct.Dock = DockStyle.Fill;
            Form1.Instance.pnlContainer.Controls.Add(ct);

            //  }

            Form1.Instance.pnlContainer.Controls["CurrencyTable"].BringToFront();
        }
示例#10
0
        public ActionResult AddCurrency(CurrencyObject currency)
        {
            var gVal = new GenericValidator();

            try
            {
                if (ModelState.IsValid)
                {
                    var valStatus = ValidateCurrency(currency);
                    if (valStatus.Code < 1)
                    {
                        gVal.Code  = -1;
                        gVal.Error = valStatus.Error;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    var k = new CurrencyServices().AddCurrency(currency);
                    if (k < 1)
                    {
                        gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Insertion_Failure;
                        gVal.Code  = -1;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }
                    gVal.Code  = k;
                    gVal.Error = message_Feedback.Model_State_Error;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = -5;
                gVal.Error = message_Feedback.Model_State_Error;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Process_Failed;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
示例#11
0
        public ActionResult GetCurrency(long id)
        {
            try
            {
                if (id < 1)
                {
                    return(Json(new CurrencyObject(), JsonRequestBehavior.AllowGet));
                }

                var currency = new CurrencyServices().GetCurrency(id);
                if (id < 1)
                {
                    return(Json(new CurrencyObject(), JsonRequestBehavior.AllowGet));
                }
                Session["_currency"] = currency;
                return(Json(currency, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new CurrencyObject(), JsonRequestBehavior.AllowGet));
            }
        }
        public string CreateCurrency([FromBody] CurrencyRequestDTO request)
        {
            var createcurrency = new CurrencyServices(_dataContext);

            return(createcurrency.CreateCurrency(request));
        }