Exemplo n.º 1
0
        public ActionResult Edit([Bind(Include = "Id,Code,ShortName,FullName,Symbol")] CurrencyViewModel model)
        {
            if (ModelState.IsValid)
            {
                Currency currency = AdminModelsMapper.GetCurrency(model);
                using (var currencyRepository = RepositoryFactory.GetCurrencyRepository())
                {
                    currencyRepository.AddOrUpdate(currency);
                    currencyRepository.SaveChanges();

                    CacheHelper.ClearCachedCurrencies();
                    return(RedirectToAction("Index", "Currency", new { area = "Admin" }));
                }
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "Id,Code,ShortName,FullName,Symbol")] CurrencyViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Currency currency = AdminModelsMapper.GetCurrency(model);
                    using (var currencyRepository = RepositoryFactory.GetCurrencyRepository())
                    {
                        currencyRepository.AddOrUpdate(currency);
                        currencyRepository.SaveChanges();
                    }

                    CacheHelper.ClearCachedCurrencies();
                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                ModelState.AddModelError("Name", "Невозможно сохранить изменения.");
            }

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult Delete([Bind(Include = "Id,Code,ShortName,FullName,Symbol")] CurrencyViewModel model)
        {
            if (ModelState.IsValid)
            {
                Currency currency = AdminModelsMapper.GetCurrency(model);
                using (var currencyRepository = RepositoryFactory.GetCurrencyRepository())
                {
                    try
                    {
                        currencyRepository.Delete(currency);
                        currencyRepository.SaveChanges();

                        CacheHelper.ClearCachedCurrencies();
                        return(RedirectToAction("Index", "Currency", new { area = "Admin" }));
                    }
                    catch
                    {
                        ModelState.AddModelError("ShortName", "Невозможно удалить валюту из системы. Возможно, она используется пользователями магазина.");
                    }
                }
            }

            return(View(model));
        }