Beispiel #1
0
        public IActionResult RenderGridView([FromBody] EntityGridModel model)
        {
            QueryView.Domain.QueryView queryView = null;
            if (model.QueryViewId.HasValue && !model.QueryViewId.Equals(Guid.Empty))
            {
                queryView = _queryViewFinder.FindById(model.QueryViewId.Value);
            }
            else if (model.EntityId.HasValue && !model.EntityId.Value.Equals(Guid.Empty))
            {
                queryView = _queryViewFinder.FindEntityDefaultView(model.EntityId.Value);
            }
            else if (model.EntityName.IsNotEmpty())
            {
                queryView = _queryViewFinder.FindEntityDefaultView(model.EntityName);
            }
            else
            {
                return(NotFound());
            }
            if (queryView == null)
            {
                return(NotFound());
            }
            if (!queryView.IsDefault && queryView.AuthorizationEnabled)
            {
                if (!_roleObjectAccessService.Exists(queryView.QueryViewId, QueryViewDefaults.ModuleName, CurrentUser.Roles.Select(n => n.RoleId).ToArray()))
                {
                    return(Unauthorized());
                }
            }
            model.QueryView = queryView;
            model.EntityId  = queryView.EntityId;

            FetchDescriptor fetch = new FetchDescriptor
            {
                Page        = model.Page,
                PageSize    = model.PageSize,
                FetchConfig = queryView.FetchConfig,
                GetAll      = !model.PagingEnabled
            };

            if (model.IsSortBySeted)
            {
                QueryColumnSortInfo sort = new QueryColumnSortInfo(model.SortBy, model.SortDirection == 0);
                fetch.Sort = sort;
            }
            //查询关键字
            if (model.Q.IsNotEmpty())
            {
                fetch.Keyword = model.Q;
                fetch.Field   = model.QField;
            }
            var canFetch = true;

            //filter by relationship
            if (model.RelationShipName.IsNotEmpty())
            {
                var relationship = _relationShipFinder.FindByName(model.RelationShipName);
                if (relationship != null && model.ReferencedRecordId.HasValue && !model.ReferencedRecordId.Value.Equals(Guid.Empty))
                {
                    if (model.Filter == null)
                    {
                        model.Filter = new FilterExpression();
                    }
                    var condition = new ConditionExpression(relationship.ReferencingAttributeName, ConditionOperator.Equal, model.ReferencedRecordId);
                    model.Filter.AddCondition(condition);
                }
                model.RelationShipMeta = relationship;
            }
            if (model.RelationShipName.IsNotEmpty() && (!model.ReferencedRecordId.HasValue || model.ReferencedRecordId.Value.Equals(Guid.Empty)))
            {
                //如果被引用ID为空,则不查询数据
                canFetch = false;
            }
            fetch.Filter = model.Filter;
            if (canFetch)
            {
                fetch.User = CurrentUser;
                var datas = _fetchService.Execute(fetch);
                if (model.OnlyData)
                {
                    //var serializer = new DataContractJsonSerializer(typeof(User), new DataContractJsonSerializerSettings()
                    //{
                    //    UseSimpleDictionaryFormat = true//去掉Key和Value
                    //});
                    //return new JsonResult() { Data = datas.Items.SerializeToJson(), JsonRequestBehavior = JsonRequestBehavior.AllowGet };
                    return(Content(datas.SerializeToJson()));
                }
                model.Grid             = _gridService.Build(queryView, _fetchService.QueryResolver.EntityList, _fetchService.QueryResolver.AttributeList);
                model.EntityList       = _fetchService.QueryResolver.EntityList;
                model.AttributeList    = _fetchService.QueryResolver.AttributeList;
                model.RelationShipList = _fetchService.QueryResolver.RelationShipList;
                model.Items            = datas.Items;
                model.TotalItems       = datas.TotalItems;
            }
            else
            {
                _fetchService.GetMetaDatas(fetch);
                model.Grid             = _gridService.Build(queryView, _fetchService.QueryResolver.EntityList, _fetchService.QueryResolver.AttributeList);
                model.EntityList       = _fetchService.QueryResolver.EntityList;
                model.AttributeList    = _fetchService.QueryResolver.AttributeList;
                model.RelationShipList = _fetchService.QueryResolver.RelationShipList;
                model.Items            = new List <dynamic>();
                model.TotalItems       = 0;
            }
            var buttons = _ribbonbuttonFinder.Find(model.EntityId.Value, RibbonButtonArea.SubGrid);

            if (buttons.NotEmpty())
            {
                buttons             = buttons.OrderBy(x => x.DisplayOrder).ToList();
                model.RibbonButtons = buttons;
            }
            if (model.IsSortBySeted == false)
            {
                if (_fetchService.QueryExpression.Orders.NotEmpty())
                {
                    model.SortBy        = _fetchService.QueryExpression.Orders[0].AttributeName;
                    model.SortDirection = (int)_fetchService.QueryExpression.Orders[0].OrderType;
                }
            }
            return(View($"~/Views/Entity/{WebContext.ActionName}.cshtml", model));
        }
