Beispiel #1
0
        public virtual ActionResult <string> PartialUpdateContext([FromBody] RequestAppletModel model)
        {
            // Получение всех необходимых сущностей
            Applet applet = viewInfo.ViewApplets.FirstOrDefault(n => n.Name == model.AppletName);
            BusinessObjectComponent component = viewInfo.BOComponents.FirstOrDefault(bcId => bcId.BusCompId == applet.BusCompId);

            // Получение списка с апплетами, необходимыми для обновления. Если есть флаг обновления текущего апплета, то он добавляется в выходной список
            List <Applet> appletsToUpdate = new List <Applet>();

            if (model.RefreshCurrentApplet)
            {
                appletsToUpdate.Add(applet);
            }

            // Добавление всех апплетов, основанных на той же компоненте и не являющихся попапами в список для обновления
            viewInfo.ViewApplets.ForEach(viewApplet =>
            {
                if (viewApplet.BusCompId == applet.BusCompId && viewApplet.Id != applet.Id && viewApplet.Type != "Popup")
                {
                    appletsToUpdate.Add(viewApplet);
                }
            });

            AppletListBuilding(new List <BusinessObjectComponent>(), component, component, appletsToUpdate);
            appletsToUpdate = appletsToUpdate.Where(i => i.Initflag == false).ToList();
            //viewInfo.AppletsSortedByLinks.AddRange(appletsToUpdate);

            // Result
            return(JsonConvert.SerializeObject(appletsToUpdate.Select(n => n.Name), Formatting.Indented, new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            }));
        }
        public override BUSBusinessObjectComponent DataToBusiness(BusinessObjectComponent dataEntity, TContext context)
        {
            BUSBusinessObjectComponent businessEntity = base.DataToBusiness(dataEntity, context);

            // BusObject
            BusinessObject busObject = context.BusinessObjects.AsNoTracking().FirstOrDefault(i => i.Id == dataEntity.BusObjectId);

            businessEntity.BusObject     = busObject;
            businessEntity.BusObjectId   = busObject.Id;
            businessEntity.BusObjectName = busObject.Name;

            // BusComp
            BusinessComponent busComp = context.BusinessComponents.AsNoTracking().FirstOrDefault(i => i.Id == dataEntity.BusCompId);

            if (busComp != null)
            {
                businessEntity.BusCompId   = busComp.Id;
                businessEntity.BusCompName = busComp.Name;
            }

            // Link
            Link link = context.Links.AsNoTracking().FirstOrDefault(i => i.Id == dataEntity.LinkId);

            if (link != null)
            {
                businessEntity.Link     = link;
                businessEntity.LinkId   = link.Id;
                businessEntity.LinkName = link.Name;
            }
            return(businessEntity);
        }
Beispiel #3
0
        public override BUSDataMapField Init(TContext context)
        {
            BUSDataMapField        businessEntity   = base.Init(context);
            DataMapObjectComponent dataMapComponent = context.DataMapObjectComponents
                                                      .AsNoTracking()
                                                      .Select(mapComponent => new
            {
                id = mapComponent.Id,
                sourceBOComponentId      = mapComponent.SourceBOComponentId,
                destinationBOComponentId = mapComponent.DestinationBOComponentId
            })
                                                      .Select(mapComponent => new DataMapObjectComponent
            {
                Id = mapComponent.id,
                SourceBOComponentId      = mapComponent.sourceBOComponentId,
                DestinationBOComponentId = mapComponent.destinationBOComponentId,
            })
                                                      .FirstOrDefault(i => i.Id.ToString() == ComponentsRecordsInfo.GetSelectedRecord("Data Map Object Component"));

            if (dataMapComponent != null)
            {
                businessEntity.DataMapComponent   = dataMapComponent;
                businessEntity.DataMapComponentId = dataMapComponent.Id;
                BusinessObjectComponent sourceBOComponent = context.BusinessObjectComponents.FirstOrDefault(i => i.Id == dataMapComponent.SourceBOComponentId);
                businessEntity.SourceBusinessComponentId = sourceBOComponent.BusCompId;
                BusinessObjectComponent destinationBOComponentId = context.BusinessObjectComponents.FirstOrDefault(i => i.Id == dataMapComponent.DestinationBOComponentId);
                businessEntity.DestinationBusinessComponentId = destinationBOComponentId.BusCompId;
            }
            return(businessEntity);
        }
Beispiel #4
0
        public override void ExecuteQuery([FromBody] UIApplet model)
        {
            base.ExecuteQuery(model);
            string        searchSpecification = "";
            List <object> searchSpecArgs      = new List <object>();

            if (!string.IsNullOrWhiteSpace(model.Name))
            {
                searchSpecification += $"Name.ToLower().Contains(@0)";
                searchSpecArgs.Add(model.Name.ToLower());
            }
            if (!string.IsNullOrWhiteSpace(model.BusCompName))
            {
                List <Guid?> componentsId = new List <Guid?>();
                context.BusinessComponents.Where(n => n.Name.ToLower().Contains(model.BusCompName.ToLower())).ToList().ForEach(component => componentsId.Add(component.Id));
                searchSpecArgs.Add(componentsId);
                searchSpecification = string.IsNullOrWhiteSpace(searchSpecification) ? "@0.Contains(BusCompId)" : $"{searchSpecification} && {"@1.Contains(BusCompId)"}";
            }
            if (!string.IsNullOrWhiteSpace(model.Type))
            {
                searchSpecArgs.Add(model.Type.ToLower());
                string typeSearchSpec = $"Type.ToLower().Contains(@{searchSpecArgs.IndexOf(model.Type.ToLower())})";
                searchSpecification = string.IsNullOrWhiteSpace(searchSpecification) ? typeSearchSpec : $"{searchSpecification} && {typeSearchSpec}";
            }
            BusinessObjectComponent objectComponent = viewInfo.BOComponents.FirstOrDefault(n => n.Name == "Applet");

            ComponentsRecordsInfo.SetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecification, searchSpecification);
            ComponentsRecordsInfo.SetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecArgs, searchSpecArgs.ToArray());
        }
Beispiel #5
0
        public virtual void CancelQuery()
        {
            viewInfo.ActionType = ActionType.CancelQuery;
            Applet applet = viewInfo.CurrentPopupApplet ?? viewInfo.CurrentApplet;
            BusinessObjectComponent objectComponent = viewInfo.BOComponents.FirstOrDefault(i => i.BusCompId == applet.BusCompId);

            SetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecification, string.Empty);
            SetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecArgs, null);
        }
        public override BusinessObjectComponent BusinessToData(BusinessObjectComponent boComponent, BUSBusinessObjectComponent businessEntity, TContext context, bool NewRecord)
        {
            BusinessObjectComponent dataEntity = base.BusinessToData(boComponent, businessEntity, context, NewRecord);

            dataEntity.BusObject   = businessEntity.BusObject;
            dataEntity.BusObjectId = businessEntity.BusObjectId;
            dataEntity.BusComp     = businessEntity.BusComp;
            dataEntity.BusCompId   = businessEntity.BusCompId;
            dataEntity.Link        = businessEntity.Link;
            dataEntity.LinkId      = businessEntity.LinkId;
            return(dataEntity);
        }
        public override BUSDataMapField DataToBusiness(DataMapField dataEntity, TContext context)
        {
            BUSDataMapField        businessEntity   = base.DataToBusiness(dataEntity, context);;
            DataMapObjectComponent dataMapComponent = context.DataMapObjectComponents
                                                      .AsNoTracking()
                                                      .Select(mapComponent => new
            {
                id   = mapComponent.Id,
                name = mapComponent.Name,
                sourceBusinessComponentId      = mapComponent.SourceBOComponentId,
                destinationBusinessComponentId = mapComponent.DestinationBOComponentId,
                dataMapFields = mapComponent.DataMapFields.Select(mapField => new
                {
                    id   = mapField.Id,
                    name = mapField.Name
                })
            })
                                                      .Select(mapComponent => new DataMapObjectComponent
            {
                Id   = mapComponent.id,
                Name = mapComponent.name,
                SourceBOComponentId      = mapComponent.sourceBusinessComponentId,
                DestinationBOComponentId = mapComponent.destinationBusinessComponentId,
                DataMapFields            = mapComponent.dataMapFields.Select(mapField => new DataMapField
                {
                    Id   = mapField.id,
                    Name = mapField.name
                }).ToList()
            })
                                                      .FirstOrDefault(i => i.Id == dataEntity.DataMapComponentId);

            businessEntity.DataMapComponent   = dataMapComponent;
            businessEntity.DataMapComponentId = dataMapComponent.Id;
            BusinessObjectComponent sourceBOComponent = context.BusinessObjectComponents.FirstOrDefault(i => i.Id == dataMapComponent.SourceBOComponentId);

            businessEntity.SourceBusinessComponentId = sourceBOComponent.BusCompId;
            BusinessObjectComponent destinationBOComponentId = context.BusinessObjectComponents.FirstOrDefault(i => i.Id == dataMapComponent.DestinationBOComponentId);

            businessEntity.DestinationBusinessComponentId = destinationBOComponentId.BusCompId;
            Field sourceField = context.Fields.FirstOrDefault(i => i.Id == dataEntity.SourceFieldId);

            if (sourceField != null)
            {
                businessEntity.SourceField     = sourceField;
                businessEntity.SourceFieldId   = sourceField.Id;
                businessEntity.SourceFieldName = sourceField.Name;
            }
            businessEntity.Destination     = dataEntity.Destination;
            businessEntity.FieldValidation = dataEntity.FieldValidation;
            return(businessEntity);
        }
