public ActionResult PopupEdit(PageTemplateManageModel model, SubmitType submit) { if (ModelState.IsValid) { var response = _pageTemplateService.SavePageTemplate(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)); }
/// <summary> /// Update page template data /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel UpdatePageTemplateData(XEditableModel model) { var pageTemplate = GetById(model.Pk); if (pageTemplate != null) { var property = ReflectionUtilities.GetAllPropertiesOfType(typeof(PageTemplateManageModel)) .FirstOrDefault(p => p.Name.Equals(model.Name, StringComparison.CurrentCultureIgnoreCase)); if (property != null) { object value = model.Value.ToType(property, WorkContext.CurrentTimezone); #region Validate var manageModel = new PageTemplateManageModel(pageTemplate); manageModel.SetProperty(model.Name, value); var validationResults = manageModel.ValidateModel(); if (validationResults.Any()) { return(new ResponseModel { Success = false, Message = validationResults.BuildValidationMessages() }); } #endregion pageTemplate.SetProperty(model.Name, value); var response = Update(pageTemplate); return(response.SetMessage(response.Success ? T("PageTemplate_Message_UpdatePageTemplateInfoSuccessfully") : T("PageTemplate_Message_UpdatePageTemplateInfoFailure"))); } return(new ResponseModel { Success = false, Message = T("PageTemplate_Message_PropertyNotFound") }); } return(new ResponseModel { Success = false, Message = T("PageTemplate_Message_ObjectNotFound") }); }
/// <summary> /// Save page template /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SavePageTemplate(PageTemplateManageModel model) { ResponseModel response; var pageTemplate = GetById(model.Id); if (pageTemplate != null) { var log = new PageTemplateLogManageModel(pageTemplate); pageTemplate.Name = model.Name; pageTemplate.Content = model.Content; pageTemplate.ParentId = model.ParentId; pageTemplate.IsValid = true; pageTemplate.CompileMessage = string.Empty; response = HierarchyUpdate(pageTemplate); if (response.Success) { _pageTemplateLogService.SavePageTemplateLog(log); } response.SetMessage(response.Success ? T("PageTemplate_Message_UpdateSuccessfully") : T("PageTemplate_Message_UpdateFailure")); } else { Mapper.CreateMap <PageTemplateManageModel, PageTemplate>(); pageTemplate = Mapper.Map <PageTemplateManageModel, PageTemplate>(model); var sameLevelTemplates = Fetch(t => pageTemplate.ParentId.HasValue ? t.ParentId == model.ParentId : !t.ParentId.HasValue); var recordOrder = sameLevelTemplates.Any() ? sameLevelTemplates.Max(t => t.RecordOrder) + 10 : 10; pageTemplate.RecordOrder = recordOrder; pageTemplate.IsValid = true; response = HierarchyInsert(pageTemplate); response.SetMessage(response.Success ? T("PageTemplate_Message_CreateSuccessfully") : T("PageTemplate_Message_CreateFailure")); } // Re-initialize templates if (response.Success) { Initialize(pageTemplate.Id); } return(response); }
/// <summary> /// Save page template /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SavePageTemplate(PageTemplateManageModel model) { ResponseModel response; var pageTemplate = GetById(model.Id); if (pageTemplate != null) { var log = new PageTemplateLogManageModel(pageTemplate); var childTemplates = new List <PageTemplate>(); if (pageTemplate.Name.Equals(DefaultTemplateName)) { childTemplates = GetAll().Where(t => !t.Name.Equals(DefaultTemplateName)).ToList(); } else if (!pageTemplate.Content.Equals(model.Content) || pageTemplate.ParentId != model.ParentId) { childTemplates = _pageTemplateRepository.GetHierarcies(pageTemplate).ToList(); } if (childTemplates.Any()) { foreach (var childTemplate in childTemplates) { Update(childTemplate); } } pageTemplate.Name = model.Name; pageTemplate.Content = model.Content; pageTemplate.ParentId = model.ParentId; response = HierarchyUpdate(pageTemplate); if (response.Success) { _pageTemplateLogServices.SavePageTemplateLog(log); } return(response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::PageTemplates:::Messages:::UpdateSuccessfully:::Update page template successfully.") : _localizedResourceServices.T("AdminModule:::PageTemplates:::Messages:::UpdateFailure:::Update page template failed. Please try again later."))); } Mapper.CreateMap <PageTemplateManageModel, PageTemplate>(); pageTemplate = Mapper.Map <PageTemplateManageModel, PageTemplate>(model); response = HierarchyInsert(pageTemplate); return(response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::PageTemplates:::Messages:::CreateSuccessfully:::Create page template successfully.") : _localizedResourceServices.T("AdminModule:::PageTemplates:::Messages:::CreateFailure:::Create page template failed. Please try again later."))); }
public ActionResult Edit(int?id, int?logId) { PageTemplateManageModel model = null; if (id.HasValue) { model = _pageTemplateServices.GetTemplateManageModel(id.Value); } else if (logId.HasValue) { model = _pageTemplateServices.GetTemplateManageModelByLogId(logId.Value); } if (model == null) { SetErrorMessage(LocalizedResourceServices.T("AdminModule:::PageTemplates:::Messages:::ObjectNotFounded:::Page template is not founded.")); return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Edit(int?id, int?logId) { PageTemplateManageModel model = null; if (id.HasValue) { model = _pageTemplateService.GetTemplateManageModel(id.Value); } else if (logId.HasValue) { model = _pageTemplateService.GetTemplateManageModelByLogId(logId.Value); } if (model == null) { SetErrorMessage(T("PageTemplate_Message_ObjectNotFound")); return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Edit(PageTemplateManageModel model, SubmitTypeEnums submit) { if (ModelState.IsValid) { var response = _pageTemplateServices.SavePageTemplate(model); if (response.Success) { SetSuccessMessage(response.Message); switch (submit) { case SubmitTypeEnums.Save: return(RedirectToAction("Index")); default: return(RedirectToAction("Edit", new { id = model.Id })); } } SetErrorMessage(response.Message); } model.Parents = _pageTemplateServices.GetPossibleParents(model.Id); return(View(model)); }
public ActionResult Create(PageTemplateManageModel model, SubmitType submit) { if (ModelState.IsValid) { var response = _pageTemplateService.SavePageTemplate(model); SetResponseMessage(response); if (response.Success) { var id = (int)response.Data; switch (submit) { case SubmitType.Save: return(RedirectToAction("Index")); default: return(RedirectToAction("Edit", new { id })); } } } model.Parents = _pageTemplateService.GetPossibleParents(); return(View(model)); }
public ActionResult Edit(PageTemplateManageModel model, string returnUrl, SubmitType submit) { if (ModelState.IsValid) { var response = _pageTemplateService.SavePageTemplate(model); SetResponseMessage(response); if (response.Success) { switch (submit) { case SubmitType.Save: if (!string.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } return(RedirectToAction("Index")); default: return(RedirectToAction("Edit", new { id = model.Id, returnUrl })); } } } return(View(model)); }