Beispiel #2
0
        public AggregateRoot Retrieve(QueryBase request, bool ignorePermissions = false)
        {
            //查询单个实体,查询列表

            //var entity = args.EntityId.Equals(Guid.Empty) ? _entityFinder.FindByName(args.EntityName) : _entityFinder.FindById(args.EntityId);

            //var record = _dataFinder.RetrieveById(entity.Name, args.RecordId.Value);

            string entityname = "";
            Guid?  recordId   = null;
            Guid?  formId     = null;

            _aggregateRoot.MainEntity = _dataFinder.RetrieveById(entityname, recordId.Value);

            //表单列表
            SystemForm formEntity = null;

            formEntity = _systemFormFinder.FindById(formId.Value);
            FormBuilder formBuilder = new FormBuilder(formEntity.FormConfig);

            List <PanelDescriptor> panelDescriptors = formBuilder.Form.Panels;

            foreach (var panel in panelDescriptors)
            {
                foreach (var section in panel.Sections)
                {
                    foreach (var row in section.Rows)
                    {
                        foreach (var cell in row.Cells)
                        {
                            if (cell.Control.ControlType == FormControlType.SubGrid)
                            {
                                var param = (SubGridParameters)cell.Control.Parameters;

                                //param.ViewId;
                                //param.RelationshipName

                                var queryView = _queryViewFinder.FindById(Guid.Parse(param.ViewId));
                                if (queryView != null)
                                {
                                    //if (!queryView.IsDefault && queryView.IsAuthorization)
                                    {
                                    }

                                    FetchDescriptor fetch = new FetchDescriptor
                                    {
                                        //Page = model.Page,
                                        //PageSize = model.PageSize,
                                        //FetchConfig = queryView.FetchConfig,
                                        //GetAll = !model.PagingEnabled
                                    };

                                    //排序,过滤
                                    var relationship = _relationShipFinder.FindByName(param.RelationshipName);
                                    var filter       = new FilterExpression();
                                    var condition    = new ConditionExpression(relationship.ReferencingAttributeName, ConditionOperator.Equal, recordId.Value);
                                    filter.AddCondition(condition);
                                    fetch.Filter = filter;
                                    fetch.User   = User;
                                    var datas = _fetchService.Execute(fetch);
                                    //_aggregateRoot.grids.Add("", datas.Items);
                                }
                            }
                        }
                    }
                }
            }
            return(_aggregateRoot);
        }
        public IActionResult Post([FromBody] EntityGridModel model)
        {
            QueryView.Domain.QueryView queryView = null;
            if (model.QueryViewId.HasValue && !model.QueryViewId.Equals(Guid.Empty))
            {
                queryView = _queryViewFinder.FindById(model.QueryViewId.Value);
            }
            else if (model.EntityId.HasValue && !model.EntityId.Value.Equals(Guid.Empty))
            {
                queryView = _queryViewFinder.FindEntityDefaultView(model.EntityId.Value);
            }
            else if (model.EntityName.IsNotEmpty())
            {
                queryView = _queryViewFinder.FindEntityDefaultView(model.EntityName);
            }
            else
            {
                return(NotFound());
            }
            if (queryView == null)
            {
                return(NotFound());
            }
            if (!queryView.IsDefault && queryView.AuthorizationEnabled)
            {
                if (!_roleObjectAccessService.Exists(queryView.QueryViewId, QueryViewDefaults.ModuleName, CurrentUser.Roles.Select(n => n.RoleId).ToArray()))
                {
                    return(Unauthorized());
                }
            }
            model.QueryView = queryView;
            model.EntityId  = queryView.EntityId;

            FetchDescriptor fetch = new FetchDescriptor
            {
                Page        = model.Page,
                PageSize    = model.PageSize,
                FetchConfig = queryView.FetchConfig,
                GetAll      = !model.PagingEnabled
            };

            if (model.IsSortBySeted)
            {
                QueryColumnSortInfo sort = new QueryColumnSortInfo(model.SortBy, model.SortDirection == 0);
                fetch.Sort = sort;
            }
            //查询关键字
            if (model.Q.IsNotEmpty())
            {
                fetch.Keyword = model.Q;
                fetch.Field   = model.QField;
            }
            var canFetch = true;

            //filter by relationship
            if (model.RelationShipName.IsNotEmpty())
            {
                var relationship = _relationShipFinder.FindByName(model.RelationShipName);
                if (relationship != null && model.ReferencedRecordId.HasValue && !model.ReferencedRecordId.Value.Equals(Guid.Empty))
                {
                    if (model.Filter == null)
                    {
                        model.Filter = new FilterExpression();
                    }
                    var condition = new ConditionExpression(relationship.ReferencingAttributeName, ConditionOperator.Equal, model.ReferencedRecordId);
                    model.Filter.AddCondition(condition);
                }
                model.RelationShipMeta = relationship;
            }
            if (model.RelationShipName.IsNotEmpty() && (!model.ReferencedRecordId.HasValue || model.ReferencedRecordId.Value.Equals(Guid.Empty)))
            {
                //如果被引用ID为空,则不查询数据
                canFetch = false;
            }
            fetch.Filter = model.Filter;
            if (canFetch)
            {
                fetch.User = CurrentUser;
                var    fetchDatas     = _fetchService.Execute(fetch);
                object aggregateDatas = null;
                if (queryView.AggregateConfig.IsNotEmpty())
                {
                    var aggFields = new List <AggregateExpressionField>().DeserializeFromJson(queryView.AggregateConfig);
                    if (aggFields.NotEmpty())
                    {
                        var queryExp = new QueryExpression().DeserializeFromJson(queryView.FetchConfig);
                        if (model.Filter != null &&
                            (model.Filter.Conditions.NotEmpty() || (model.Filter.Filters.NotEmpty() && model.Filter.Filters.First().Conditions.NotEmpty())))
                        {
                            queryExp.Criteria.AddFilter(model.Filter);
                        }
                        var aggExp = new AggregateExpression
                        {
                            ColumnSet       = queryExp.ColumnSet,
                            Criteria        = queryExp.Criteria,
                            EntityName      = queryExp.EntityName,
                            LinkEntities    = queryExp.LinkEntities,
                            AggregateFields = aggFields
                        };
                        var aggDatas   = _aggregateService.Execute(aggExp);
                        var attributes = _attributeFinder.FindByName(queryView.EntityId, aggFields.Select(x => x.AttributeName).ToArray());
                        foreach (dynamic item in aggDatas)
                        {
                            var line      = item as IDictionary <string, object>;
                            var attribute = attributes.Find(x => x.Name.IsCaseInsensitiveEqual(line.Keys.First()));
                            item.metadata      = new { attribute.Name, attribute.LocalizedName, attribute.AttributeTypeName, attribute.EntityId, attribute.EntityName, attribute.EntityLocalizedName };
                            item.aggregatetype = aggFields.Find(x => x.AttributeName.IsCaseInsensitiveEqual(attribute.Name)).AggregateType;
                        }
                        aggregateDatas = new { View = new { queryView.QueryViewId, queryView.Name }, Data = aggDatas };
                    }
                }
                return(Content(new { FetchData = fetchDatas, AggregateData = aggregateDatas }.SerializeToJson()));
            }
            if (!model.IsSortBySeted)
            {
                if (_fetchService.QueryExpression.Orders.NotEmpty())
                {
                    model.SortBy        = _fetchService.QueryExpression.Orders[0].AttributeName;
                    model.SortDirection = (int)_fetchService.QueryExpression.Orders[0].OrderType;
                }
            }
            return(View($"~/Views/Entity/{WebContext.ActionName}.cshtml", model));
        }
