public async Task <ActionResult> Settings(string tabId, int parentId, IFormCollection collection) { var db = DbService.ReadSettingsForUpdate(); var model = EntityViewModel.Create <DbViewModel>(db, tabId, parentId); await TryUpdateModelAsync(model); if (ModelState.IsValid) { if (model.Data.RecordActions) { if (model.OverrideRecordsFile) { var currentDbVersion = _appInfoRepository.GetCurrentDbVersion(); XmlDbUpdateSerializerHelpers.ErasePreviouslyRecordedActions(CommonHelpers.GetBackendUrl(HttpContext), currentDbVersion); } if (model.OverrideRecordsUser || model.Data.SingleUserId == null) { model.Data.SingleUserId = QPContext.CurrentUserId; } } else { model.Data.SingleUserId = null; } model.Data = DbService.UpdateSettings(model.Data); return(Redirect("Settings", new { successfulActionCode = ActionCode.UpdateDbSettings })); } return(await JsonHtml("Settings", model)); }
public ActionResult Settings(string tabId, int parentId, FormCollection collection) { var db = DbService.ReadSettingsForUpdate(); var model = EntityViewModel.Create <DbViewModel>(db, tabId, parentId); TryUpdateModel(model); model.Validate(ModelState); if (ModelState.IsValid) { object message = null; var needSendMessage = false; if (model.Data.RecordActions) { if (model.OverrideRecordsFile) { var currentDbVersion = _appInfoRepository.GetCurrentDbVersion(); XmlDbUpdateSerializerHelpers.ErasePreviouslyRecordedActions(CommonHelpers.GetBackendUrl(HttpContext), currentDbVersion); } if (model.OverrideRecordsUser || model.Data.SingleUserId == null) { model.Data.SingleUserId = QPContext.CurrentUserId; needSendMessage = true; message = new { userId = QPContext.CurrentUserId, userName = QPContext.CurrentUserName }; } } else { needSendMessage = true; model.Data.SingleUserId = null; } model.Data = DbService.UpdateSettings(model.Data); if (needSendMessage) { _communicationService.Send("singleusermode", message); } return(Redirect("Settings", new { successfulActionCode = ActionCode.UpdateDbSettings })); } return(JsonHtml("Settings", model)); }
public virtual void Process(string xmlString, IList <string> filePathes = null) { Ensure.Argument.NotNullOrWhiteSpace(xmlString, nameof(xmlString)); var filteredXmlDocument = FilterFromSubRootNodeDuplicates(xmlString); var currentDbVersion = String.Empty; using (new QPConnectionScope(ConnectionInfo, _identityInsertOptions)) { currentDbVersion = _appInfoRepository.GetCurrentDbVersion(); ValidateReplayInput(filteredXmlDocument, currentDbVersion); } var filteredXmlString = filteredXmlDocument.ToNormalizedString(SaveOptions.DisableFormatting); var dbLogEntry = new XmlDbUpdateLogModel { UserId = _userId, Body = filteredXmlString, FileName = filePathes == null ? null : string.Join(",", filePathes), Applied = DateTime.Now, Hash = HashHelpers.CalculateMd5Hash(filteredXmlString) }; using (new ThreadStorageScopeContext()) using (var ts = QPConfiguration.CreateTransactionScope(IsolationLevel.ReadCommitted)) using (new QPConnectionScope(ConnectionInfo, _identityInsertOptions)) { if (_dbLogService.IsFileAlreadyReplayed(dbLogEntry.Hash)) { var throwEx = new XmlDbUpdateLoggingException("XmlDbUpdate conflict: current xml document(s) already applied and exist at database."); throwEx.Data.Add("LogEntry", dbLogEntry.ToJsonLog()); throw throwEx; } var updateId = _dbLogService.InsertFileLogEntry(dbLogEntry); ReplayActionsFromXml(filteredXmlDocument.Root?.Elements(), currentDbVersion, filteredXmlDocument.Root?.Attribute(XmlDbUpdateXDocumentConstants.RootBackendUrlAttribute)?.Value, updateId); ts.Complete(); } }