示例#1
0
        /// /////////////////////////////

        async Task <IEnumerable <ReportGroupDTO> > BuildTreeAndGetRoots(List <ReportGroup> actualObjects)
        {
            Dictionary <int, ReportGroupDTO> lookup = new Dictionary <int, ReportGroupDTO>();

            actualObjects.ForEach(x => lookup.Add(x.Id, new ReportGroupDTO {
                AssociatedObject = x
            }));
            try
            {
                ReportGroupDTO proposedParent = new ReportGroupDTO();
                foreach (var item in lookup.Values)
                {
                    if (lookup.TryGetValue(item.AssociatedObject.ParentId, out proposedParent))
                    {
                        item.Parent = proposedParent;
                        proposedParent?.Childs?.Add(item);
                    }
                }
                var result = await Task.Run(() => lookup.Values.Where(x => x.AssociatedObject.ParentId == -1));

                return(result);
            }
            catch (Exception e)
            {
                Logger.Error(e, "");
                throw;
            }
        }
        public EntityListReportDTO ToEntityListReportDTO(DR_Requester requester, EntityListReport item, bool withDetails)
        {
            EntityListReportDTO result = new EntityListReportDTO();

            result.ID = item.ID;
            bizEntitySearchableReport.ToEntitySearchableReportDTO(item.EntitySearchableReport, result, withDetails);
            result.EntityListViewID = item.EntityListViewID;

            if (withDetails)
            {
                BizEntityRelationshipTail bizEntityRelationshipTail = new MyModelManager.BizEntityRelationshipTail();
                BizEntityListView         bizEntityListView         = new BizEntityListView();
                result.EntityListView = bizEntityListView.GetEntityListView(requester, item.EntityListViewID);
                if (result.EntityListView == null)
                {
                    throw new Exception("عدم دسترسی به لیست نمایش به شناسه" + " " + item.EntityListViewID);
                }
                foreach (var dbSubReport in item.EntityListReportSubs1)
                {
                    EntityListReportSubsDTO subReport = new EntityListReportSubsDTO();
                    subReport.Title   = dbSubReport.Title;
                    subReport.OrderID = dbSubReport.OrderID ?? 0;
                    subReport.EntityRelationshipTailID = dbSubReport.EntityRelationshipTailID;
                    subReport.EntityListReportID       = dbSubReport.ChildEntityListReportID;
                    foreach (var subColumn in dbSubReport.EntityListReportSubsColumns)
                    {
                        EntityListReportSubsColumnsDTO rSubsColumn = new EntityListReportSubsColumnsDTO();
                        rSubsColumn.ParentEntityListViewColumnsID          = subColumn.ParentEntityListViewColumnsID;
                        rSubsColumn.ParentEntityListViewColumnAlias        = subColumn.EntityListViewColumns1.Alias ?? subColumn.EntityListViewColumns1.Column.Name;
                        rSubsColumn.ParentEntityListViewColumnRelativeName = subColumn.EntityListViewColumns1.Column.Name + (subColumn.EntityListViewColumns1.EntityRelationshipTailID ?? 0);
                        rSubsColumn.ParentEntityListViewColumnType         = (Enum_ColumnType)subColumn.EntityListViewColumns1.Column.TypeEnum;

                        rSubsColumn.ChildEntityListViewColumnsID          = subColumn.ChildEntityListViewColumnsID;
                        rSubsColumn.ChildEntityListViewColumnAlias        = subColumn.EntityListViewColumns.Alias ?? subColumn.EntityListViewColumns.Column.Name;
                        rSubsColumn.ChildEntityListViewColumnRelativeName = subColumn.EntityListViewColumns.Column.Name + (subColumn.EntityListViewColumns.EntityRelationshipTailID ?? 0);
                        rSubsColumn.ChildEntityListViewColumnType         = (Enum_ColumnType)subColumn.EntityListViewColumns.Column.TypeEnum;

                        subReport.SubsColumnsDTO.Add(rSubsColumn);
                    }
                    result.EntityListReportSubs.Add(subReport);
                }
                foreach (var sub in item.ReportGroups)
                {
                    ReportGroupDTO rColumn = new ReportGroupDTO();
                    rColumn.ID = sub.ID;
                    rColumn.ListViewColumnID     = sub.EntityListViewColumnsID;
                    rColumn.EntityListViewColumn = result.EntityListView.EntityListViewAllColumns.First(x => x.ID == sub.EntityListViewColumnsID);
                    rColumn.ColumnName           = rColumn.EntityListViewColumn.Column.Alias;
                    result.ReportGroups.Add(rColumn);
                }
            }

            return(result);
        }