Beispiel #8
0
        public override void ExecuteQuery([FromBody] UIScreen model)
        {
            base.ExecuteQuery(model);
            string        searchSpecification = "";
            List <object> searchSpecArgs      = new List <object>();

            if (!string.IsNullOrWhiteSpace(model.Name))
            {
                searchSpecification += $"Name.ToLower().Contains(@0)";
                searchSpecArgs.Add(model.Name.ToLower());
            }
            BusinessObjectComponent objectComponent = viewInfo.BOComponents.FirstOrDefault(n => n.Name == "Screen");

            ComponentsRecordsInfo.SetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecification, searchSpecification);
            ComponentsRecordsInfo.SetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecArgs, searchSpecArgs.ToArray());
        }
        public override void ExecuteQuery([FromBody] UIBusinessComponent model)
        {
            base.ExecuteQuery(model);
            string        searchSpecification = "";
            List <object> searchSpecArgs      = new List <object>();

            if (!string.IsNullOrWhiteSpace(model.Name))
            {
                searchSpecification += $"Name.ToLower().Contains(@0)";
                searchSpecArgs.Add(model.Name.ToLower());
            }
            if (!string.IsNullOrWhiteSpace(model.TableName))
            {
                List <Guid?> tablesId = new List <Guid?>();
                context.Tables.Where(n => n.Name.ToLower().Contains(model.TableName.ToLower())).ToList().ForEach(table => tablesId.Add(table.Id));
                searchSpecArgs.Add(tablesId);
                searchSpecification = string.IsNullOrWhiteSpace(searchSpecification) ? "@0.Contains(TableId)" : $"{searchSpecification} && @1.Contains(TableId)";
            }
            BusinessObjectComponent objectComponent = viewInfo.BOComponents.FirstOrDefault(n => n.Name == "Business Component");

            ComponentsRecordsInfo.SetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecification, searchSpecification);
            ComponentsRecordsInfo.SetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecArgs, searchSpecArgs.ToArray());
        }
Beispiel #10
0
        public ActionResult <object> GetRecord(string appletName)
        {
            // Если в представлении не установлена текущая запись
            if (viewInfo.CurrentRecord == null && orderedEntities.FirstOrDefault() != null)
            {
                viewInfo.CurrentRecord = orderedEntities.FirstOrDefault().Id.ToString();
            }

            TBUSUIFactory      busUIFactory   = new TBUSUIFactory();
            TDataBUSFactory    dataBUSFactory = new TDataBUSFactory();
            TBusinessComponent businessEntity;

            ViewItem                viewItem        = viewInfo.ViewItems.FirstOrDefault(n => n.Applet.Name == appletName);
            BusinessComponent       busComp         = viewInfo.ViewBCs.FirstOrDefault(i => i.Id == viewItem.Applet.BusCompId);
            BusinessObjectComponent objectComponent = viewInfo.BOComponents.FirstOrDefault(bcId => bcId.BusCompId == busComp.Id);
            string selectedRecordId = GetSelectedRecord(busComp?.Name);

            if (viewInfo.AppletsSortedByLinks.LastOrDefault()?.Id == viewItem.Applet?.Id)
            {
                viewInfo.EndInitialize();
            }

            // Если у апплета установлена кастомная инициализация
            if ((viewInfo.CurrentApplet?.Initflag == true && viewInfo.CurrentApplet.Name == appletName) ||
                (viewInfo.CurrentPopupApplet?.Initflag == true && viewInfo.CurrentPopupApplet.Name == appletName))
            {
                TBusinessComponent initComponent = busUIFactory.Init(context);
                ComponentsContext <TBusinessComponent> .SetComponentContext(busComp.Name, initComponent);

                return(JsonConvert.SerializeObject(busUIFactory.BusinessToUI(initComponent), Formatting.Indented, new JsonSerializerSettings
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                }));
            }

            // Выделенная запись
            if (selectedRecordId != null)
            {
                businessEntity = dataBUSFactory.DataToBusiness(orderedEntities.FirstOrDefault(i => i.Id.ToString() == selectedRecordId), context);
            }

            // Запись по умолчанию, в случае, если на бизнес компонете апплета нет выделенной записи
            else
            {
                // Если у записи есть ограничение по родительской
                string searchSpecificationByParent = GetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecificationByParent);
                if (searchSpecificationByParent == null)
                {
                    // Если количество отображаемых записей больше нуля
                    if (orderedEntities?.Count() > 0)
                    {
                        businessEntity = dataBUSFactory.DataToBusiness(orderedEntities.ElementAtOrDefault(viewItem.AutofocusRecord), context);
                    }
                    else
                    {
                        businessEntity = new TBusinessComponent()
                        {
                        };
                        return(null);
                    }
                }
                else
                {
                    // Если количество отображаемых записей больше нуля
                    if (orderedEntities.AsQueryable().Where(searchSpecificationByParent)?.Count() != 0)
                    {
                        businessEntity = dataBUSFactory.DataToBusiness(orderedEntities.ElementAtOrDefault(viewItem.AutofocusRecord), context);
                    }
                    else
                    {
                        businessEntity = new TBusinessComponent()
                        {
                        };
                        return(null);
                    }
                }
            }

            ComponentsContext <TBusinessComponent> .SetComponentContext(busComp.Name, businessEntity);

            return(Ok(JsonConvert.SerializeObject(busUIFactory.BusinessToUI(businessEntity), Formatting.Indented, new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            })));
        }
