public override BUSApplet DataToBusiness(Applet dataEntity, TContext context)
        {
            BUSApplet      businessEntity = base.DataToBusiness(dataEntity, context);
            PhysicalRender physicalRender = context.PhysicalRenders.AsNoTracking().FirstOrDefault(i => i.Id == dataEntity.PhysicalRenderId);

            if (physicalRender != null)
            {
                businessEntity.PhysicalRender     = physicalRender;
                businessEntity.PhysicalRenderId   = physicalRender.Id;
                businessEntity.PhysicalRenderName = physicalRender.Name;
            }
            BusinessComponent busComp = context.BusinessComponents.AsNoTracking().FirstOrDefault(i => i.Id == dataEntity.BusCompId);

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

            businessEntity.Virtual      = dataEntity.Virtual;
            businessEntity.Header       = dataEntity.Header;
            businessEntity.Type         = dataEntity.Type;
            businessEntity.EmptyState   = dataEntity.EmptyState;
            businessEntity.DisplayLines = dataEntity.DisplayLines;
            businessEntity.Initflag     = dataEntity.Initflag;
            return(businessEntity);
        }
        public override void OnRecordDelete(Applet recordToDelete, DbSet <Applet> entities, TContext context)
        {
            string permissibleName = GetPermissibleName(recordToDelete.Name);

            if (EntityFileExists(permissibleName, "Applet"))
            {
                DeleteEntityFile(permissibleName, "Applet");
                DeleteEntityFile(EntitiesConfig.UIFR + permissibleName + "FR", "BUSUIFactory");
                DeleteEntityFile(permissibleName + "Controller", "AppletController");
            }
            base.OnRecordDelete(recordToDelete, entities, context);
        }
        public override Applet BusinessToData(Applet applet, BUSApplet businessEntity, TContext context, bool NewRecord)
        {
            Applet dataEntity = base.BusinessToData(applet, businessEntity, context, NewRecord);

            dataEntity.Header           = businessEntity.Header;
            dataEntity.Type             = businessEntity.Type;
            dataEntity.Initflag         = businessEntity.Initflag;
            dataEntity.EmptyState       = businessEntity.EmptyState;
            dataEntity.PhysicalRenderId = businessEntity.PhysicalRenderId;
            dataEntity.DisplayLines     = businessEntity.DisplayLines;
            dataEntity.BusCompId        = businessEntity.BusCompId;
            dataEntity.Routing          = "/api/" + GetPermissibleName(businessEntity.Name) + "/";
            dataEntity.Virtual          = businessEntity.Virtual;
            return(dataEntity);
        }
Ejemplo n.º 4
0
        public static void GenerateModel(MainContext context, Type entityType, Guid recordId)
        {
            SyntaxTree syntaxTree;
            string     entityName = string.Empty;
            IEnumerable <MemberDeclarationSyntax> members = new List <MemberDeclarationSyntax>();

            switch (entityType.Name)
            {
            case "Table":
                Table table = context.Tables
                              .AsNoTracking()
                              .Include(tc => tc.TableColumns)
                              .FirstOrDefault(i => i.Id == recordId);
                entityName = table.Name;
                members    = CreateTableColumns(table.TableColumns, context);
                break;

            case "BusinessComponent":
                BusinessComponent busComp = context.BusinessComponents
                                            .AsNoTracking()
                                            .Include(f => f.Fields)
                                            .ThenInclude(tc => tc.TableColumn)
                                            .Include(f => f.Fields)
                                            .ThenInclude(tc => tc.JoinColumn)
                                            .FirstOrDefault(i => i.Id == recordId);
                entityName = busComp.Name;
                members    = CreateFields(busComp.Fields);
                break;

            case "Applet":
                Applet applet = context.Applets
                                .AsNoTracking()
                                .Include(c => c.Controls)
                                .ThenInclude(f => f.Field)
                                .Include(c => c.Columns)
                                .ThenInclude(f => f.Field)
                                .FirstOrDefault(i => i.Id == recordId);
                entityName = applet.Name;
                members    = CreateColumns(applet.Columns, context).Concat(CreateControls(applet.Controls, context));
                break;
            }
            string permissibleName = GetPermissibleName(entityName);

            if (TryGetModel(GSCrmApplication, permissibleName, entityType.Name, out syntaxTree))
            {
                SyntaxNode             rootNode  = syntaxTree.GetRoot();
                ClassDeclarationSyntax classNode = rootNode
                                                   .DescendantNodes()
                                                   .OfType <ClassDeclarationSyntax>()
                                                   .SingleOrDefault(n => n.Identifier.ValueText == permissibleName);
                List <PropertyDeclarationSyntax> interProps = new List <PropertyDeclarationSyntax>();
                classNode.Members.OfType <PropertyDeclarationSyntax>().ToList().ForEach(property =>
                {
                    if (!members.Contains(property) && !property.Identifier.ValueText.StartsWith(SystemPrefix))
                    {
                        interProps.Add(property);
                    }
                });
                rootNode   = rootNode.ReplaceNode(classNode, classNode.WithMembers(List(members.Except(interProps))));
                syntaxTree = SyntaxTree(rootNode).WithFilePath(syntaxTree.FilePath);
            }
            else
            {
                syntaxTree = CreateModel(permissibleName, entityType, members);
                if (entityType == typeof(Table))
                {
                    Compile("GSCrmApplicationContext", syntaxTree);
                }
            }
            WriteTree(GSCrmApplication, permissibleName, entityType.Name, syntaxTree);
            Compile("GSCrm" + entityType.Name, syntaxTree);
        }