Esempio n. 1
0
        public bool Update(Domain.QueryView entity)
        {
            var original = _queryViewRepository.FindById(entity.QueryViewId);

            entity.ModifiedBy = _currentUser.SystemUserId;
            entity.ModifiedOn = DateTime.Now;
            var result = true;

            using (UnitOfWork.Build(_queryViewRepository.DbContext))
            {
                result = _queryViewRepository.Update(entity);
                _dependencyService.Update(entity);
                //localization
                _localizedLabelService.Update(entity.Name.IfEmpty(""), "LocalizedName", entity.QueryViewId, _appContext.BaseLanguage);
                _localizedLabelService.Update(entity.Description.IfEmpty(""), "Description", entity.QueryViewId, _appContext.BaseLanguage);
                //assigning roles
                if (original.AuthorizationEnabled || !entity.AuthorizationEnabled)
                {
                    _eventPublisher.Publish(new AuthorizationStateChangedEvent
                    {
                        ObjectId = new List <Guid> {
                            entity.QueryViewId
                        }
                        ,
                        State = false
                        ,
                        ResourceName = QueryViewDefaults.ModuleName
                    });
                }
                //set to cache
                _cacheService.SetEntity(entity);
            }
            return(result);
        }
Esempio n. 2
0
 public bool Create(Domain.QueryView entity)
 {
     return(CreateCore(entity, (n) =>
     {
         _dependencyService.Create(n);
     }));
 }
Esempio n. 3
0
 private void WrapLocalizedLabel(Domain.QueryView entity)
 {
     /* 先关闭多语言切换功能 2018-10-10* /
      * /*
      * var labels = _localizedLabelService.Query(n => n.Where(f => f.LanguageId == this.User.UserSettings.LanguageId && f.ObjectId == entity.QueryViewId));
      * entity.Name = _localizedLabelService.GetLabelText(labels, entity.QueryViewId, "LocalizedName", entity.Name);
      * entity.Description = _localizedLabelService.GetLabelText(labels, entity.QueryViewId, "Description", entity.Description);
      */
 }
Esempio n. 4
0
        public bool Update(Domain.QueryView entity)
        {
            //依赖于字段
            var queryExp           = new QueryExpression().DeserializeFromJson(entity.FetchConfig);
            var requiredAttributes = _queryMetadataFinder.GetAttributes(queryExp);

            _dependencyService.Update(QueryViewDefaults.ModuleName, entity.QueryViewId, AttributeDefaults.ModuleName, requiredAttributes.Select(x => x.AttributeId).ToArray());
            //依赖于按钮
            if (entity.IsCustomButton && entity.CustomButtons.IsNotEmpty())
            {
                var buttonIds = new Guid[] { }.DeserializeFromJson(entity.CustomButtons);
                if (buttonIds.NotEmpty())
                {
                    _dependencyService.Update(QueryViewDefaults.ModuleName, entity.QueryViewId, RibbonButtonDefaults.ModuleName, buttonIds);
                }
            }
            return(true);
        }
Esempio n. 5
0
        private bool CreateCore(Domain.QueryView entity, Action <Domain.QueryView> createDependents)
        {
            entity.SolutionId = SolutionDefaults.DefaultSolutionId;//组件属于默认解决方案
            var result = true;

            using (UnitOfWork.Build(_queryViewRepository.DbContext))
            {
                result = _queryViewRepository.Create(entity);
                //依赖项
                createDependents(entity);

                //本地化标签
                _localizedLabelService.Append(entity.SolutionId, entity.Name.IfEmpty(""), QueryViewDefaults.ModuleName, "LocalizedName", entity.QueryViewId)
                .Append(entity.SolutionId, entity.Description.IfEmpty(""), QueryViewDefaults.ModuleName, "Description", entity.QueryViewId)
                .Save();
                //add to cache
                _cacheService.SetEntity(entity);
            }
            return(result);
        }
