コード例 #1
0
        public override BUSDataMapObjectComponent Init(TContext context)
        {
            BUSDataMapObjectComponent businessEntity = base.Init(context);
            DataMapObject             dataMapObject  = context.DataMapObjects
                                                       .AsNoTracking()
                                                       .Select(mapObject => new
            {
                id = mapObject.Id,
                sourceBusinessObjectId      = mapObject.SourceBusinessObjectId,
                destinationBusinessObjectId = mapObject.DestinationBusinessObjectId
            })
                                                       .Select(mapObject => new DataMapObject
            {
                Id = mapObject.id,
                SourceBusinessObjectId      = mapObject.sourceBusinessObjectId,
                DestinationBusinessObjectId = mapObject.destinationBusinessObjectId
            })
                                                       .FirstOrDefault(i => i.Id.ToString() == ComponentsRecordsInfo.GetSelectedRecord("Data Map Object"));

            if (dataMapObject != null)
            {
                businessEntity.DataMapObject               = dataMapObject;
                businessEntity.DataMapObjectId             = dataMapObject.Id;
                businessEntity.SourceBusinessObjectId      = dataMapObject.SourceBusinessObjectId;
                businessEntity.DestinationBusinessObjectId = dataMapObject.DestinationBusinessObjectId;
            }
            return(businessEntity);
        }
コード例 #2
0
        public override DataMapObject BusinessToData(DataMapObject dataMapObject, BUSDataMapObject businessEntity, TContext context, bool NewRecord)
        {
            DataMapObject dataEntity = base.BusinessToData(dataMapObject, businessEntity, context, NewRecord);

            dataEntity.DataMap                     = businessEntity.DataMap;
            dataEntity.DataMapId                   = businessEntity.DataMapId;
            dataEntity.SourceBusinessObject        = businessEntity.SourceBusinessObject;
            dataEntity.SourceBusinessObjectId      = businessEntity.SourceBusinessObjectId;
            dataEntity.DestinationBusinessObject   = businessEntity.DestinationBusinessObject;
            dataEntity.DestinationBusinessObjectId = businessEntity.DestinationBusinessObjectId;
            return(dataEntity);
        }
コード例 #3
0
        public static async Task <int> UpdateAsync(this DataMapObject mapObject)
        {
            var selectQuery = "SELECT * FROM " + mapObject.TableName + " WHERE " + mapObject.GetAttribute(nameof(mapObject.Guid)).ColumnName + " = '" + mapObject.Guid + "'";

            using (var results = await DBFactory.GetMySqlDatabase().DataTableFromQueryStringAsync(selectQuery))
            {
                results.Rows[0][Tables.Extensions.ModifyUser] = Security.SecurityFunctions.LocalUser.UserName;

                PopulateRowFromObject(results.Rows[0], mapObject);
                return(await DBFactory.GetMySqlDatabase().UpdateTableAsync(selectQuery, results));
            }
        }
コード例 #4
0
        public static DataColumnNameAttribute GetAttribute(this DataMapObject source, string properyName)
        {
            var prop = source.GetType().GetProperty(properyName);

            if (prop == null)
            {
                return(null);
            }

            var attr = prop.GetCustomAttribute <DataColumnNameAttribute>(true);

            return(attr);
        }
コード例 #5
0
        public static async Task <int> InsertAsync(this DataMapObject mapObject)
        {
            var selectQuery = "SELECT * FROM " + mapObject.TableName + " LIMIT 0";

            using (var results = await DBFactory.GetMySqlDatabase().DataTableFromQueryStringAsync(selectQuery))
            {
                var newRow = results.Rows.Add();
                newRow[Tables.Extensions.ModifyUser] = Security.SecurityFunctions.LocalUser.UserName;
                PopulateRowFromObject(newRow, mapObject);

                return(await DBFactory.GetMySqlDatabase().UpdateTableAsync(selectQuery, results));
            }
        }
