/// <summary> /// Save Script /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SaveScriptManageModel(ScriptManageModel model) { ResponseModel response; var script = GetById(model.Id); if (script != null) { var log = new ScriptLogManageModel(script); script.Name = model.Name; script.Content = model.Content; response = Update(script); if (response.Success) { _scriptLogService.SaveScriptLog(log); } return(response.SetMessage(response.Success ? T("Script_Message_UpdateSuccessfully") : T("Script_Message_UpdateFailure"))); } Mapper.CreateMap <ScriptManageModel, Script>(); script = Mapper.Map <ScriptManageModel, Script>(model); response = CreateScript(script); return(response.SetMessage(response.Success ? T("Script_Message_CreateSuccessfully") : T("Script_Message_CreateFailure"))); }
/// <summary> /// Save current page to audit /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SaveScriptLog(ScriptLogManageModel model) { var script = _scriptRepository.GetById(model.ScriptId); if (script != null) { /* * Map Script log model to log entity * Get last updated version of Script log * If there are nothing change then do not do anything * Otherwise insert log */ Mapper.CreateMap <ScriptLogManageModel, ScriptLog>(); var log = Mapper.Map <ScriptLogManageModel, ScriptLog>(model); var scriptLog = GetAll().Where(a => a.ScriptId == script.Id).OrderByDescending(a => a.Id).FirstOrDefault(); log.ChangeLog = scriptLog != null ? ChangeLog(scriptLog, model) : "** Create Script **"; 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("Script_Message_ObjectNotFound") }); }
/// <summary> /// Update data and create change log /// </summary> /// <param name="scriptLog"></param> /// <param name="scriptLogModel"></param> /// <returns></returns> private string ChangeLog(ScriptLog scriptLog, ScriptLogManageModel scriptLogModel) { var changeLog = new StringBuilder(); const string format = "- Update field: {0}\n"; if (!ConvertUtilities.Compare(scriptLog.Name, scriptLogModel.Name)) { changeLog.AppendFormat(format, "Name"); scriptLog.Name = scriptLogModel.Name; } if (!ConvertUtilities.Compare(scriptLog.Content, scriptLogModel.Content)) { changeLog.AppendFormat(format, "Content"); scriptLog.Content = scriptLogModel.Content; } if (!string.IsNullOrEmpty(changeLog.ToString())) { changeLog.Insert(0, "** Update Script **\n"); } return(changeLog.ToString()); }