コード例 #1
0
        private static void CreateChildMenuRecords(int newParentMenuId, string newApplicationModule,
                                                   List <MenuDataModel> childMenuRecords, List <MenuDataModel> dataSourceMenu, List <MenuDisplayNameDataModel> menuDisplayNameList,
                                                   int languageId, RequestProfile newRequestProfile)
        {
            if (childMenuRecords.Count > 0)
            {
                var sortOrderSeed = 1;
                foreach (MenuDataModel menuSourceRecord in childMenuRecords)
                {
                    var menuModel = new MenuDataModel();

                    menuModel.Name             = menuSourceRecord.Name;
                    menuModel.Value            = menuSourceRecord.Value;
                    menuModel.Description      = menuSourceRecord.Description;
                    menuModel.IsVisible        = menuSourceRecord.IsVisible;
                    menuModel.IsChecked        = menuSourceRecord.IsChecked;
                    menuModel.PrimaryDeveloper = menuSourceRecord.PrimaryDeveloper;
                    menuModel.NavigateURL      = menuSourceRecord.NavigateURL;

                    menuModel.ParentMenuId      = newParentMenuId;
                    menuModel.ApplicationId     = newRequestProfile.ApplicationId;
                    menuModel.ApplicationModule = newApplicationModule;
                    menuModel.SortOrder         = sortOrderSeed;

                    if (!DoesExist(menuModel, newRequestProfile))
                    {
                        var newMenuId = MenuDataManager.Create(menuModel, newRequestProfile);

                        var menuDisplayNameValue = menuModel.Value;

                        try
                        {
                            menuDisplayNameValue = menuDisplayNameList.Find(x => x.MenuId == menuSourceRecord.MenuId && x.IsDefault == 1).Value;
                        }
                        catch { }

                        var dataDisplayName = new MenuDisplayNameDataModel();
                        dataDisplayName.MenuId     = newMenuId;
                        dataDisplayName.Value      = menuDisplayNameValue;
                        dataDisplayName.LanguageId = languageId;
                        dataDisplayName.IsDefault  = 1;

                        // create display name entry according to the default display name
                        MenuDisplayNameDataManager.Create(dataDisplayName, newRequestProfile);

                        sortOrderSeed++;

                        var childMenuRecordsList = dataSourceMenu
                                                   .Where(t => t.ParentMenuId == menuSourceRecord.MenuId)
                                                   .Select(t => t)
                                                   .OrderBy(t => t.SortOrder).ToList();

                        CreateChildMenuRecords(newMenuId, newApplicationModule,
                                               childMenuRecordsList, dataSourceMenu, menuDisplayNameList,
                                               languageId, newRequestProfile);
                    }
                }
            }
        }
コード例 #2
0
        public static void SyncModule(string newModule, int newApplicationId,
                                      string sourceModule, int sourceApplicationId, RequestProfile requestProfile)
        {
            var sourceRequestProfile = new RequestProfile();

            sourceRequestProfile.ApplicationId = sourceApplicationId;
            sourceRequestProfile.AuditId       = requestProfile.AuditId;

            var newRequestProfile = new RequestProfile();

            newRequestProfile.ApplicationId = newApplicationId;
            newRequestProfile.AuditId       = requestProfile.AuditId;

            // get Language id of "Standard"
            var languageData = new LanguageDataModel();

            languageData.Name = "English";

            var languageRecords = LanguageDataManager.GetEntityDetails(languageData, newRequestProfile, 0);

            if (languageRecords.Count > 0)
            {
                DeleteHardExistingRecords(newModule, newRequestProfile);

                var languageId = languageRecords[0].LanguageId.Value;

                var dataQuery = new MenuDataModel();
                dataQuery.ApplicationModule = sourceModule;
                dataQuery.ApplicationId     = sourceApplicationId;

                var dataSourceMenu = MenuDataManager.GetEntityDetails(dataQuery, sourceRequestProfile, 0);

                var menuDisplayNameData = new MenuDisplayNameDataModel();
                var menuDisplayNameList = MenuDisplayNameDataManager.GetEntityDetails(menuDisplayNameData, sourceRequestProfile);

                var sortOrderSeed = 101;

                var listSourceRecords = dataSourceMenu
                                        .Where(t => t.ParentMenuId == null)
                                        .Select(t => t)
                                        .OrderBy(t => t.SortOrder).ToList();

                if (listSourceRecords.Count > 0)
                {
                    foreach (MenuDataModel menuSourceRecord in listSourceRecords)
                    {
                        var menuModel = new MenuDataModel();

                        menuModel.Name             = menuSourceRecord.Name;
                        menuModel.Value            = menuSourceRecord.Value;
                        menuModel.Description      = menuSourceRecord.Description;
                        menuModel.IsVisible        = menuSourceRecord.IsVisible;
                        menuModel.IsChecked        = menuSourceRecord.IsChecked;
                        menuModel.ParentMenuId     = menuSourceRecord.ParentMenuId;
                        menuModel.PrimaryDeveloper = menuSourceRecord.PrimaryDeveloper;
                        menuModel.NavigateURL      = menuSourceRecord.NavigateURL;

                        menuModel.ApplicationId     = newApplicationId;
                        menuModel.ApplicationModule = newModule;
                        menuModel.SortOrder         = sortOrderSeed;

                        if (!DoesExist(menuModel, newRequestProfile))
                        {
                            var newMenuId = MenuDataManager.Create(menuModel, newRequestProfile);

                            var menuDisplayNameValue = menuModel.Value;

                            try
                            {
                                menuDisplayNameValue = menuDisplayNameList.Find(x => x.MenuId == menuSourceRecord.MenuId && x.IsDefault == 1).Value;
                            }
                            catch { }

                            var dataDisplayName = new MenuDisplayNameDataModel();
                            dataDisplayName.MenuId     = newMenuId;
                            dataDisplayName.Value      = menuDisplayNameValue;
                            dataDisplayName.LanguageId = languageId;
                            dataDisplayName.IsDefault  = 1;

                            // create display name entry according to the default display name
                            MenuDisplayNameDataManager.Create(dataDisplayName, newRequestProfile);

                            sortOrderSeed++;

                            var childMenuRecordsList = dataSourceMenu
                                                       .Where(t => t.ParentMenuId == menuSourceRecord.MenuId)
                                                       .Select(t => t)
                                                       .OrderBy(t => t.SortOrder).ToList();

                            CreateChildMenuRecords(newMenuId, newModule,
                                                   childMenuRecordsList, dataSourceMenu, menuDisplayNameList,
                                                   languageId, newRequestProfile);
                        }
                    }

                    // get menu category id of "Standard"
                    var menuCategoryData = new MenuCategoryDataModel();
                    menuCategoryData.Name = "Standard";

                    var menuCategoryRecords = MenuCategoryDataManager.GetEntityDetails(menuCategoryData, newRequestProfile, 0);

                    if (menuCategoryRecords.Count > 0)
                    {
                        var menuCategoryId = menuCategoryRecords[0].MenuCategoryId;

                        // get newly inserted records
                        dataQuery = new MenuDataModel();
                        dataQuery.ApplicationModule = newModule;
                        dataQuery.ApplicationId     = newApplicationId;
                        var newMenuRecords = GetEntityDetails(dataQuery, newRequestProfile);

                        var listMenuIds = newMenuRecords.Select(x => x.MenuId.Value).ToArray();

                        // add MenuCategoryXMenu records
                        MenuCategoryXMenuDataManager.CreateByMenuCategory(menuCategoryId.Value, listMenuIds, newRequestProfile);
                    }
                }
            }
        }