コード例 #6
0
        public override BUSDataMapObject DataToBusiness(DataMapObject dataEntity, TContext context)
        {
            BUSDataMapObject businessEntity       = base.DataToBusiness(dataEntity, context);
            BusinessObject   sourceBusinessObject = context.BusinessObjects.AsNoTracking().FirstOrDefault(i => i.Id == dataEntity.SourceBusinessObjectId);

            if (sourceBusinessObject != null)
            {
                businessEntity.SourceBusinessObject     = sourceBusinessObject;
                businessEntity.SourceBusinessObjectId   = sourceBusinessObject.Id;
                businessEntity.SourceBusinessObjectName = sourceBusinessObject.Name;
            }
            BusinessObject destinationBusinessObject = context.BusinessObjects.AsNoTracking().FirstOrDefault(i => i.Id == dataEntity.DestinationBusinessObjectId);

            if (destinationBusinessObject != null)
            {
                businessEntity.DestinationBusinessObject     = destinationBusinessObject;
                businessEntity.DestinationBusinessObjectId   = destinationBusinessObject.Id;
                businessEntity.DestinationBusinessObjectName = destinationBusinessObject.Name;
            }
            return(businessEntity);
        }
コード例 #7
0
        public override BUSDataMapObject UIToBusiness(UIDataMapObject UIEntity, TContext context, IViewInfo viewInfo, bool isNewRecord)
        {
            BUSDataMapObject businessEntity = base.UIToBusiness(UIEntity, context, viewInfo, isNewRecord);
            DataMap          dataMap        = context.DataMaps
                                              .Select(map => new
            {
                id             = map.Id,
                name           = map.Name,
                dataMapObjects = map.DataMapObjects.Select(mapObject => new
                {
                    id   = mapObject.Id,
                    name = mapObject.Name
                })
            })
                                              .Select(map => new DataMap
            {
                Id             = map.id,
                Name           = map.name,
                DataMapObjects = map.dataMapObjects.Select(mapObject => new DataMapObject
                {
                    Id   = mapObject.id,
                    Name = mapObject.name
                }).ToList()
            })
                                              .FirstOrDefault(i => i.Id.ToString() == ComponentsRecordsInfo.GetSelectedRecord("Data Map"));

            if (dataMap == null)
            {
                businessEntity.ErrorMessage = "First you need create data map.";
            }
            else
            {
                // Если запись новая и она не уникальна, записывается ошибка
                DataMapObject dataMapObject = dataMap.DataMapObjects?.FirstOrDefault(n => n.Name == UIEntity.Name);
                if (dataMapObject != null && dataMapObject.Id != UIEntity.Id)
                {
                    businessEntity.ErrorMessage = $"Data map object with this name is already exists in data map {businessEntity.DataMap.Name}.";
                }
                else
                {
                    businessEntity.DataMap   = dataMap;
                    businessEntity.DataMapId = dataMap.Id;

                    // SourceBusinessObject
                    BusinessObject sourceBusinessObject = context.BusinessObjects.AsNoTracking().FirstOrDefault(n => n.Name == UIEntity.SourceBusinessObjectName);
                    if (sourceBusinessObject != null)
                    {
                        businessEntity.SourceBusinessObject     = sourceBusinessObject;
                        businessEntity.SourceBusinessObjectId   = sourceBusinessObject.Id;
                        businessEntity.SourceBusinessObjectName = sourceBusinessObject.Name;
                    }

                    // DestinationBusinessObject
                    BusinessObject destinationBusinessObject = context.BusinessObjects.AsNoTracking().FirstOrDefault(n => n.Name == UIEntity.DestinationBusinessObjectName);
                    if (destinationBusinessObject != null)
                    {
                        businessEntity.DestinationBusinessObject     = destinationBusinessObject;
                        businessEntity.DestinationBusinessObjectId   = destinationBusinessObject.Id;
                        businessEntity.DestinationBusinessObjectName = destinationBusinessObject.Name;
                    }
                }
            }
            return(businessEntity);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
ファイル: Queries.cs プロジェクト: Bobbar/PhoneDirectoryWPF
 public static string DeleteMapObject(DataMapObject mapObject)
 {
     return(string.Format("DELETE FROM {0} WHERE {1} ='{2}'", mapObject.TableName, mapObject.GetAttribute(nameof(mapObject.Guid)).ColumnName, mapObject.Guid));
 }
コード例 #10
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);
        }