Esempio n. 6
0
        public GridDescriptor Build(Domain.QueryView view, List <Schema.Domain.Entity> entities, List <Schema.Domain.Attribute> attributes)
        {
            var            gridBuilder = new GridBuilder(view);
            GridDescriptor grid        = gridBuilder.Grid;
            int            i           = 0;

            foreach (var cell in grid.Rows[0].Cells)
            {
                if (cell.Label.IsEmpty())
                {
                    if (cell.EntityName.IsCaseInsensitiveEqual(view.EntityName))//主实体
                    {
                        var attr = attributes.Find(x => x.Name.IsCaseInsensitiveEqual(cell.Name) && x.EntityName.IsCaseInsensitiveEqual(view.EntityName));
                        if (attr != null)
                        {
                            grid.Rows[0].Cells[i].Label = attr.LocalizedName;
                        }
                    }
                    else //关联实体
                    {
                        //当列为关联实体字段时,列名加上关联实体名
                        var temp = cell.Name.SplitSafe(".");
                        if (temp.Length > 1)
                        {
                            var attr = attributes.Find(x => x.Name.IsCaseInsensitiveEqual(temp[1]) && x.EntityName.IsCaseInsensitiveEqual(cell.EntityName));
                            if (attr != null)
                            {
                                grid.Rows[0].Cells[i].Label = attr.LocalizedName + "(" + attr.EntityLocalizedName + ")";
                            }
                        }
                    }
                }
                i++;
            }

            return(grid);
        }
Esempio n. 7
0
 public GridBuilder(Domain.QueryView view)
 {
     _view = view;
     Grid  = Grid.DeserializeFromJson(_view.LayoutConfig);
 }
Esempio n. 8
0
        /// <summary>
        /// 生成默认视图
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public (Domain.QueryView DefaultView, List <Dependency.Domain.Dependency> Dependents) Get(Schema.Domain.Entity entity, List <Schema.Domain.Attribute> attributes)
        {
            Domain.QueryView view = new Domain.QueryView
            {
                Name        = entity.LocalizedName,
                EntityId    = entity.EntityId,
                EntityName  = entity.Name,
                IsDefault   = true,
                StateCode   = Core.RecordState.Enabled,
                IsPrivate   = false,
                QueryViewId = Guid.NewGuid(),
                CreatedBy   = entity.CreatedBy
            };
            //fetch
            QueryExpression _queryExpression = new QueryExpression(entity.Name, _appContext.GetFeature <ICurrentUser>().UserSettings.LanguageId);

            _queryExpression.Distinct = false;
            _queryExpression.NoLock   = true;
            _queryExpression.AddOrder("createdon", OrderType.Descending);
            var primaryField = attributes.Find(n => n.IsPrimaryField);

            _queryExpression.ColumnSet = new ColumnSet(primaryField.Name.ToLower(), "createdon");
            if (entity.EntityMask == EntityMaskEnum.User)
            {
                _queryExpression.ColumnSet.AddColumn("ownerid");
            }
            view.FetchConfig = _queryExpression.SerializeToJson();
            //layout
            GridDescriptor grid = new GridDescriptor();
            RowDescriptor  row  = new RowDescriptor();

            row.AddCell(new CellDescriptor()
            {
                Name = primaryField.Name.ToLower(), EntityName = entity.Name, IsHidden = false, IsSortable = true, Width = 150
            });
            row.AddCell(new CellDescriptor()
            {
                Name = "createdon", EntityName = entity.Name, IsHidden = false, IsSortable = true, Width = 150
            });
            if (entity.EntityMask == EntityMaskEnum.User)
            {
                row.AddCell(new CellDescriptor()
                {
                    Name = "ownerid", EntityName = entity.Name, IsHidden = false, IsSortable = true, Width = 150
                });
            }
            grid.AddRow(row);
            grid.AddSort(new QueryColumnSortInfo("createdon", false));
            view.LayoutConfig = grid.SerializeToJson(false);

            var dependents = new List <Dependency.Domain.Dependency>();

            foreach (var item in attributes.Where(x => x.Name.IsCaseInsensitiveEqual(primaryField.Name) || x.Name.IsCaseInsensitiveEqual("createdon") || x.Name.IsCaseInsensitiveEqual("ownerid")))
            {
                var dp = new Dependency.Domain.Dependency();
                //dp.DependentComponentType = DependencyComponentTypes.Get(QueryViewDefaults.ModuleName);
                dp.DependentObjectId = view.QueryViewId;
                //dp.RequiredComponentType = DependencyComponentTypes.Get(AttributeDefaults.ModuleName);
                dp.RequiredObjectId = item.AttributeId;
                dependents.Add(dp);
            }
            return(view, dependents);
        }