public async Task <ActionResult> CreateCountrySetting(CountrySettingViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Error"));
            }

            var countryId = model.CountryId ?? 0;

            if (countryId == 0)
            {
                ViewBag.Error = @Resources.ErrorMessages.NoCountryId;
                return(View("Error"));
            }

            var setting = _countrySettingsService.GetItem(countryId);

            if (setting != null)
            {
                ViewBag.Error = @Resources.ErrorMessages.SettingAlreadyExists;
                return(View("Error"));
            }

            try
            {
                var item = Mapper.Map <CountrySettingViewModel, CountrySettingDTO>(model);

                _countrySettingsService.AddItem(item);
                _countrySettingsService.Commit();
                _countrySettingsService.Dispose();

                var userName = User.Identity.Name;
                Logger.Log.Info($"{userName}: CreateCountrySetting {model.CountryId} ");

                TempData["Success"] = Resources.Messages.SettingsCreateSuccess;
                return(RedirectToAction("CountrySettings"));
            }
            catch (Exception ex)
            {
                var userName = User.Identity.Name;
                Logger.Log.Error($"{userName}: CreateProduct() {ex.Message} ");

                @ViewBag.Error = ex.Message;
                return(View("Error"));
            }
        }
Esempio n. 2
0
        // TODO: are these not the same now? Differ only on wrong type?
        public static Type WrapOrDefault <Type>(object o, bool mustRelease = true)
            where Type : IBase
        {
            IBase wrapped = Wrap(o, mustRelease);

            if (wrapped is Type)
            {
                return((Type)wrapped);
            }

            // Release if required
            if (wrapped != null)
            {
                wrapped.Dispose();
            }
            return(default(Type));
        }
 public void Dispose()
 {
     _municipios.Dispose();
 }