public ActionResult EditCurrency(int id)
        {
            var currency = _currencyRepository.Get(id);

            var viewModel = new CurrencyViewModel(_countryRepository)
            {
                Id = currency.Id,
                Code = currency.Code,
                Name = currency.Name,
                ShortName = currency.ShortName,
                FlagFileName = currency.FlagFileName
            };

            var country = currency.CountryCurrencies.First().CountryRecord;
            if (country != null)
            {
                viewModel.CountryId = country.Id;
            }

            return View(viewModel);
        }
        public ActionResult EditCurrency(CurrencyViewModel viewModel)
        {
            var currency = _currencyRepository.Get(viewModel.Id);

            if (viewModel.ImageChanged &&
                !string.IsNullOrEmpty(currency.FlagFileName) &&
                (currency.FlagFileName != viewModel.FlagFileName))
            {
                _imageFileHelper.DeleteImageFromDisc(currency.Id);
            }

            currency.Code = viewModel.Code;
            currency.Name = viewModel.Name;
            currency.ShortName = viewModel.ShortName;
            currency.CurrencyCulture = _cultureUsed;

            if (viewModel.ImageChanged)
            {
                bool isNotPng;
                currency.FlagFileName = _imageFileHelper.SaveImageToDisc(viewModel.FlagImage, viewModel.Id,
                    out isNotPng);
                if (isNotPng)
                {
                    _orchardServices.Notifier.Error(T("Flag Image file must be *.png."));
                    return RedirectToAction("EditCurrency", new {id = currency.Id});
                }
            }
            else
            {
                currency.FlagFileName = viewModel.FlagFileName;
            }

            var countryCurrency = currency.CountryCurrencies.First();

            if (viewModel.CountryId.HasValue)
            {
                var country = _countryRepository.Get(viewModel.CountryId.Value);
                countryCurrency.CountryRecord = country;
            }
            else
            {
                countryCurrency.CountryRecord = null;
            }

            _currencyRepository.Update(currency);

            _orchardServices.Notifier.Information(T("Currency has been changed!"));
            return RedirectToAction("Index");
        }
        public ActionResult AddCurrency(CurrencyViewModel viewModel)
        {
            var currency = new CurrencyRecord
            {
                Code = viewModel.Code,
                Name = viewModel.Name,
                ShortName = viewModel.ShortName,
                CurrencyCulture = _cultureUsed
            };

            bool isNotPng;
            currency.FlagFileName = _imageFileHelper.SaveImageToDisc(viewModel.FlagImage, currency.Id, out isNotPng);

            if (isNotPng)
            {
                _orchardServices.Notifier.Error(T("Flag Image file must be *.png."));
                return RedirectToAction("Index");
            }

            var countryCurrency = new LinkCountryCurrencyRecord
            {
                CurrencyRecord = currency
            };

            if (viewModel.CountryId.HasValue)
            {
                var country = _countryRepository.Get(viewModel.CountryId.Value);
                countryCurrency.CountryRecord = country;
            }

            currency.CountryCurrencies.Add(countryCurrency);

            _currencyRepository.Create(currency);

            _orchardServices.Notifier.Information(T("Currency has been added!"));
            return RedirectToAction("Index");
        }