Ejemplo n.º 1
0
        private void GenerateNavigation(EntityMeta entityMeta)
        {
            Console.WriteLine(string.Format("Generate navigation for entity {0}.", entityMeta.Name));
            if (string.IsNullOrEmpty(entityMeta.ScaffoldGroupTitle))
            {
                return;
            }

            var group = dbConfig.ModuleGroups.Include(g => g.App).Where(g => g.App.Id == appId && g.Title.Equals(entityMeta.ScaffoldGroupTitle)).SingleOrDefault();

            if (group == null)
            {
                group = new ModuleGroup()
                {
                    App = app, Title = entityMeta.ScaffoldGroupTitle, OrderNo = entityMeta.ScaffoldGroupOrderNo
                };
                dbConfig.ModuleGroups.Add(group);
                dbConfig.SaveChanges();
            }

            var module = dbConfig.Modules.Include(m => m.Group).Where(m => m.Title == entityMeta.Name && m.ModuleType == ModuleType.AutoGenerated).SingleOrDefault();

            if (module == null)
            {
                module = new Module()
                {
                    Group = group, ModuleType = ModuleType.AutoGenerated, Title = entityMeta.Name, OrderNo = entityMeta.ScaffoldModuleOrderNo, ScaffoldEntity = entityMeta.Name
                };
                dbConfig.Modules.Add(module);
                dbConfig.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is to generate menu items and groups for navigation menu purpose.
        /// </summary>
        /// <param name="context">An instance of <see cref="DotWebDb"/>.</param>
        private void GenerateNavigationModules(DotWebDb context)
        {
            foreach (var tableMeta in schemaInfo.Tables)
            {
                string groupName = tableMeta.SchemaName == "dbo" ? schemaInfo.App.DefaultGroupName : tableMeta.SchemaName;
                var    group     = schemaInfo.App.Groups.FirstOrDefault(
                    g => g.AppId == appId && g.Name.Equals(groupName, StringComparison.InvariantCultureIgnoreCase));
                if (group == null)
                {
                    group = new ModuleGroup()
                    {
                        AppId   = appId,
                        Name    = groupName,
                        Title   = groupName,
                        OrderNo = schemaInfo.App.Groups.Count == 0 ? 1 : schemaInfo.App.Groups.Count + 1,
                    };
                    schemaInfo.App.Groups.Add(group);
                }

                var dbModule = context.Modules.Include(m => m.Group).SingleOrDefault(m => m.TableName.Equals(tableMeta.Name, StringComparison.InvariantCultureIgnoreCase) &&
                                                                                     m.Group.AppId == appId);

                if (dbModule == null)
                {
                    group.Modules.Add(new Module()
                    {
                        TableName  = tableMeta.Name,
                        Title      = tableMeta.Name.ToTitleCase(),
                        OrderNo    = group.Modules.Count == 0 ? 1 : group.Modules.Count + 1,
                        ModuleType = ModuleType.AutoGenerated
                    });
                }
            }
        }