public ResponseModel SaveSettingManageModel(SiteSettingManageModel model, NameValueCollection data) { var setting = _siteSettingRepository.GetByKey(model.SettingName); if (setting != null) { setting.SettingTypeId = model.SettingTypeId; var settingParsers = ReflectionUtilities.GetAllImplementTypesOfInterface(typeof(ISettingModel)); ResponseModel response; foreach (var parser in settingParsers) { var instance = (ISettingModel)Activator.CreateInstance(parser); if (instance.SettingName.Equals(setting.Name)) { setting.Value = instance.GetSettingValue(data); response = Update(setting); return(response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::Settings:::Messages:::UpdateSuccessfully:::Update setting successfully.") : _localizedResourceServices.T("AdminModule:::Settings:::Messages:::UpdateFailure:::Update setting failed. Please try again later."))); } } setting.Value = data["Value"]; response = Update(setting); return(response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::Settings:::Messages:::UpdateSuccessfully:::Update setting successfully.") : _localizedResourceServices.T("AdminModule:::Settings:::Messages:::UpdateFailure:::Update setting failed. Please try again later."))); } return(new ResponseModel { Success = false, Message = _localizedResourceServices.T("AdminModule:::Settings:::Messages:::ObjectNotFounded:::Setting is not founded.") }); }
public SiteSettingManageModel GetSettingManageModel(int id) { var setting = GetById(id); if (setting != null) { var settingManageModel = new SiteSettingManageModel { SettingTypeId = setting.SettingTypeId, SettingTypes = _settingTypeServices.GetSettingTypes(setting.SettingTypeId), SettingName = setting.Name }; var settingParsers = ReflectionUtilities.GetAllImplementTypesOfInterface(typeof(ISettingModel)); foreach (var parser in settingParsers) { var instance = (ISettingModel)Activator.CreateInstance(parser); if (instance.SettingName.Equals(setting.Name)) { settingManageModel.Setting = instance.LoadSetting(); return(settingManageModel); } } settingManageModel.Setting = setting; return(settingManageModel); } return(null); }
/// <summary> /// Save site setting /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SaveSettingManageModel(SiteSettingManageModel model) { var setting = GetByKey(model.SettingName); if (setting != null) { setting.SettingType = model.SettingType; setting.Description = model.Description; setting.Value = model.Value; var response = UpdateSetting(setting); // Re-init site settings if (response.Success) { Initialize(); } return(response.SetMessage(response.Success ? T("SiteSetting_Message_UpdateSuccessfully") : T("SiteSetting_Message_UpdateFailure"))); } return(new ResponseModel { Success = false, Message = T("SiteSetting_Message_ObjectNotFound") }); }
public ActionResult PopupEdit(SiteSettingManageModel model, SubmitType submit) { if (ModelState.IsValid) { var response = _siteSettingService.SaveSettingManageModel(model); SetResponseMessage(response); if (response.Success) { switch (submit) { case SubmitType.PopupSave: return(View("CloseFancyBox", new CloseFancyBoxViewModel { IsReload = false, ReturnUrl = string.Empty })); case SubmitType.SaveAndContinueEdit: return(RedirectToAction("PopupEdit", new { id = model.Id })); } } } SetupPopupAction(); return(View(model)); }
public ActionResult Edit(SiteSettingManageModel model, SubmitType submit) { if (ModelState.IsValid) { var setting = _siteSettingService.GetSetting(model.SettingName); var updateSuccess = true; var settingParser = HostContainer.GetInstances <IComplexSetting>().FirstOrDefault(parser => parser.GetSetup().Name.Equals(setting.Name)); if (settingParser != null) { if (TryUpdateModel((dynamic)settingParser)) { model.Value = SerializeUtilities.Serialize(settingParser); } else { updateSuccess = false; } } if (updateSuccess) { var response = _siteSettingService.SaveSettingManageModel(model); SetResponseMessage(response); if (response.Success) { switch (submit) { case SubmitType.Save: return(RedirectToAction("Index")); default: return(RedirectToAction("Edit", new { id = model.Id })); } } } SetErrorMessage(T("SiteSetting_Message_UpdateFailure")); return(RedirectToAction("Edit", new { id = model.Id })); } return(View(model)); }
public ActionResult Edit(SiteSettingManageModel model, SubmitTypeEnums submit) { if (ModelState.IsValid) { var response = _settingServices.SaveSettingManageModel(model, Request.Form); if (response.Success) { var templateId = model.Id; SetSuccessMessage(response.Message); switch (submit) { case SubmitTypeEnums.Save: return(RedirectToAction("Index")); default: return(RedirectToAction("Edit", new { id = templateId })); } } SetErrorMessage(response.Message); } return(View(model)); }