Beispiel #11
0
        public static List <TTable> FilterEntities(TContext context, FilterEntitiesModel model, IEnumerable <TTable> dataEntities)
        {
            if (model.Link != null)
            {
                TDataBUSFactory         dataBUSFactory  = new TDataBUSFactory();
                BusinessObjectComponent objectComponent = model.BOComponents.FirstOrDefault(bcId => bcId.BusCompId == model.BusComp.Id);

                // Родительская БК и филды
                BusinessComponent parentBusComp = context.BusinessComponents
                                                  .AsNoTracking()
                                                  .Select(bc => new
                {
                    id     = bc.Id,
                    name   = bc.Name,
                    table  = bc.Table,
                    fields = bc.Fields.Select(field => new { id = field.Id, name = field.Name })
                })
                                                  .Select(bc => new BusinessComponent
                {
                    Id     = bc.id,
                    Name   = bc.name,
                    Table  = bc.table,
                    Fields = bc.fields.Select(field => new Field {
                        Id = field.id, Name = field.name
                    }).ToList()
                })
                                                  .FirstOrDefault(i => i.Id == model.Link.ParentBCId);
                Field parentField = parentBusComp.Fields.FirstOrDefault(i => i.Id == model.Link.ParentFieldId);
                Field childField  = model.BusComp.Fields.FirstOrDefault(i => i.Id == model.Link.ChildFieldId);

                // Родительская запись
                var recordId = ComponentsRecordsInfo.GetSelectedRecord(parentBusComp.Name);
                IEnumerable <dynamic> parentRecords = (IEnumerable <dynamic>)(context.GetType().GetProperty(parentBusComp.Table.Name).GetValue(context));
                dynamic parentRecord = parentRecords.FirstOrDefault(i => i.Id.ToString() == recordId);

                // Значение родитеского поля из родительской БКО по которому будет фильтроваться дочерняя(текущая БКО)
                string parentFieldValue = parentRecord == null ? string.Empty : parentRecord.GetType().GetProperty(parentField.Name).GetValue(parentRecord).ToString();

                /* Установка search spec-а по дочерней(текущей) БКО
                 * Если на родительской бк есть записи, надо фильтровать дочернюю бк */
                if (parentFieldValue != string.Empty)
                {
                    string searchSpecificationByParent = $"{childField.Name} = \"{parentFieldValue}\"";
                    ComponentsRecordsInfo.SetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecificationByParent, searchSpecificationByParent);
                    dataEntities = dataEntities.AsQueryable().Where(searchSpecificationByParent).ToList();
                }

                // Если записей нет, значит надо очистить дочернюю бк
                else
                {
                    dataEntities = new List <TTable>();
                }

                return(dataEntities.Take(10).ToList());
            }
            else
            {
                var selectedRecordId = ComponentsRecordsInfo.GetSelectedRecord(model.BusComp.Name);
                if (selectedRecordId != null)
                {
                    return(dataEntities.SkipWhile(i => i.Id.ToString() != selectedRecordId).Take(10).ToList());
                }
                else
                {
                    return(dataEntities.Take(10).ToList());
                }
            }
        }
        public override BUSDataMapObjectComponent UIToBusiness(UIDataMapObjectComponent UIEntity, TContext context, IViewInfo viewInfo, bool isNewRecord)
        {
            BUSDataMapObjectComponent businessEntity = base.UIToBusiness(UIEntity, context, viewInfo, isNewRecord);
            DataMapObject             dataMapObject  = context.DataMapObjects
                                                       .AsNoTracking()
                                                       .Select(mapObject => new
            {
                id   = mapObject.Id,
                name = mapObject.Name,
                sourceBusinessObjectId      = mapObject.SourceBusinessObjectId,
                destinationBusinessObjectId = mapObject.DestinationBusinessObjectId,
                dataMapComponents           = mapObject.DataMapObjectComponents.Select(mapComponent => new
                {
                    id   = mapComponent.Id,
                    name = mapComponent.Name
                })
            })
                                                       .Select(mapObject => new DataMapObject
            {
                Id   = mapObject.id,
                Name = mapObject.name,
                SourceBusinessObjectId      = mapObject.sourceBusinessObjectId,
                DestinationBusinessObjectId = mapObject.destinationBusinessObjectId,
                DataMapObjectComponents     = mapObject.dataMapComponents.Select(mapComponent => new DataMapObjectComponent
                {
                    Id   = mapComponent.id,
                    Name = mapComponent.name
                }).ToList()
            })
                                                       .FirstOrDefault(i => i.Id.ToString() == ComponentsRecordsInfo.GetSelectedRecord("Data Map Object"));

            if (dataMapObject == null)
            {
                businessEntity.ErrorMessage = "First you need create data map object.";
            }
            else
            {
                DataMapObjectComponent mapObjectComponent = dataMapObject?.DataMapObjectComponents.FirstOrDefault(n => n.Name == UIEntity.Name);
                if (dataMapObject?.SourceBusinessObjectId == Guid.Empty)
                {
                    businessEntity.ErrorMessage = $"At first you need to add a source business object to data map object {dataMapObject.Name}.";
                }
                if (dataMapObject?.DestinationBusinessObjectId == Guid.Empty)
                {
                    businessEntity.ErrorMessage = $"At first you need to add a destination business object to data map object {dataMapObject.Name}.";
                }
                else if (mapObjectComponent != null && mapObjectComponent.Id != UIEntity.Id)
                {
                    businessEntity.ErrorMessage = $"Data map component with this name is already exists in data map object {dataMapObject.Name}.";
                }
                else
                {
                    businessEntity.DataMapObject   = dataMapObject;
                    businessEntity.DataMapObjectId = dataMapObject.Id;

                    // SourceBusinessObject
                    BusinessObject sourceBusinessObject = context.BusinessObjects
                                                          .AsNoTracking()
                                                          .Select(bo => new
                    {
                        id = bo.Id,
                        busObjectComponents = bo.BusObjectComponents.Select(boc => new
                        {
                            id      = boc.Id,
                            name    = boc.Name,
                            busComp = new
                            {
                                id   = boc.BusComp.Id,
                                name = boc.BusComp.Name
                            }
                        })
                    })
                                                          .Select(bo => new BusinessObject
                    {
                        Id = bo.id,
                        BusObjectComponents = bo.busObjectComponents.Select(boc => new BusinessObjectComponent
                        {
                            Id      = boc.id,
                            Name    = boc.name,
                            BusComp = new BusinessComponent
                            {
                                Id   = boc.busComp.id,
                                Name = boc.busComp.name
                            }
                        }).ToList()
                    })
                                                          .FirstOrDefault(i => i.Id == dataMapObject.SourceBusinessObjectId);
                    if (sourceBusinessObject != null)
                    {
                        businessEntity.SourceBusinessObject   = sourceBusinessObject;
                        businessEntity.SourceBusinessObjectId = sourceBusinessObject.Id;

                        // SourceBusinessComponent
                        BusinessObjectComponent sourceBOComponent = sourceBusinessObject.BusObjectComponents.FirstOrDefault(n => n.BusComp.Name == UIEntity.SourceBOComponentName);
                        if (sourceBOComponent != null)
                        {
                            businessEntity.SourceBOComponent     = sourceBOComponent;
                            businessEntity.SourceBOComponentId   = sourceBOComponent.Id;
                            businessEntity.SourceBOComponentName = sourceBOComponent.Name;
                            BusinessComponent sourceBusinessComponent = context.BusinessComponents.FirstOrDefault(i => i.Id == sourceBOComponent.BusComp.Id);
                            businessEntity.SourceBusinessComponent   = sourceBusinessComponent;
                            businessEntity.SourceBusinessComponentId = sourceBusinessComponent.Id;
                        }
                    }

                    // DestinationBusinessObject
                    BusinessObject destinationBusinessObject = context.BusinessObjects
                                                               .AsNoTracking()
                                                               .Select(bo => new
                    {
                        id = bo.Id,
                        busObjectComponents = bo.BusObjectComponents.Select(boc => new
                        {
                            id      = boc.Id,
                            name    = boc.Name,
                            busComp = new
                            {
                                id   = boc.BusComp.Id,
                                name = boc.BusComp.Name
                            }
                        })
                    })
                                                               .Select(bo => new BusinessObject
                    {
                        Id = bo.id,
                        BusObjectComponents = bo.busObjectComponents.Select(boc => new BusinessObjectComponent
                        {
                            Id      = boc.id,
                            Name    = boc.name,
                            BusComp = new BusinessComponent
                            {
                                Id   = boc.busComp.id,
                                Name = boc.busComp.name
                            }
                        }).ToList()
                    })
                                                               .FirstOrDefault(i => i.Id == dataMapObject.DestinationBusinessObjectId);
                    if (destinationBusinessObject != null)
                    {
                        businessEntity.DestinationBusinessObject   = destinationBusinessObject;
                        businessEntity.DestinationBusinessObjectId = destinationBusinessObject.Id;

                        // DestinationBusinessComponent
                        BusinessObjectComponent destinationBOComponent = destinationBusinessObject.BusObjectComponents.FirstOrDefault(n => n.BusComp.Name == UIEntity.DestinationBOComponentName);
                        if (destinationBOComponent != null)
                        {
                            businessEntity.DestinationBOComponent     = destinationBOComponent;
                            businessEntity.DestinationBOComponentId   = destinationBOComponent.Id;
                            businessEntity.DestinationBOComponentName = destinationBOComponent.Name;
                            BusinessComponent destinationBusinessComponent = context.BusinessComponents.FirstOrDefault(i => i.Id == destinationBOComponent.BusComp.Id);
                            businessEntity.DestinationBusinessComponent   = destinationBusinessComponent;
                            businessEntity.DestinationBusinessComponentId = destinationBusinessComponent.Id;
                        }
                    }

                    // ParentDataMapComponent
                    DataMapObjectComponent parentDataMapComponent = dataMapObject.DataMapObjectComponents.FirstOrDefault(n => n.Name == UIEntity.ParentDataMapComponentName);
                    if (parentDataMapComponent != null)
                    {
                        businessEntity.ParentDataMapComponent     = parentDataMapComponent;
                        businessEntity.ParentDataMapComponentId   = parentDataMapComponent.Id;
                        businessEntity.ParentDataMapComponentName = parentDataMapComponent.Name;
                    }
                    businessEntity.SourceSearchSpecification = UIEntity.SourceSearchSpecification;
                }
            }
            return(businessEntity);
        }
Beispiel #13
0
        public override BUSBusinessObjectComponent UIToBusiness(UIBusinessObjectComponent UIEntity, TContext context, IViewInfo viewInfo, bool isNewRecord)
        {
            BUSBusinessObjectComponent businessEntity = base.UIToBusiness(UIEntity, context, viewInfo, isNewRecord);
            BusinessObject             busObject      = context.BusinessObjects
                                                        .AsNoTracking()
                                                        .Select(bo => new
            {
                id         = bo.Id,
                name       = bo.Name,
                components = bo.BusObjectComponents.Select(boc => new
                {
                    id   = boc.Id,
                    name = boc.Name
                })
            })
                                                        .Select(bo => new BusinessObject
            {
                Id   = bo.id,
                Name = bo.name,
                BusObjectComponents = bo.components.Select(boc => new BusinessObjectComponent
                {
                    Id   = boc.id,
                    Name = boc.name
                }).ToList()
            })
                                                        .FirstOrDefault(n => n.Id.ToString() == ComponentsRecordsInfo.GetSelectedRecord("Business Object"));

            if (busObject == null)
            {
                businessEntity.ErrorMessage = "First you need create business object.";
            }
            else
            {
                // Если запись новая и она не уникальна, записывается ошибка
                BusinessObjectComponent businessObjectComponent = busObject.BusObjectComponents?.FirstOrDefault(n => n.Name == UIEntity.Name);
                if (businessObjectComponent != null && businessObjectComponent.Id != UIEntity.Id)
                {
                    businessEntity.ErrorMessage = $"Business object component with this name is already exists in business object {busObject.Name}.";
                }
                else
                {
                    // BusObject
                    businessEntity.BusObject     = busObject;
                    businessEntity.BusObjectId   = busObject.Id;
                    businessEntity.BusObjectName = busObject.Name;

                    // BusComp
                    BusinessComponent busComp = context.BusinessComponents.AsNoTracking().FirstOrDefault(n => n.Name == UIEntity.BusCompName);
                    if (busComp != null)
                    {
                        businessEntity.BusComp     = busComp;
                        businessEntity.BusCompId   = busComp.Id;
                        businessEntity.BusCompName = busComp.Name;
                    }

                    // Link
                    Link link = context.Links.AsNoTracking().FirstOrDefault(n => n.Name == UIEntity.LinkName);
                    if (link != null)
                    {
                        businessEntity.Link     = link;
                        businessEntity.LinkId   = link.Id;
                        businessEntity.LinkName = link.Name;
                    }
                }
            }

            return(businessEntity);
        }
