/// <summary> /// Save template /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SaveTemplateManageModel(WidgetTemplateManageModel model) { ResponseModel response; var template = GetById(model.Id); if (template != null) { var log = new WidgetTemplateLogManageModel(template); template.Name = model.Name; template.Widgets = SerializeUtilities.Serialize(model.Shortcuts); template.Content = model.Content; template.Style = model.Style; template.Script = model.Script; template.FullContent = GetFullTemplate(model); response = Update(template); if (response.Success) { _templateLogService.SaveTemplateLog(log); } return(response.SetMessage(response.Success ? T("WidgetTemplate_Message_UpdateSuccessfully") : T("WidgetTemplate_Message_UpdateFailure"))); } Mapper.CreateMap <WidgetTemplateManageModel, WidgetTemplate>(); template = Mapper.Map <WidgetTemplateManageModel, WidgetTemplate>(model); template.FullContent = GetFullTemplate(model); response = CreateTemplate(template); return(response.SetMessage(response.Success ? T("WidgetTemplate_Message_CreateSuccessfully") : T("WidgetTemplate_Message_CreateFailure"))); }
/// <summary> /// Save current page to audit /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SaveTemplateLog(WidgetTemplateLogManageModel model) { var template = _templateRepository.GetById(model.TemplateId); if (template != null) { /* * Map template log model to log entity * Get last updated version of template log * If there are nothing change then do not do anything * Otherwise insert log */ Mapper.CreateMap <WidgetTemplateLogManageModel, WidgetTemplateLog>(); var log = Mapper.Map <WidgetTemplateLogManageModel, WidgetTemplateLog>(model); var templateLog = GetAll().Where(a => a.TemplateId == template.Id).OrderByDescending(a => a.Id).FirstOrDefault(); log.ChangeLog = templateLog != null ? ChangeLog(templateLog, model) : "** Create Template **"; if (string.IsNullOrEmpty(log.ChangeLog)) { return(new ResponseModel { Success = true }); } log.SessionId = HttpContext.Current.Session.SessionID; return(Insert(log)); } return(new ResponseModel { Success = false, Message = T("WidgetTemplate_Message_ObjectNotFound") }); }
/// <summary> /// Update data and create change log /// </summary> /// <param name="widgetTemplateLog"></param> /// <param name="widgetTemplateLogModel"></param> /// <returns></returns> private string ChangeLog(WidgetTemplateLog widgetTemplateLog, WidgetTemplateLogManageModel widgetTemplateLogModel) { var changeLog = new StringBuilder(); const string format = "- Update field: {0}\n"; if (!ConvertUtilities.Compare(widgetTemplateLog.Name, widgetTemplateLogModel.Name)) { changeLog.AppendFormat(format, "Name"); widgetTemplateLog.Name = widgetTemplateLogModel.Name; } if (!ConvertUtilities.Compare(widgetTemplateLog.Content, widgetTemplateLogModel.Content)) { changeLog.AppendFormat(format, "Content"); widgetTemplateLog.Content = widgetTemplateLogModel.Content; } if (!string.IsNullOrEmpty(changeLog.ToString())) { changeLog.Insert(0, "** Update Template **\n"); } return(changeLog.ToString()); }