Example #1
0
        public void AddExchangeRate()
        {
            /* List<Currency> currencies = context.Currencies.Where(c => c.Name == "USD").ToList();
             * for (int i = 0; i < currencies.Count; i++)
             * {
             *   context.Entry(currencies[i]).State = EntityState.Deleted;
             * }
             * context.SaveChanges();*/
            Currency currency = new Currency
            {
                Code             = "222",
                Name             = "USD",
                IsNativeCurrency = false
            };

            context.Currencies.Add(currency);
            context.SaveChanges();
            ExchangeRate exchangeRate = new ExchangeRate
            {
                ExchangeRateTypeId = context.ExchangeRateTypes.FirstOrDefault(ert => ert.IsEqual(ExchangeRateTypesEnum.Market)).Id,
                CurrencyId         = currency.Id,
                RateForSale        = 75,
                RateForPurchaise   = 76,
                RateDate           = DateTime.Now
            };

            exchangeRateService.AddExchangeRate(exchangeRate);
            bool rateIsExist = exchangeRateService.IsExist(exchangeRate.Id);

            Assert.True(rateIsExist);

            context.Entry(exchangeRate).State = EntityState.Deleted;
            context.Entry(currency).State     = EntityState.Deleted;
            context.SaveChanges();
        }
        public void AddExchangeRate()
        {
            ExchangeRate exchangeRate = new ExchangeRate()
            {
                CurrencyId       = 2,
                RateForSale      = 75,
                RateForPurchaise = 76,
                RateDate         = DateTime.Now
            };

            exchangeRateService.AddExchangeRate(exchangeRate);
            bool rateIsExist = exchangeRateService.IsExist(exchangeRate.Id);

            Assert.True(rateIsExist);
        }
Example #3
0
        public ActionResult CreateEdit(UExchangeRate exRate, string Action = "")
        {
            if (ModelState.IsValid)
            {
                if (!exRate.Id.Equals(Guid.Empty))
                {
                    exRate._ExchangeRate.CountryProgrammeId = countryProg.Id;
                    if (exchangeRateService.EditExchangeRate(exRate._ExchangeRate))
                    {
                        ModelState.Clear();
                        exRate = new UExchangeRate();
                    }
                }
                else
                {
                    exRate._ExchangeRate.CountryProgrammeId = countryProg.Id;
                    if (exchangeRateService.AddExchangeRate(exRate._ExchangeRate))
                    {
                        ModelState.Clear();
                        exRate = new UExchangeRate();
                    }
                }
            }

            exRate.CurrencySelect = new SelectList(exchangeRateService.CurrencyObj.GetCurrencies(countryProg.Id), "Id", "Name");
            return(ListView());
        }
        public ActionResult Create(ExchangeRateViewModel model)
        {
            validationService.ValidateRateCreatingAndEditing(model, ModelState);


            decimal rateForSale      = 0;
            decimal rateForPurchaise = 0;

            if (!RateTryParse(model.RateForSale, out rateForSale) ||
                !RateTryParse(model.RateForPurchaise, out rateForPurchaise))
            {
                ModelState.AddModelError("RateForSale", localizer["RateFormatValidation"]);
                ModelState.AddModelError("RateForPurchaise", localizer["RateFormatValidation"]);
            }
            else if (rateForSale <= 0 || rateForPurchaise <= 0)
            {
                ModelState.AddModelError("RateForSale", localizer["RateNotNull"]);
                ModelState.AddModelError("RateForPurchaise", localizer["RateNotNull"]);
            }

            if (ModelState.IsValid)
            {
                ExchangeRate exchangeRate = new ExchangeRate()
                {
                    RateForPurchaise = rateForPurchaise,
                    RateForSale      = rateForSale,
                    RateDate         = DateTime.Now,
                    CurrencyId       = model.CurrencyId,
                    ExchangeRateType = context.ExchangeRateTypes.FirstOrDefault(e => e.IsEqual(ExchangeRateTypesEnum.Market))
                };

                exchangeRateService.AddExchangeRate(exchangeRate);
                context.SaveChanges();

                return(RedirectToAction("Index", "ExchangeRate"));
            }

            model.CurrencyList = currencyService.GetCurrencies().ToList();

            return(View(model));
        }