Beispiel #14
0
        public override BUSDataMapField UIToBusiness(UIDataMapField UIEntity, TContext context, IViewInfo viewInfo, bool isNewRecord)
        {
            BUSDataMapField        businessEntity   = base.UIToBusiness(UIEntity, context, viewInfo, isNewRecord);
            DataMapObjectComponent dataMapComponent = context.DataMapObjectComponents
                                                      .AsNoTracking()
                                                      .Select(mapComponent => new
            {
                id   = mapComponent.Id,
                name = mapComponent.Name,
                sourceBOComponentId      = mapComponent.SourceBOComponentId,
                destinationBOComponentId = mapComponent.DestinationBOComponentId,
                dataMapFields            = mapComponent.DataMapFields.Select(mapField => new
                {
                    id   = mapField.Id,
                    name = mapField.Name
                })
            })
                                                      .Select(mapComponent => new DataMapObjectComponent
            {
                Id   = mapComponent.id,
                Name = mapComponent.name,
                SourceBOComponentId      = mapComponent.sourceBOComponentId,
                DestinationBOComponentId = mapComponent.destinationBOComponentId,
                DataMapFields            = mapComponent.dataMapFields.Select(mapField => new DataMapField
                {
                    Id   = mapField.id,
                    Name = mapField.name
                }).ToList()
            })
                                                      .FirstOrDefault(i => i.Id.ToString() == ComponentsRecordsInfo.GetSelectedRecord("Data Map Object Component"));

            if (dataMapComponent == null)
            {
                businessEntity.ErrorMessage = "First you need create data map component.";
            }
            else
            {
                DataMapField dataMapField = dataMapComponent?.DataMapFields.FirstOrDefault(n => n.Name == UIEntity.Name);
                if (dataMapComponent?.SourceBOComponentId == Guid.Empty)
                {
                    businessEntity.ErrorMessage = $"At first you need to add a source business component to data map component {dataMapComponent.Name}.";
                }
                if (dataMapComponent?.DestinationBOComponentId == Guid.Empty)
                {
                    businessEntity.ErrorMessage = $"At first you need to add a destination business component to data map component {dataMapComponent.Name}.";
                }
                if (dataMapField != null && dataMapField.Id != UIEntity.Id)
                {
                    businessEntity.ErrorMessage = $"Data map field with this name is already exists in data map component {dataMapComponent.Name}.";
                }
                else
                {
                    businessEntity.DataMapComponent   = dataMapComponent;
                    businessEntity.DataMapComponentId = dataMapComponent.Id;
                    BusinessObjectComponent sourceBOComponent       = context.BusinessObjectComponents.FirstOrDefault(i => i.Id == dataMapComponent.SourceBOComponentId);
                    BusinessComponent       sourceBusinessComponent = context.BusinessComponents
                                                                      .Include(f => f.Fields)
                                                                      .FirstOrDefault(i => i.Id == sourceBOComponent.BusCompId);
                    businessEntity.SourceBusinessComponentId = sourceBusinessComponent.Id;
                    Field sourceField = sourceBusinessComponent.Fields.FirstOrDefault(n => n.Name == UIEntity.SourceFieldName);
                    businessEntity.SourceField     = sourceField;
                    businessEntity.SourceFieldId   = sourceField.Id;
                    businessEntity.SourceFieldName = sourceField.Name;
                    BusinessObjectComponent destinationBOComponentId = context.BusinessObjectComponents.FirstOrDefault(i => i.Id == dataMapComponent.DestinationBOComponentId);
                    businessEntity.DestinationBusinessComponentId = destinationBOComponentId.BusCompId;
                    businessEntity.Destination     = UIEntity.Destination;
                    businessEntity.FieldValidation = UIEntity.FieldValidation;
                }
            }
            return(businessEntity);
        }