Beispiel #4
0
        public IActionResult GridView([FromBody] EntityGridModel model)
        {
            QueryView.Domain.QueryView queryView = null;
            if (model.QueryViewId.HasValue && !model.QueryViewId.Equals(Guid.Empty))
            {
                queryView = _queryViewFinder.FindById(model.QueryViewId.Value);
            }
            else if (model.EntityId.HasValue && !model.EntityId.Value.Equals(Guid.Empty))
            {
                queryView = _queryViewFinder.FindEntityDefaultView(model.EntityId.Value);
            }
            else if (model.EntityName.IsNotEmpty())
            {
                queryView = _queryViewFinder.FindEntityDefaultView(model.EntityName);
            }
            else
            {
                return(NotFound());
            }
            if (queryView == null)

            {
                return(NotFound());
            }
            if (!queryView.IsDefault && queryView.AuthorizationEnabled)
            {
                if (!_roleObjectAccessService.Exists(queryView.QueryViewId, QueryViewDefaults.ModuleName, CurrentUser.Roles.Select(n => n.RoleId).ToArray()))
                {
                    return(Unauthorized());
                }
            }
            //EntityGridModel model = new EntityGridModel();
            model.QueryView    = queryView;
            model.EntityId     = queryView.EntityId;
            model.QueryViewId  = queryView.QueryViewId;
            model.TargetFormId = queryView.TargetFormId;
            if (model.IsEnabledViewSelector)
            {
                model.QueryViews = _queryViewFinder.QueryAuthorized(n => n.Where(f => f.EntityId == model.EntityId && f.StateCode == RecordState.Enabled)
                                                                    .Sort(s => s.SortAscending(f => f.Name)));
            }
            if (!model.PageSizeBySeted && CurrentUser.UserSettings.PagingLimit > 0)
            {
                model.PageSize = CurrentUser.UserSettings.PagingLimit;
            }
            FetchDescriptor fetch = new FetchDescriptor
            {
                User        = CurrentUser,
                Page        = model.Page,
                PageSize    = model.PageSize,
                FetchConfig = queryView.FetchConfig
            };

            if (model.IsSortBySeted)
            {
                QueryColumnSortInfo sort = new QueryColumnSortInfo(model.SortBy, model.SortDirection == 0);
                fetch.Sort = sort;
            }
            fetch.Filter = model.Filter;

            if (model.Q.IsNotEmpty())
            {
                fetch.Keyword = model.Q;
                fetch.Field   = model.QField;
            }
            //buttons
            if (model.IsShowButtons)
            {
                FilterContainer <RibbonButton.Domain.RibbonButton> buttonFilter = FilterContainerBuilder.Build <RibbonButton.Domain.RibbonButton>()
                                                                                  .And(w => w.StateCode == RecordState.Enabled && w.EntityId == model.EntityId.Value &&
                                                                                       (w.ShowArea == RibbonButtonArea.ListHead || w.ShowArea == RibbonButtonArea.ListRow));
                if (model.QueryView.IsCustomButton && model.QueryView.CustomButtons.IsNotEmpty())
                {
                    List <Guid> buttonid = new List <Guid>();
                    buttonid = buttonid.DeserializeFromJson(model.QueryView.CustomButtons);
                    buttonFilter.And(w => w.RibbonButtonId.In(buttonid));
                }
                var buttons = _ribbonbuttonFinder.Query(n => n
                                                        .Where(buttonFilter)
                                                        .Sort(s => s.SortAscending(f => f.DisplayOrder)));
                model.RibbonButtons = buttons;
            }

            //var datas = _fetchService.Execute(fetch);
            _fetchDataService.GetMetaDatas(fetch);
            model.Grid             = _gridService.Build(queryView, _fetchDataService.QueryResolver.EntityList, _fetchDataService.QueryResolver.AttributeList);
            model.EntityList       = _fetchDataService.QueryResolver.EntityList;
            model.AttributeList    = _fetchDataService.QueryResolver.AttributeList;
            model.RelationShipList = _fetchDataService.QueryResolver.RelationShipList;
            //model.Items = datas.Items;
            //model.TotalItems = datas.TotalItems;
            //model.TotalPages = datas.TotalPages;
            //aggregation
            if (queryView.AggregateConfig.IsNotEmpty())
            {
                var aggFields = new List <AggregateExpressionField>().DeserializeFromJson(queryView.AggregateConfig);
                if (aggFields.NotEmpty())
                {
                    var aggExp = new AggregateExpression
                    {
                        ColumnSet       = _fetchDataService.QueryExpression.ColumnSet,
                        Criteria        = _fetchDataService.QueryExpression.Criteria,
                        EntityName      = _fetchDataService.QueryExpression.EntityName,
                        LinkEntities    = _fetchDataService.QueryExpression.LinkEntities,
                        AggregateFields = aggFields
                    };
                    var aggDatas = _aggregateService.Execute(aggExp);
                    model.AggregationData = aggDatas.NotEmpty() ? aggDatas.First() : null;
                    model.AggregateFields = aggFields;
                }
            }
            if (model.IsSortBySeted == false)
            {
                if (_fetchDataService.QueryExpression.Orders.NotEmpty())
                {
                    model.SortBy        = _fetchDataService.QueryExpression.Orders[0].AttributeName;
                    model.SortDirection = (int)_fetchDataService.QueryExpression.Orders[0].OrderType;
                }
            }
            //字段权限
            model.NonePermissionFields = _fetchDataService.NonePermissionFields;

            return(View($"~/Views/Entity/{WebContext.ActionName}.cshtml", model));
        }
