Example #1
0
        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));
        }
Example #2
0
        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));
        }