/// <summary> /// Update Notice data /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel UpdateNoticeData(XEditableModel model) { var notice = GetById(model.Pk); if (notice != null) { var property = ReflectionUtilities.GetAllPropertiesOfType(typeof(NoticeManageModel)) .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 NoticeManageModel(notice); manageModel.SetProperty(model.Name, value); var validationResults = manageModel.ValidateModel(); if (validationResults.Any()) { return(new ResponseModel { Success = false, Message = validationResults.BuildValidationMessages() }); } #endregion notice.SetProperty(model.Name, value); var response = Update(notice); return(response.SetMessage(response.Success ? T("Notice_Message_UpdateNoticeInfoSuccessfully") : T("Notice_Message_UpdateNoticeInfoFailure"))); } return(new ResponseModel { Success = false, Message = T("Notice_Message_PropertyNotFound") }); } return(new ResponseModel { Success = false, Message = T("Notice_Message_ObjectNotFound") }); }
public ActionResult PopupEdit(NoticeManageModel model, SubmitType submit) { if (ModelState.IsValid) { var response = _noticeService.SaveNotice(model); SetResponseMessage(response); if (response.Success) { switch (submit) { case SubmitType.PopupSave: return(View("CloseFancyBox", new CloseFancyBoxViewModel())); case SubmitType.SaveAndContinueEdit: return(RedirectToAction("PopupEdit", new { id = model.Id })); } } } SetupPopupAction(); return(View(model)); }
public ActionResult Create(NoticeManageModel model, SubmitType submit) { if (ModelState.IsValid) { var response = _noticeService.SaveNotice(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 })); } } } return(View(model)); }
/// <summary> /// Save notice /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SaveNotice(NoticeManageModel model) { ResponseModel response; var notice = GetById(model.Id); if (notice != null) { notice.DateStart = model.DateStart; notice.DateEnd = model.DateEnd; notice.Message = model.Message; notice.IsUrgent = model.IsUrgent; notice.NoticeTypeId = model.NoticeTypeId; response = Update(notice); return(response.SetMessage(response.Success ? T("Notice_Message_UpdateSuccessfully") : T("Notice_Message_UpdateFailure"))); } Mapper.CreateMap <NoticeManageModel, Notice>(); notice = Mapper.Map <NoticeManageModel, Notice>(model); response = Insert(notice); return(response.SetMessage(response.Success ? T("Notice_Message_CreateSuccessfully") : T("Notice_Message_CreateFailure"))); }
public ActionResult Edit(NoticeManageModel model, string returnUrl, SubmitType submit) { if (ModelState.IsValid) { var response = _noticeService.SaveNotice(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)); }