Beispiel #5
0
        public IActionResult RecordsDialog([FromBody] SelectEntityRecordsDialogModel model, DialogModel dm)
        {
            QueryView.Domain.QueryView queryView = null;
            if (model.QueryId.HasValue && !model.QueryId.Equals(Guid.Empty))
            {
                queryView = _queryViewFinder.FindById(model.QueryId.Value);
            }
            else if (model.EntityId.HasValue && !model.EntityId.Equals(Guid.Empty))
            {
                queryView = _queryViewFinder.FindEntityDefaultView(model.EntityId.Value);
            }
            else if (model.EntityName.IsNotEmpty())
            {
                queryView = _queryViewFinder.FindEntityDefaultView(model.EntityName);
            }
            else
            {
                return(NotFound());
            }
            if (queryView == null)
            {
                return(NotFound());
            }
            model.QueryId   = queryView.QueryViewId;
            model.QueryView = queryView;
            model.EntityId  = queryView.EntityId;

            FetchDescriptor fetch = new FetchDescriptor
            {
                User        = CurrentUser,
                Page        = model.Page,
                PageSize    = model.PageSize,
                FetchConfig = queryView.FetchConfig
            };

            if (model.IsSortBySeted)
            {
                QueryColumnSortInfo sort = new QueryColumnSortInfo(model.SortBy, model.SortDirection == 0);
                fetch.Sort = sort;
            }
            if (model.Q.IsNotEmpty())
            {
                fetch.Keyword = model.Q;
                fetch.Field   = model.QField;
            }
            if (model.Filter == null)
            {
                model.Filter = new FilterExpression();
            }
            //filter disabled records
            if (model.OnlyEnabledRecords)
            {
                if (model.Filter.Conditions.IsEmpty() || model.Filter.Conditions.Find(n => n.AttributeName.IsCaseInsensitiveEqual("statecode")) == null)
                {
                    model.Filter.AddCondition("statecode", ConditionOperator.Equal, 1);
                }
            }
            //filter by relationship
            if (model.RelationShipName.IsNotEmpty())
            {
                var relationship = _relationShipFinder.FindByName(model.RelationShipName);
                if (relationship != null && model.ReferencedRecordId.HasValue && !model.ReferencedRecordId.Value.Equals(Guid.Empty))
                {
                    var condition = new ConditionExpression(relationship.ReferencingAttributeName, ConditionOperator.Equal, model.ReferencedRecordId);
                    model.Filter.AddCondition(condition);
                }
                model.RelationShipMeta = relationship;
            }
            fetch.Filter = model.Filter;

            var datas = _fetchDataService.Execute(fetch);

            model.Grid             = _gridService.Build(queryView, _fetchDataService.QueryResolver.EntityList, _fetchDataService.QueryResolver.AttributeList);
            model.EntityList       = _fetchDataService.QueryResolver.EntityList;
            model.AttributeList    = _fetchDataService.QueryResolver.AttributeList;
            model.RelationShipList = _fetchDataService.QueryResolver.RelationShipList;
            model.Items            = datas.Items;
            model.TotalItems       = datas.TotalItems;
            if (model.IsSortBySeted == false)
            {
                if (_fetchDataService.QueryExpression.Orders.NotEmpty())
                {
                    model.SortBy        = _fetchDataService.QueryExpression.Orders[0].AttributeName;
                    model.SortDirection = (int)_fetchDataService.QueryExpression.Orders[0].OrderType;
                }
            }

            ViewData["DialogModel"] = dm;
            return(View($"~/Views/Entity/{WebContext.ActionName}.cshtml", model));
        }
