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)); }
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)); }
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)); }