RequestListFilterEntity SettingToFilter(FilterEntitySetting setting)
        {
            RequestListFilterEntity filter = RequestListFilterEntity.Create();

            filter.CloneKey      = new IdentKey(setting.CloneKey);
            filter.FilterName    = setting.FilterName;
            filter.StartDateTime = setting.StartDateTime;
            filter.StopDateTime  = setting.StopDateTime;

            UserEntity user = _nsiService.GetUserById(setting.ResponseId);

            filter.ResponseUser = user == null?UserEntity.Create() : user;

            user = _nsiService.GetUserById(setting.CreatorId);
            filter.CreatorUser = user == null?UserEntity.Create() : user;

            AppEntity app = _nsiService.GetAppById(setting.ApplicationId);

            filter.Application = app == null?AppEntity.Create() : app;

            OrgEntity org = _nsiService.GetOrgById(setting.OrganizationId);

            filter.Organization = org == null?OrgEntity.Create() : org;

            filter.Comments     = setting.Comments;
            filter.Subject      = setting.Subject;
            filter.Contact      = setting.Contact;
            filter.TagIdList    = setting.TagIdList;
            filter.StatusIdList = setting.StatusIdList;

            return(filter);
        }
        RequestListViewModel SettingToRequestListVM(ListViewModelSetting setting)
        {
            FilterEntitySetting filterSetting = new FilterEntitySetting();

            LoadSetting <FilterEntitySetting>(setting.CurrentFilterName, filterSetting);

            RequestListFilterEntity filter    = SettingToFilter(filterSetting);
            RequestListViewModel    viewModel = _mainController.CreateRequestListViewModel(filter, setting.ReadOnly);

            viewModel.InitialCurrentRequestId = setting.CurrentRequestId;

            return(viewModel);
        }
        ListViewModelSetting RequestListVMToSetting(RequestListViewModel viewModel)
        {
            ListViewModelSetting setting = new ListViewModelSetting();

            setting.CurrentRequestId  = viewModel.RequestList.Current != null ? viewModel.RequestList.Current.Id : null;
            setting.ReadOnly          = viewModel.ReadOnly;
            setting.GridData          = viewModel.GridData;
            setting.CurrentFilterName = viewModel.Filter.InternalName;
            FilterEntitySetting filterSetting = FilterToSetting(viewModel.Filter);

            SaveSetting(setting.CurrentFilterName, filterSetting);

            return(setting);
        }
        FilterEntitySetting FilterToSetting(RequestListFilterEntity filter)
        {
            FilterEntitySetting setting = new FilterEntitySetting();

            setting.CloneKey       = filter.CloneKey.ToGuid();
            setting.FilterName     = filter.FilterName;
            setting.StartDateTime  = filter.StartDateTime;
            setting.StopDateTime   = filter.StopDateTime;
            setting.OrganizationId = filter.Organization.Id;
            setting.ApplicationId  = filter.Application.Id;
            setting.ResponseId     = filter.ResponseUser.Id;
            setting.CreatorId      = filter.CreatorUser.Id;
            setting.TagIdList      = filter.TagIdList;
            setting.Subject        = filter.Subject;
            setting.Comments       = filter.Comments;
            setting.Contact        = filter.Contact;
            setting.StatusIdList   = filter.StatusIdList;

            return(setting);
        }
        public void Save()
        {
            using (DbTransaction transaction = new DbTransaction(_dbMgr))
            {
                Clear();

                RootSetting rootSetting = new RootSetting();

                if (_filterEntityList != null)
                {
                    foreach (RequestListFilterEntity filter in _filterEntityList)
                    {
                        FilterEntitySetting filterSetting = FilterToSetting(filter);
                        SaveSetting(filter.InternalName, filterSetting);
                        rootSetting.FilterList.Add(filter.InternalName);
                    }
                }

                if (_requestEditVMList != null)
                {
                    foreach (RequestEditViewModel viewModel in _requestEditVMList)
                    {
                        EditViewModelSetting viewModelSetting = RequstEditVMToSetting(viewModel);
                        SaveSetting(viewModel.Name, viewModelSetting);
                        rootSetting.EditViewModelList.Add(viewModel.Name);
                    }
                }
                if (_requestListVMList != null)
                {
                    foreach (RequestListViewModel viewModel in _requestListVMList)
                    {
                        ListViewModelSetting viewModelSetting = RequestListVMToSetting(viewModel);
                        SaveSetting(viewModel.Name, viewModelSetting);
                        rootSetting.ListViewModelList.Add(viewModel.Name);
                    }
                }

                SaveSetting(RootSettingName, rootSetting);
                transaction.Success = true;
            }
        }
        public void Load()
        {
            Init();

            RootSetting rootSetting = new RootSetting();

            LoadSetting <RootSetting>(RootSettingName, rootSetting);

            if (rootSetting.FilterList != null)
            {
                foreach (string filterName in rootSetting.FilterList)
                {
                    FilterEntitySetting filterSetting = new FilterEntitySetting();
                    LoadSetting <FilterEntitySetting>(filterName, filterSetting);
                    _filterEntityList.Add(SettingToFilter(filterSetting));
                }
            }

            if (rootSetting.EditViewModelList != null)
            {
                foreach (string editVMName in rootSetting.EditViewModelList)
                {
                    EditViewModelSetting editVMSetting = new EditViewModelSetting();
                    LoadSetting <EditViewModelSetting>(editVMName, editVMSetting);
                    _requestEditVMList.Add(SettingToRequestEditVM(editVMSetting));
                }
            }

            if (rootSetting.ListViewModelList != null)
            {
                foreach (string ListVMName in rootSetting.ListViewModelList)
                {
                    ListViewModelSetting listVMSetting = new ListViewModelSetting();
                    LoadSetting <ListViewModelSetting>(ListVMName, listVMSetting);
                    RequestListViewModel viewModel = SettingToRequestListVM(listVMSetting);
                    viewModel.Name = ListVMName;
                    _requestListVMList.Add(viewModel);
                }
            }
        }