Beispiel #6
0
        public IActionResult Post([FromBody] EntityGridModel model)
        {
            QueryView.Domain.QueryView queryView = null;
            if (model.QueryViewId.HasValue && !model.QueryViewId.Equals(Guid.Empty))
            {
                queryView = _queryViewFinder.FindById(model.QueryViewId.Value);
            }
            else if (model.EntityId.HasValue && !model.EntityId.Value.Equals(Guid.Empty))
            {
                queryView = _queryViewFinder.FindEntityDefaultView(model.EntityId.Value);
            }
            else if (model.EntityName.IsNotEmpty())
            {
                queryView = _queryViewFinder.FindEntityDefaultView(model.EntityName);
            }
            else
            {
                return(NotFound());
            }
            if (queryView == null)
            {
                return(NotFound());
            }
            if (!queryView.IsDefault && queryView.AuthorizationEnabled)
            {
                if (!_roleObjectAccessService.Exists(queryView.QueryViewId, QueryViewDefaults.ModuleName, CurrentUser.Roles.Select(n => n.RoleId).ToArray()))
                {
                    return(Unauthorized());
                }
            }
            model.QueryView = queryView;
            model.EntityId  = queryView.EntityId;

            FetchDescriptor fetch = new FetchDescriptor
            {
                Page        = model.Page,
                PageSize    = model.PageSize,
                FetchConfig = queryView.FetchConfig,
                GetAll      = !model.PagingEnabled
            };

            if (model.IsSortBySeted)
            {
                QueryColumnSortInfo sort = new QueryColumnSortInfo(model.SortBy, model.SortDirection == 0);
                fetch.Sort = sort;
            }
            //查询关键字
            if (model.Q.IsNotEmpty())
            {
                fetch.Keyword = model.Q;
                fetch.Field   = model.QField;
            }
            var canFetch = true;

            //filter by relationship
            if (model.RelationShipName.IsNotEmpty())
            {
                var relationship = _relationShipFinder.FindByName(model.RelationShipName);
                if (relationship != null && model.ReferencedRecordId.HasValue && !model.ReferencedRecordId.Value.Equals(Guid.Empty))
                {
                    if (model.Filter == null)
                    {
                        model.Filter = new FilterExpression();
                    }
                    var condition = new ConditionExpression(relationship.ReferencingAttributeName, ConditionOperator.Equal, model.ReferencedRecordId);
                    model.Filter.AddCondition(condition);
                }
                model.RelationShipMeta = relationship;
            }
            if (model.RelationShipName.IsNotEmpty() && (!model.ReferencedRecordId.HasValue || model.ReferencedRecordId.Value.Equals(Guid.Empty)))
            {
                //如果被引用ID为空,则不查询数据
                canFetch = false;
            }
            fetch.Filter = model.Filter;
            if (canFetch)
            {
                fetch.User = CurrentUser;
                var datas = _fetchService.Execute(fetch);
                return(Content(datas.SerializeToJson()));
            }
            if (!model.IsSortBySeted)
            {
                if (_fetchService.QueryExpression.Orders.NotEmpty())
                {
                    model.SortBy        = _fetchService.QueryExpression.Orders[0].AttributeName;
                    model.SortDirection = (int)_fetchService.QueryExpression.Orders[0].OrderType;
                }
            }
            return(View($"~/Views/Entity/{WebContext.ActionName}.cshtml", model));
        }