Beispiel #15
0
        public ActionResult Drilldown()
        {
            Applet currentApplet = viewInfo.CurrentPopupApplet ?? viewInfo.CurrentApplet;

            currentApplet = context.Applets
                            .AsNoTracking()
                            .Select(a => new
            {
                id      = a.Id,
                name    = a.Name,
                type    = a.Type,
                busComp = new
                {
                    id      = a.BusComp.Id,
                    name    = a.BusComp.Name,
                    routing = a.BusComp.Routing
                },
                drilldowns = a.Drilldowns.Select(d => new
                {
                    id               = d.Id,
                    name             = d.Name,
                    hyperLinkFieldId = d.HyperLinkFieldId,
                    sourceField      = new
                    {
                        id   = d.SourceField.Id,
                        name = d.SourceField.Name
                    },
                    destinationBusinessComponent = new
                    {
                        id      = d.DestinationBusinessComponent.Id,
                        name    = d.DestinationBusinessComponent.Name,
                        routing = d.DestinationBusinessComponent.Routing
                    },
                    destinationField = new
                    {
                        id   = d.DestinationField.Id,
                        name = d.DestinationField.Name
                    },
                    destinationScreenId     = d.DestinationScreenId,
                    destinationScreenItemId = d.DestinationScreenItemId,
                    destinationScreenItem   = new
                    {
                        id   = d.DestinationScreenItem.Id,
                        view = new
                        {
                            id          = d.DestinationScreenItem.View.Id,
                            busObjectId = d.DestinationScreenItem.View.BusObjectId
                        }
                    }
                })
            })
                            .Select(a => new Applet
            {
                Id      = a.id,
                Name    = a.name,
                Type    = a.type,
                BusComp = new BusinessComponent
                {
                    Id      = a.busComp.id,
                    Name    = a.busComp.name,
                    Routing = a.busComp.routing
                },
                Drilldowns = a.drilldowns.Select(d => new Drilldown
                {
                    Id               = d.id,
                    Name             = d.name,
                    HyperLinkFieldId = d.hyperLinkFieldId,
                    SourceField      = new Field
                    {
                        Id   = d.sourceField.id,
                        Name = d.sourceField.name
                    },
                    DestinationBusinessComponent = new BusinessComponent
                    {
                        Id      = d.destinationBusinessComponent.id,
                        Name    = d.destinationBusinessComponent.name,
                        Routing = d.destinationBusinessComponent.routing
                    },
                    DestinationField = new Field
                    {
                        Id   = d.destinationField.id,
                        Name = d.destinationField.name
                    },
                    DestinationScreenId   = d.destinationScreenId,
                    DestinationScreenItem = new ScreenItem
                    {
                        Id   = d.destinationScreenItem.id,
                        View = new View
                        {
                            Id          = d.destinationScreenItem.view.id,
                            BusObjectId = d.destinationScreenItem.view.busObjectId
                        }
                    }
                }).ToList()
            })
                            .FirstOrDefault(i => i.Id == currentApplet.Id);
            if (currentApplet != null)
            {
                string controlName;
                Field  field;
                switch (currentApplet.Type)
                {
                case "Tile":
                    controlName = viewInfo.CurrentColumn.Name;
                    field       = viewInfo.CurrentColumn.Field;
                    break;

                default:
                    controlName = viewInfo.CurrentPopupControl?.Name ?? viewInfo.CurrentControl?.Name;
                    field       = viewInfo.CurrentPopupControl?.Field ?? viewInfo.CurrentControl?.Field;
                    break;
                }
                if (field != null)
                {
                    TBUSFactory BUSFactory = new TBUSFactory();
                    Drilldown   drilldown  = currentApplet.Drilldowns.FirstOrDefault(i => i.HyperLinkFieldId == field.Id);
                    if (drilldown != null && drilldown.DestinationBusinessComponent?.Name != null && drilldown.DestinationField?.Name != null && drilldown.SourceField?.Name != null)
                    {
                        // Целевой экран
                        Screen destinationScreen = context.Screens.AsNoTracking().FirstOrDefault(i => i.Id == drilldown.DestinationScreenId);
                        if (destinationScreen != null)
                        {
                            applicationInfo.CurrentScreen = destinationScreen;

                            // Целевыое представление
                            View destinationView = context.Views.AsNoTracking().FirstOrDefault(i => i.Id == drilldown.DestinationScreenItem.View.Id);
                            if (destinationView != null)
                            {
                                applicationInfo.CurrentView = destinationView;

                                // Исходное поле
                                dynamic      sourceRecord   = BUSFactory.GetRecord(null, context, viewInfo, currentApplet.BusComp, "Id", viewInfo.CurrentRecord);
                                PropertyInfo sourceProperty = sourceRecord.GetType().GetProperty(drilldown.SourceField.Name);
                                if (sourceProperty != null)
                                {
                                    // Очистка старой информации о выбранных записях
                                    if (screenInfo.Screen.Name != destinationScreen.Name)
                                    {
                                        ComponentsRecordsInfo.Dispose();
                                    }

                                    // Установка текущей выбранной записи на целевой бизнес компоненте
                                    var sourcePropertyValue = sourceProperty.GetValue(sourceRecord);
                                    if (sourcePropertyValue != null)
                                    {
                                        dynamic destinationRecord = BUSFactory.GetRecord(null, context, viewInfo, drilldown.DestinationBusinessComponent, drilldown.DestinationField.Name, sourcePropertyValue.ToString());
                                        if (destinationRecord != null)
                                        {
                                            ComponentsRecordsInfo.SetSelectedRecord(drilldown.DestinationBusinessComponent.Name, destinationRecord.Id.ToString());
                                        }

                                        // Установка текущих выбранных записей на всех родительских бизнес компонентах целевой компоненты
                                        BusinessObject destinationBO = context.BusinessObjects
                                                                       .AsNoTracking()
                                                                       .Include(boc => boc.BusObjectComponents)
                                                                       .ThenInclude(l => l.Link)
                                                                       .ThenInclude(cf => cf.ChildField)
                                                                       .Include(boc => boc.BusObjectComponents)
                                                                       .ThenInclude(l => l.Link)
                                                                       .ThenInclude(pf => pf.ParentField)
                                                                       .FirstOrDefault(i => i.Id == destinationView.BusObjectId);
                                        BusinessObjectComponent destinationComponent = destinationBO.BusObjectComponents.FirstOrDefault(i => i.BusCompId == drilldown.DestinationBusinessComponent.Id);
                                        dynamic childRecord = destinationRecord;
                                        if (destinationComponent.Link != null)
                                        {
                                            BusinessComponent parentBusComp = context.BusinessComponents
                                                                              .AsNoTracking()
                                                                              .Select(bc => new
                                            {
                                                id    = bc.Id,
                                                name  = bc.Name,
                                                table = new
                                                {
                                                    id   = bc.Table.Id,
                                                    name = bc.Table.Name
                                                }
                                            })
                                                                              .Select(bc => new BusinessComponent
                                            {
                                                Id    = bc.id,
                                                Name  = bc.name,
                                                Table = new Table
                                                {
                                                    Id   = bc.table.id,
                                                    Name = bc.table.name
                                                }
                                            })
                                                                              .FirstOrDefault(i => i.Id == destinationComponent.Link.ParentBCId);
                                            BusinessComponent childBusComp = context.BusinessComponents
                                                                             .AsNoTracking()
                                                                             .Select(bc => new { id = bc.Id, name = bc.Name })
                                                                             .Select(bc => new BusinessComponent {
                                                Id = bc.id, Name = bc.name
                                            })
                                                                             .FirstOrDefault(i => i.Id == destinationComponent.Link.ChildBCId);
                                            string childFieldValue = childRecord.GetType().GetProperty(destinationComponent.Link.ChildField.Name).GetValue(childRecord).ToString();
                                            string parentFieldName = destinationComponent.Link.ParentField.Name;
                                            IEnumerable <dynamic> parentRecords = (IEnumerable <dynamic>)(context.GetType().GetProperty(parentBusComp.Table.Name).GetValue(context));
                                            string  searchSpecificationByParent = $"{parentFieldName} = \"{childFieldValue}\"";
                                            dynamic parentRecord = parentRecords.AsQueryable().Where(searchSpecificationByParent).FirstOrDefault();
                                            ComponentsRecordsInfo.SetSearchSpecification(childBusComp.Name, SearchSpecTypes.SearchSpecificationByParent, searchSpecificationByParent);
                                            ComponentsRecordsInfo.SetSelectedRecord(parentBusComp.Name, parentRecord.Id.ToString());
                                            destinationComponent = destinationBO.BusObjectComponents.FirstOrDefault(i => i.BusCompId == destinationComponent.Link.ParentBCId);
                                            childRecord          = parentRecord;
                                        }

                                        // Установка хлебных крошек
                                        ScreenItem crumb = screenInfo.Screen.ScreenItems.FirstOrDefault(n => n.View != null && n.View.Name == screenInfo.CurrentView.Name);
                                        ComponentsRecordsInfo.AppendCrumb(crumb);
                                        if (screenInfo.Screen.Name == destinationScreen.Name)
                                        {
                                            screenInfo.Initialize(screenInfo.Screen.Name, destinationView.Name, context);
                                            screenInfoUI.Initialize(screenInfo, context);
                                            viewInfo.View = destinationView;
                                        }
                                        viewInfo.ActionType = ActionType.Drilldown;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(Ok());
        }
Beispiel #16
0
        public ActionResult <object> GetRecords(string appletName)
        {
            // Получение всех необходимых сущностей
            List <BusinessObjectComponent> boComponents = viewInfo.BOComponents;
            Applet            applet  = viewInfo.ViewApplets.FirstOrDefault(n => n.Name == appletName);
            BusinessComponent busComp = context.BusinessComponents
                                        .AsNoTracking()
                                        .Select(bc => new
            {
                id     = bc.Id,
                name   = bc.Name,
                fields = bc.Fields.Select(field => new { id = field.Id, name = field.Name })
            })
                                        .Select(bc => new BusinessComponent
            {
                Id     = bc.id,
                Name   = bc.name,
                Fields = bc.fields.Select(field => new Field {
                    Id = field.id, Name = field.name
                }).ToList()
            })
                                        .FirstOrDefault(i => i.Id == applet.BusCompId);
            BusinessObjectComponent objectComponent = viewInfo.BOComponents.FirstOrDefault(bcId => bcId.BusCompId == busComp.Id);
            ViewItem           viewItem             = viewInfo.ViewItems.Where(apId => apId.AppletId == applet.Id).FirstOrDefault();
            TBUSUIFactory      busUIFactory         = new TBUSUIFactory();
            TDataBUSFactory    dataBUSFactory       = new TDataBUSFactory();
            TBusinessComponent defaultRecord        = new TBusinessComponent();
            List <TTable>      currentRecords       = new List <TTable>();

            // Получение данных
            List <TTable> dataEntities        = orderedEntities.ToList();
            string        searchSpecification = GetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecification);

            object[] searchSpecArgs = (object[])GetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecArgs);
            if (!string.IsNullOrWhiteSpace(searchSpecification))
            {
                dataEntities = orderedEntities.AsQueryable().Where(searchSpecification, searchSpecArgs).ToList();
            }
            List <string> displayRecords   = GetDisplayedRecords(busComp.Name);
            List <string> dataEntitiesId   = dataEntities.Select(i => i?.Id.ToString()).ToList();
            string        selectedRecordId = GetSelectedRecord(busComp.Name);

            // Среди БКО ищу ту, у которой линка не пустая и где дочерней БК является текущая
            Link link = boComponents
                        .Where(link => link.Link != null)
                        .Select(link => link.Link)
                        .FirstOrDefault(bc => bc.ChildBCId == busComp.Id);

            // Есть линка
            if (link != null)
            {
                // Родительская БК и филды
                BusinessComponent parentBusComp = context.BusinessComponents
                                                  .AsNoTracking()
                                                  .Select(bc => new
                {
                    id     = bc.Id,
                    name   = bc.Name,
                    table  = bc.Table,
                    fields = bc.Fields.Select(field => new { id = field.Id, name = field.Name })
                })
                                                  .Select(bc => new BusinessComponent
                {
                    Id     = bc.id,
                    Name   = bc.name,
                    Table  = bc.table,
                    Fields = bc.fields.Select(field => new Field {
                        Id = field.id, Name = field.name
                    }).ToList()
                })
                                                  .FirstOrDefault(i => i.Id == link.ParentBCId);
                Field parentField = parentBusComp.Fields.FirstOrDefault(i => i.Id == link.ParentFieldId);
                Field childField  = busComp.Fields.FirstOrDefault(i => i.Id == link.ChildFieldId);

                // Родительская запись
                var recId = GetSelectedRecord(parentBusComp.Name);
                IEnumerable <dynamic> parentRecords = (IEnumerable <dynamic>)(context.GetType().GetProperty(parentBusComp.Table.Name).GetValue(context));
                dynamic parentRecord = parentRecords.FirstOrDefault(i => i.Id.ToString() == recId);

                // Значение родитеского поля из родительской БКО по которому будет фильтроваться дочерняя(текущая БКО)
                string parentFieldValue = parentRecord == null ? string.Empty
                    : parentRecord.GetType().GetProperty(parentField.Name).GetValue(parentRecord).ToString();

                /* Установка search spec-а по дочерней(текущей) БКО
                 * Если на родительской бк есть записи, надо фильтровать дочернюю бк */
                if (parentFieldValue != string.Empty)
                {
                    string searchSpecificationByParent = $"{childField.Name} = \"{parentFieldValue}\"";
                    SetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecificationByParent, searchSpecificationByParent);
                    dataEntities = dataEntities.AsQueryable().Where(searchSpecificationByParent).ToList();
                }

                // Если записей нет, значит надо очистить дочернюю бк
                else
                {
                    dataEntities = new List <TTable>();
                }
            }

            // В зависимости от действия, произошедшего в представлении
            if (dataEntities.Count > 0)
            {
                defaultRecord = dataBUSFactory.DataToBusiness(dataEntities.ElementAtOrDefault(viewItem.AutofocusRecord), context);
            }
            switch (viewInfo.ActionType)
            {
            // Навигация вперед по списку
            case ActionType.NextRecords:
                if (viewInfo.CurrentApplet?.Name == appletName)
                {
                    // Ищу по id последней записи на тайле
                    TTable lastRecord = dataEntities.FirstOrDefault(i => i.Id.ToString() == displayRecords.LastOrDefault());

                    // Следующие записи
                    dataEntities = dataEntities.SkipWhile(i => i.Id != lastRecord.Id).Take(applet.DisplayLines).ToList();

                    // Если id последней записи в базе совпадает с id последней отоброжаемой записи, значит список долистали до конца
                    if (dataEntities.LastOrDefault().Id == lastRecord.Id)
                    {
                        return(BadRequest());
                    }

                    // Проставление текущей записи
                    var nextRecord = dataEntities.ElementAtOrDefault(viewItem.AutofocusRecord);
                    if (nextRecord != null && nextRecord?.Id != Guid.Empty)
                    {
                        viewInfo.CurrentRecord = nextRecord.Id.ToString();
                        SetSelectedRecord(busComp.Name, nextRecord.Id.ToString());
                        ComponentsContext <TBusinessComponent> .SetComponentContext(busComp.Name, dataBUSFactory.DataToBusiness(nextRecord, context));
                    }
                }
                else
                {
                    SetSelectedRecord(busComp.Name, dataEntitiesId.ElementAtOrDefault(viewItem.AutofocusRecord));
                    ComponentsContext <TBusinessComponent> .SetComponentContext(busComp.Name, defaultRecord);
                }
                break;

            // Навигация назад по списку
            case ActionType.PreviousRecords:
                if (viewInfo.CurrentApplet?.Name == appletName)
                {
                    // Ищу по id первой записи на тайле
                    TTable firstRecord = dataEntities.FirstOrDefault(i => i.Id.ToString() == displayRecords.FirstOrDefault());

                    // Предыдущие записи
                    List <TTable> previousRecords = dataEntities.AsEnumerable().Reverse().SkipWhile(i => i.Id != firstRecord.Id).ToList();
                    if (previousRecords.Count < applet.DisplayLines && dataEntities.Count > applet.DisplayLines)
                    {
                        TTable firstPreviousRecord = previousRecords.AsEnumerable().Reverse().FirstOrDefault();
                        dataEntities = dataEntities.SkipWhile(i => i.Id != firstPreviousRecord.Id).Take(applet.DisplayLines).ToList();
                    }
                    else
                    {
                        dataEntities = previousRecords.Take(applet.DisplayLines).Reverse().ToList();
                    }

                    // Если id первой записи в базе совпадает с id первой отоброжаемой записи, значит список долистали до начала
                    if (dataEntities.FirstOrDefault()?.Id == firstRecord.Id)
                    {
                        return(BadRequest());
                    }

                    // Проставление текущей записи
                    var previousRecord = dataEntities.ElementAtOrDefault(viewItem.AutofocusRecord);
                    if (previousRecord != null && previousRecord?.Id != Guid.Empty)
                    {
                        viewInfo.CurrentRecord = previousRecord.Id.ToString();
                        SetSelectedRecord(busComp.Name, previousRecord.Id.ToString());
                        ComponentsContext <TBusinessComponent> .SetComponentContext(busComp.Name, dataBUSFactory.DataToBusiness(previousRecord, context));
                    }
                }
                else
                {
                    SetSelectedRecord(busComp.Name, dataEntitiesId.ElementAtOrDefault(viewItem.AutofocusRecord));
                    ComponentsContext <TBusinessComponent> .SetComponentContext(busComp.Name, defaultRecord);
                }
                break;

            case ActionType.InitializeView:
                /* Промотка до текущей отоброжаемой записи
                 * Проверяется, что в список с текущими отображаемыми записями не пуст
                 * И что они содержат текущую выбранную запись */
                if (displayRecords?.Count > 0 && dataEntitiesId.IndexOf(selectedRecordId) != -1)
                {
                    displayRecords.ForEach(id => currentRecords.Add(dataEntities.FirstOrDefault(i => i.Id.ToString() == id)));
                    dataEntities = currentRecords;
                }

                else
                {
                    SetSelectedRecord(busComp.Name, dataEntitiesId.ElementAtOrDefault(viewItem.AutofocusRecord));
                    ComponentsContext <TBusinessComponent> .SetComponentContext(busComp.Name, defaultRecord);
                }

                // Установка текущей выбранной записи
                if (viewInfo.CurrentApplet?.Name == appletName)
                {
                    viewInfo.CurrentRecord = GetSelectedRecord(busComp.Name);
                }
                break;

            case ActionType.Drilldown:
                // Промотка до текущей отоброжаемой записи
                if (dataEntities?.Count > 0 && !string.IsNullOrWhiteSpace(selectedRecordId))
                {
                    dataEntities = dataEntities.SkipWhile(i => i.Id.ToString() != selectedRecordId).Take(applet.DisplayLines).ToList();
                }
                break;

            case ActionType.DeleteRecord:
                // Промотка до текущей отоброжаемой записи
                if (displayRecords?.Count > 0 && viewInfo.CurrentApplet?.Name == appletName)
                {
                    displayRecords.ForEach(id => currentRecords.Add(dataEntities.FirstOrDefault(i => i.Id.ToString() == id)));
                    dataEntities = currentRecords;
                }
                else
                {
                    SetSelectedRecord(busComp.Name, dataEntitiesId.ElementAtOrDefault(viewItem.AutofocusRecord));
                    ComponentsContext <TBusinessComponent> .SetComponentContext(busComp.Name, defaultRecord);
                }
                break;

            case ActionType.ReloadView:
            case ActionType.UpdateRecord:
                // Промотка до текущей отоброжаемой записи
                if (displayRecords?.Count > 0)
                {
                    displayRecords.ForEach(id => currentRecords.Add(dataEntities.FirstOrDefault(i => i.Id.ToString() == id)));
                }
                dataEntities = currentRecords;
                break;

            case ActionType.CancelQuery:
                // Промотка до текущей отоброжаемой записи
                if (displayRecords?.Count > 0 && !string.IsNullOrWhiteSpace(selectedRecordId))
                {
                    dataEntities = dataEntities.SkipWhile(i => i.Id.ToString() != selectedRecordId).Take(applet.DisplayLines).ToList();
                }
                break;

            case ActionType.ExecuteQuery:
                if (dataEntities.Count > 0)
                {
                    selectedRecordId = dataEntities.FirstOrDefault().Id.ToString();
                    SetSelectedRecord(busComp.Name, selectedRecordId);
                }
                break;

            case ActionType.NewRecord:
            case ActionType.ShowPopup:
            case ActionType.SelectTileItem:
                if (viewInfo.CurrentApplet?.Name != appletName)
                {
                    SetSelectedRecord(busComp.Name, dataEntitiesId.ElementAtOrDefault(viewItem.AutofocusRecord));
                    ComponentsContext <TBusinessComponent> .SetComponentContext(busComp.Name, defaultRecord);
                }
                break;
            }

            // Установка текущей выбранной записи
            if (GetSelectedRecord(busComp.Name) == null)
            {
                SetSelectedRecord(busComp.Name, dataEntitiesId.ElementAtOrDefault(viewItem.AutofocusRecord));
            }

            if (!ComponentsContext <TBusinessComponent> .TryGetComponentContext(busComp.Name, out TBusinessComponent businessComponent))
            {
                ComponentsContext <TBusinessComponent> .SetComponentContext(busComp.Name, defaultRecord);
            }

            // Установка текущих отоброжаеммых записи
            dataEntities   = dataEntities.Take(applet.DisplayLines).ToList();
            dataEntitiesId = dataEntities.Select(i => i?.Id.ToString()).ToList();
            SetDisplayedRecords(busComp.Name, dataEntitiesId);

            // Маппинг в UI
            List <TApplet> UIEntities = new List <TApplet>();

            dataEntities.ForEach(dataEntity =>
                                 UIEntities.Add(
                                     busUIFactory.BusinessToUI(dataBUSFactory.DataToBusiness(dataEntity, context))
                                     ));

            // Результат с отоброжаемыми и выбранными записями
            Dictionary <string, object> result = new Dictionary <string, object>
            {
                { "SelectedRecords", GetUIRecords(context, viewInfo) },
                { "DisplayedRecords", UIEntities }
            };

            // Обнуление действия после полного обновления представления(обновления последнего апплета)
            if (viewInfo.AppletsSortedByLinks.LastOrDefault()?.Id == applet.Id)
            {
                viewInfo.EndInitialize();
            }

            return(Ok(new JsonResult(result).Value));
        }
        public void StartInitialize <TContext>(IViewInfo oldViewInfo, string viewName, TContext context)
            where TContext : MainContext, new()
        {
            // Инициализация списков
            ViewBCs              = new List <BusinessComponent>();
            ViewApplets          = new List <Applet>();
            AppletsSortedByLinks = oldViewInfo == null ? new List <Applet>() : oldViewInfo.AppletsSortedByLinks;
            ViewItems            = new List <ViewItem>();
            BOComponents         = new List <BusinessObjectComponent>();

            if (ActionType != ActionType.Drilldown)
            {
                ActionType = ActionType.InitializeView;
            }

            // Получение представления
            View = context.Views
                   .AsNoTracking()
                   .Select(v => new
            {
                id          = v.Id,
                name        = v.Name,
                busObjectId = v.BusObjectId,
                viewItems   = v.ViewItems.Select(vi => new
                {
                    id       = vi.Id,
                    name     = vi.Name,
                    sequence = vi.Sequence,
                    appletId = vi.AppletId,
                    applet   = vi.Applet == null ? null : new
                    {
                        id        = vi.Applet.Id,
                        name      = vi.Applet.Name,
                        busCompId = vi.Applet.BusCompId
                    }
                })
            })
                   .Select(v => new View
            {
                Id          = v.id,
                Name        = v.name,
                BusObjectId = v.busObjectId,
                ViewItems   = v.viewItems.Select(vi => new ViewItem
                {
                    Id       = vi.id,
                    Name     = vi.name,
                    Sequence = vi.sequence,
                    AppletId = vi.appletId,
                    Applet   = vi.applet == null ? null : new Applet
                    {
                        Id        = vi.applet.id,
                        Name      = vi.applet.name,
                        BusCompId = vi.applet.busCompId
                    }
                }).ToList()
            })
                   .FirstOrDefault(n => n.Name == viewName);

            // Получение списка элементов представления
            ViewItems = View.ViewItems.OrderBy(s => s.Sequence).ToList();

            // Получение бизнес объекта, на котором основано представление
            ViewBO = context.BusinessObjects
                     .AsNoTracking()
                     .Select(bo => new
            {
                id           = bo.Id,
                name         = bo.Name,
                boComponents = bo.BusObjectComponents.Select(boc => new
                {
                    id        = boc.Id,
                    name      = boc.Name,
                    busCompId = boc.BusCompId,
                    busComp   = boc.BusComp == null ? null : new
                    {
                        id   = boc.BusComp.Id,
                        name = boc.BusComp.Name
                    },
                    linkId = boc.LinkId,
                    link   = boc.Link == null ? null : new
                    {
                        id            = boc.Link.Id,
                        name          = boc.Link.Name,
                        parentBCId    = boc.Link.ParentBCId,
                        parentFieldId = boc.Link.ParentFieldId,
                        childBCId     = boc.Link.ChildBCId,
                        childFieldId  = boc.Link.ChildFieldId
                    }
                })
            })
                     .Select(bo => new BusinessObject
            {
                Id   = bo.id,
                Name = bo.name,
                BusObjectComponents = bo.boComponents.Select(boc => new BusinessObjectComponent
                {
                    Id        = boc.id,
                    Name      = boc.name,
                    BusCompId = boc.busCompId,
                    BusComp   = boc.busComp == null ? null : new BusinessComponent
                    {
                        Id   = boc.busComp.id,
                        Name = boc.busComp.name
                    },
                    LinkId = boc.linkId,
                    Link   = boc.link == null ? null : new Link
                    {
                        Id            = boc.link.id,
                        Name          = boc.link.name,
                        ParentBCId    = boc.link.parentBCId,
                        ParentFieldId = boc.link.parentFieldId,
                        ChildBCId     = boc.link.childBCId,
                        ChildFieldId  = boc.link.childFieldId
                    }
                }).ToList()
            })
                     .FirstOrDefault(i => i.Id == View.BusObjectId);

            // Заполнение списков с апплетами, бизнес компонентами и маршрутизацией
            ViewItems.ForEach(viewItem =>
            {
                // Получение апплета для каждого элемента представления
                Applet applet = context.Applets
                                .AsNoTracking()
                                .Include(b => b.BusComp)
                                .Include(col => col.Columns)
                                .ThenInclude(f => f.Field)
                                .Include(cntr => cntr.Controls)
                                .ThenInclude(cnUp => cnUp.ControlUPs)
                                .Include(cntr => cntr.Controls)
                                .ThenInclude(f => f.Field)
                                .FirstOrDefault(i => i.Id == viewItem.AppletId);

                // Добавление апплета и его бизнес компоненты в список
                if (ViewApplets.IndexOf(applet) == -1)
                {
                    ViewApplets.Add(applet);
                }

                if (applet.BusComp != null)
                {
                    BusinessObjectComponent component = ViewBO.BusObjectComponents.FirstOrDefault(i => i.BusCompId == applet.BusCompId);
                    if (ViewBCs.IndexOf(applet.BusComp) == -1)
                    {
                        ViewBCs.Add(applet.BusComp);
                    }
                    if (BOComponents.IndexOf(component) == -1)
                    {
                        BOComponents.Add(component);
                    }
                }
            });

            CurrentApplet = ViewApplets.FirstOrDefault();
            CurrentRecord = GetSelectedRecord(ViewBCs.FirstOrDefault(i => i.Id == CurrentApplet?.BusCompId)?.Name);

            /*BOComponents.ForEach(objectComponent =>
             * {
             *  objectComponent.SearchSpecArgs = GetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecArgs);
             *  objectComponent.SearchSpecification = GetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecification);
             *  objectComponent.SearchSpecificationByParent = GetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecificationByParent);
             * });*/
        }
Beispiel #18
0
        public virtual ActionResult <string> UpdateContext()
        {
            // Список проверенных бк, список с верхними в иерархии бк и список с апплетами для обновления
            List <Applet> appletsToUpdate = new List <Applet>();
            List <BusinessObjectComponent> topComponents = new List <BusinessObjectComponent>();

            viewInfo.AppletsSortedByLinks.Clear();

            // Необходимо выбрать те компоненты, у которых нет связей, либо те, которые являются верхними в иерархии
            viewInfo.BOComponents.ForEach(component =>
            {
                // Если у компоненты нет линки, то она добавляется в список верхних в иерархии
                if (component.Link == null)
                {
                    topComponents.Add(component);
                }

                // Иначе находится ее родительская компонента из связи
                else
                {
                    BusinessObjectComponent parentComponent = viewInfo.BOComponents.FirstOrDefault(i => i.BusCompId == component.Link.ParentBCId);

                    // Если родительской бк нет в представлении, текущая компонента добавляется в список верхних в иерархии
                    if (parentComponent == null)
                    {
                        topComponents.Add(component);
                    }

                    // Иначе до тех пор пока по связям можно подниматься наверх в списке бк текущего представления
                    else
                    {
                        while (viewInfo.BOComponents.IndexOf(parentComponent) != -1)
                        {
                            // Если у родительской компоненты нет ссылки она добавляется в список верхних в иерархии
                            if (parentComponent.Link == null)
                            {
                                if (topComponents.IndexOf(parentComponent) == -1)
                                {
                                    topComponents.Add(parentComponent);
                                }
                                break;
                            }

                            // Иначе компонента становится равной родительской компоненте из линки
                            parentComponent = viewInfo.BOComponents.FirstOrDefault(i => i.BusCompId == parentComponent.Link.ParentBCId);
                        }
                    }
                }
            });

            /* Для каждой компоненты, верхней в иерархии, запускается формирование списка апплетов, необходимых для обновления
             * И для всех компонент, отсутствующих в представлении, но являющихся верхними в иерархии для списка topComponents необходимо установить контекст */
            topComponents.ForEach(component =>
            {
                List <BusinessObjectComponent> boComponents     = viewInfo.ViewBO.BusObjectComponents;
                List <BusinessObjectComponent> parentComponents = new List <BusinessObjectComponent>();
                if (component.Link != null)
                {
                    BusinessObjectComponent parentComponent = boComponents.FirstOrDefault(i => i.BusCompId == component.Link.ParentBCId);
                    parentComponents.Add(parentComponent);
                    while (parentComponent?.Link != null)
                    {
                        parentComponent = boComponents.FirstOrDefault(i => i.BusCompId == parentComponent.Link.ParentBCId);
                        parentComponents.Add(parentComponent);
                    }

                    parentComponents.AsEnumerable().Reverse().ToList().ForEach(item =>
                    {
                        BusinessComponent busComp = context.BusinessComponents
                                                    .Include(f => f.Fields)
                                                    .FirstOrDefault(i => i.Id == item.BusCompId);

                        TBUSFactory busFactory = new TBUSFactory();
                        if (!ComponentsRecordsInfo.IsInitComponent(busComp.Name))
                        {
                            busFactory.InitializeComponentsRecords(null, context, viewInfo, new FilterEntitiesModel()
                            {
                                BOComponents = boComponents,
                                Link         = item.Link,
                                BusComp      = busComp
                            });
                        }
                    });
                }
                // Добавление всех апплетов не являющихся попапами в список для обновления
                viewInfo.ViewApplets.ForEach(viewApplet =>
                {
                    if (viewApplet.Type != "Popup")
                    {
                        appletsToUpdate.Add(viewApplet);
                    }
                });
                viewInfo.AppletsSortedByLinks.AddRange(AppletListBuilding(new List <BusinessObjectComponent>(), component, component, appletsToUpdate));
            });

            return(Ok());
        }
Beispiel #19
0
        public ActionResult <object> DeleteRecord([FromBody] RequestAppletModel model)
        {
            // Получение всех необходимых сущностей
            List <BusinessObjectComponent> boComponents = viewInfo.BOComponents;
            Applet                  applet          = viewInfo.ViewApplets.FirstOrDefault(n => n.Name == model.AppletName);
            BusinessComponent       busComp         = viewInfo.ViewBCs.FirstOrDefault(i => i.Id == applet.BusCompId);
            BusinessObjectComponent objectComponent = boComponents.FirstOrDefault(bcId => bcId.BusCompId == busComp.Id);

            object[] searchSpecArgs              = (object[])GetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecArgs);
            string   searchSpecification         = GetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecification);
            string   searchSpecificationByParent = GetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecificationByParent);

            // Получение контекста
            IEnumerable <TTable> dataEntities = orderedEntities;

            // Ограничение списка сущностей
            if (searchSpecification != null)
            {
                dataEntities = dataEntities.AsQueryable().Where(searchSpecification, searchSpecArgs).ToList();
            }
            if (searchSpecificationByParent != null)
            {
                dataEntities = dataEntities.AsQueryable().Where(searchSpecificationByParent).ToList();
            }

            // Получение записи предназначенной для удаления
            TTable recordToDelete = dataEntities.FirstOrDefault(i => i.Id == model.Id);

            if (recordToDelete == null)
            {
                return(NotFound());
            }
            else
            {
                // Удаление записи из списка отоброжаемых
                List <string> displayRecords = GetDisplayedRecords(busComp.Name);
                displayRecords.Remove(recordToDelete.Id.ToString());
                SetDisplayedRecords(busComp.Name, displayRecords);

                // Получение следующей за этой записи
                TTable nextEntity = dataEntities.SkipWhile(item => !item.Equals(recordToDelete)).Skip(1).FirstOrDefault();

                // Если ее не найдено, получение предыдущей
                if (nextEntity == null)
                {
                    nextEntity = dataEntities.TakeWhile(item => !item.Equals(recordToDelete)).LastOrDefault();
                }

                // Удаление выбранной записи
                TDataBUSFactory dataBUSFactory = new TDataBUSFactory();
                TBUSUIFactory   busUIFactory   = new TBUSUIFactory();
                dataBUSFactory.OnRecordDelete(recordToDelete, entityDBSet, context);

                // Обязательно необходимо перекверить данные после удаления
                dataEntities = orderedEntities;

                // Ограничение списка сущностей
                if (searchSpecArgs != null)
                {
                    dataEntities = dataEntities.AsQueryable().Where(searchSpecification, searchSpecArgs).ToList();
                }
                if (searchSpecificationByParent != null)
                {
                    dataEntities = dataEntities.AsQueryable().Where(searchSpecificationByParent).ToList();
                }

                // Если запись для фокуса найдена, то она добавляется в список отоброжаемых и возвращается
                if (nextEntity != null)
                {
                    // Пропуск текущих отоброжаемых записей и взятие слеующей
                    var record = dataEntities
                                 .SkipWhile(i => i.Id.ToString() != displayRecords.LastOrDefault())
                                 .Skip(1).FirstOrDefault();

                    // Если следущая запись есть и она не является удаляемой, то она добавляется в список отоброжаемых и возвращается
                    if (record != null && record.Id != recordToDelete.Id)
                    {
                        displayRecords.Add(record.Id.ToString());
                    }

                    SetDisplayedRecords(busComp.Name, displayRecords);

                    return(Ok(new JsonResult(busUIFactory.BusinessToUI(dataBUSFactory.DataToBusiness(nextEntity, context))).Value));
                }
                else
                {
                    return(Ok(new JsonResult(null).Value));
                }
            }
        }
Beispiel #20
0
        // Проходится по бк, формируя список апплетов для обновления
        private List <Applet> AppletListBuilding(List <BusinessObjectComponent> checkedComponents, BusinessObjectComponent masterBusComp, BusinessObjectComponent currentBusComp, List <Applet> appletsToUpdate)
        {
            // Формирование списка дочерних бк
            List <BusinessObjectComponent> childComponents = new List <BusinessObjectComponent>();

            viewInfo
            .BOComponents
            .Except(checkedComponents)
            .ToList()
            .ForEach(component =>
            {
                // Связь
                Link link = context.Links.FirstOrDefault(i => i.Id == component.LinkId);

                // Если у связи в БКО Id родительской компоненты совпадает с id текущей, добавляю эту БКО в список дочерних
                if (link != null && link.ParentBCId == currentBusComp.BusCompId)
                {
                    childComponents.Add(component);
                }
            });

            // До тех пор, пока есть дочерние компоненты
            while (childComponents.Count > 0)
            {
                // Получение всех необходимых сущностей
                BusinessObjectComponent component = childComponents.FirstOrDefault();
                Applet applet = viewInfo.ViewApplets
                                .Where(bcId => bcId.BusCompId == component.BusCompId)
                                .Where(type => type.Type != "Popup")
                                .FirstOrDefault();

                // Если в списке апплетов для обновления нет текущего, его надо добавить
                if (!appletsToUpdate.Contains(applet))
                {
                    appletsToUpdate.Add(applet);
                }

                // Добавление всех апплетов, основанных на той же компоненте и не являющихся попапми в список для обновления
                viewInfo.ViewApplets.ForEach(viewApplet =>
                {
                    if (viewApplet.BusCompId == applet.BusCompId && viewApplet.Id != applet.Id &&
                        viewApplet.Type != "Popup" && !appletsToUpdate.Contains(viewApplet))
                    {
                        appletsToUpdate.Add(viewApplet);
                    }
                });

                // Запустить заново
                return(AppletListBuilding(checkedComponents, masterBusComp, component, appletsToUpdate));
            }

            // Если дочерних не осталось, значит дошли до низа иерархии, либо связи изначально отсутствовали
            if (masterBusComp != currentBusComp)
            {
                // Добавляю бк в список проверенных, делаю текущей бк верхнюю, запускаю заново
                checkedComponents.Add(currentBusComp);
                return(AppletListBuilding(checkedComponents, masterBusComp, masterBusComp, appletsToUpdate));
            }

            else
            {
                if (appletsToUpdate.Count > 0)
                {
                    List <Applet>     sortedApplets     = new List <Applet>();
                    List <Applet>     formApplets       = new List <Applet>();
                    BusinessComponent businessComponent = appletsToUpdate.FirstOrDefault().BusComp;
                    appletsToUpdate.ForEach(applet =>
                    {
                        if (businessComponent.Id == applet.BusCompId)
                        {
                            if (applet.Type == "Tile")
                            {
                                sortedApplets.Add(applet);
                            }
                            else
                            {
                                formApplets.Add(applet);
                            }
                        }
                        else
                        {
                            businessComponent = applet.BusComp;
                            sortedApplets.AddRange(formApplets);
                            formApplets.Clear();
                            if (applet.Type == "Tile")
                            {
                                sortedApplets.Add(applet);
                            }
                            else
                            {
                                formApplets.Add(applet);
                            }
                        }
                    });
                    sortedApplets.AddRange(formApplets);
                    return(sortedApplets);
                }
                else
                {
                    return(appletsToUpdate);
                }
            }
        }
Beispiel #21
0
        public override BUSDataMapObjectComponent DataToBusiness(DataMapObjectComponent dataEntity, TContext context)
        {
            BUSDataMapObjectComponent businessEntity = base.DataToBusiness(dataEntity, context);
            DataMapObject             dataMapObject  = context.DataMapObjects
                                                       .AsNoTracking()
                                                       .Select(mapObject => new
            {
                id   = mapObject.Id,
                name = mapObject.Name,
                sourceBusinessObjectId      = mapObject.SourceBusinessObjectId,
                destinationBusinessObjectId = mapObject.DestinationBusinessObjectId,
                dataMapComponents           = mapObject.DataMapObjectComponents.Select(mapComponent => new
                {
                    id   = mapComponent.Id,
                    name = mapComponent.Name
                })
            })
                                                       .Select(mapObject => new DataMapObject
            {
                Id   = mapObject.id,
                Name = mapObject.name,
                SourceBusinessObjectId      = mapObject.sourceBusinessObjectId,
                DestinationBusinessObjectId = mapObject.destinationBusinessObjectId,
                DataMapObjectComponents     = mapObject.dataMapComponents.Select(mapComponent => new DataMapObjectComponent
                {
                    Id   = mapComponent.id,
                    Name = mapComponent.name
                }).ToList()
            })
                                                       .FirstOrDefault(i => i.Id == dataEntity.DataMapObjectId);

            businessEntity.DataMapObject   = dataMapObject;
            businessEntity.DataMapObjectId = dataMapObject.Id;

            // SourceBusinessObject
            BusinessObject sourceBusinessObject = context.BusinessObjects
                                                  .Select(bo => new
            {
                id = bo.Id,
                busObjectComponents = bo.BusObjectComponents.Select(boc => new
                {
                    id        = boc.Id,
                    busCompId = boc.BusCompId,
                    name      = boc.Name
                })
            })
                                                  .Select(bo => new BusinessObject
            {
                Id = bo.id,
                BusObjectComponents = bo.busObjectComponents.Select(boc => new BusinessObjectComponent
                {
                    Id        = boc.id,
                    BusCompId = boc.busCompId,
                    Name      = boc.name
                }).ToList()
            })
                                                  .FirstOrDefault(i => i.Id == dataMapObject.SourceBusinessObjectId);

            if (sourceBusinessObject != null)
            {
                businessEntity.SourceBusinessObject   = sourceBusinessObject;
                businessEntity.SourceBusinessObjectId = sourceBusinessObject.Id;
            }

            // SourceBusinessComponent
            BusinessObjectComponent sourceBOComponent = sourceBusinessObject.BusObjectComponents.FirstOrDefault(i => i.Id == dataEntity.SourceBOComponentId);

            if (sourceBOComponent != null)
            {
                businessEntity.SourceBOComponent     = sourceBOComponent;
                businessEntity.SourceBOComponentId   = sourceBOComponent.Id;
                businessEntity.SourceBOComponentName = sourceBOComponent.Name;
                BusinessComponent sourceBusinessComponent = context.BusinessComponents.FirstOrDefault(i => i.Id == sourceBOComponent.BusCompId);
                businessEntity.SourceBusinessComponent   = sourceBusinessComponent;
                businessEntity.SourceBusinessComponentId = sourceBusinessComponent.Id;
            }

            // DestinationBusinessObject
            BusinessObject destinationBusinessObject = context.BusinessObjects
                                                       .Select(bo => new
            {
                id = bo.Id,
                busObjectComponents = bo.BusObjectComponents.Select(boc => new
                {
                    id        = boc.Id,
                    busCompId = boc.BusCompId,
                    name      = boc.Name
                })
            })
                                                       .Select(bo => new BusinessObject
            {
                Id = bo.id,
                BusObjectComponents = bo.busObjectComponents.Select(boc => new BusinessObjectComponent
                {
                    Id        = boc.id,
                    BusCompId = boc.busCompId,
                    Name      = boc.name
                }).ToList()
            })
                                                       .FirstOrDefault(i => i.Id == dataMapObject.DestinationBusinessObjectId);

            if (destinationBusinessObject != null)
            {
                businessEntity.DestinationBusinessObject   = destinationBusinessObject;
                businessEntity.DestinationBusinessObjectId = destinationBusinessObject.Id;
            }

            // DestinationBusinessComponent
            BusinessObjectComponent destinationBOComponent = destinationBusinessObject.BusObjectComponents.FirstOrDefault(i => i.Id == dataEntity.DestinationBOComponentId);

            if (destinationBOComponent != null)
            {
                businessEntity.DestinationBOComponent     = destinationBOComponent;
                businessEntity.DestinationBOComponentId   = destinationBOComponent.Id;
                businessEntity.DestinationBOComponentName = destinationBOComponent.Name;
                BusinessComponent destinationBusinessComponent = context.BusinessComponents.FirstOrDefault(i => i.Id == destinationBOComponent.BusCompId);
                businessEntity.DestinationBusinessComponent   = destinationBusinessComponent;
                businessEntity.DestinationBusinessComponentId = destinationBusinessComponent.Id;
            }

            // ParentDataMapComponent
            DataMapObjectComponent parentDataMapComponent = dataMapObject.DataMapObjectComponents.FirstOrDefault(i => i.Id == dataEntity.ParentDataMapComponentId);

            if (parentDataMapComponent != null)
            {
                businessEntity.ParentDataMapComponent     = parentDataMapComponent;
                businessEntity.ParentDataMapComponentId   = parentDataMapComponent.Id;
                businessEntity.ParentDataMapComponentName = parentDataMapComponent.Name;
            }

            businessEntity.SourceSearchSpecification = dataEntity.SourceSearchSpecification;
            return(businessEntity);
        }