Exemplo n.º 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);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void SyncWithMenu(int applicationId)
        {
            //MenuList

            var requestProfile = new RequestProfile();

            requestProfile.AuditId       = 10;
            requestProfile.ApplicationId = applicationId;

            const string sql = @"dbo.MenuList ";

            var parameters =
                new
            {
                AuditId         = requestProfile.AuditId
                , ApplicationId = applicationId
            };

            List <MenuDataModel> result;

            using (var dataAccess = new DataAccessBase(DataStoreKey))
            {
                result = dataAccess.Connection.Query <MenuDataModel>(sql, parameters, commandType: CommandType.StoredProcedure).ToList();
            }

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

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

            languageData.Name = "English";

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

            if (languageRecords.Count > 0)
            {
                var languageId = languageRecords[0].LanguageId.Value;

                foreach (var menuSourceRecord in result)
                {
                    var menuId = menuSourceRecord.MenuId;

                    var displayNameRecord = menuDisplayNameList.Find(x => x.MenuId == menuSourceRecord.MenuId && x.IsDefault == 1);
                    if (displayNameRecord == null)
                    {
                        var dataDisplayName = new MenuDisplayNameDataModel();
                        dataDisplayName.MenuId     = menuSourceRecord.MenuId;
                        dataDisplayName.Value      = menuSourceRecord.Name;
                        dataDisplayName.LanguageId = languageId;
                        dataDisplayName.IsDefault  = 1;

                        // create display name entry according to the default display name
                        MenuDisplayNameDataManager.Create(dataDisplayName, requestProfile);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static void Sync(int newApplicationId, int oldApplicationId, RequestProfile requestProfile, int languageId)
        {
            var tempMapping = new Dictionary <int, int>();

            // get all records for old Application Id
            var menuData = new MenuDataModel();

            menuData.ApplicationId = oldApplicationId;
            menuData.ParentMenuId  = 12393;
            var menuList = MenuDataManager.GetEntityDetails(menuData, requestProfile, 0);

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

            // formaulate a new request Profile which will have new Applicationid
            var newRequestProfile = new RequestProfile();

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

            foreach (var menuItem in menuList)
            {
                var parentMenuName = menuItem.ParentMenu;

                //get new fc mode id based on fc mode name
                //var newParentMenuId = timeZoneList.Find(x => x.Name == fcModeName).TimeZoneId;

                var data = new MenuDataModel();
                data.ApplicationId = newApplicationId;
                data.Name          = menuItem.Name;
                data.ParentMenuId  = menuItem.ParentMenuId;

                // check for existing record in new Application Id
                var dt = DoesExist(data, newRequestProfile);
                if (dt == null || dt.Rows.Count == 0)
                {
                    data.Description      = menuItem.Description;
                    data.SortOrder        = menuItem.SortOrder;
                    data.IsChecked        = menuItem.IsChecked;
                    data.IsVisible        = menuItem.IsVisible;
                    data.NavigateURL      = menuItem.NavigateURL;
                    data.PrimaryDeveloper = menuItem.PrimaryDeveloper;
                    data.Value            = menuItem.Value;

                    if (string.IsNullOrEmpty(data.PrimaryDeveloper))
                    {
                        data.PrimaryDeveloper = " ";
                    }

                    var menuDisplayNameValue = menuItem.Value;

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

                    //create in new application id
                    var newMenuId = Create(data, newRequestProfile);

                    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);

                    tempMapping.Add(menuItem.MenuId.Value, newMenuId);
                }
            }

            //menuData.ApplicationId = newApplicationId;
            //var newMenuList = MenuDataManager.GetEntityDetails(menuData, newRequestProfile);

            //foreach (var newMenuItem in menuList)
            //{
            //    if (newMenuItem.ParentMenuId != null)
            //    {
            //        var newMenuData = new MenuDataModel();
            //        newMenuData.MenuId = newMenuItem.MenuId;
            //        if (tempMapping.ContainsKey(newMenuItem.ParentMenuId.Value))
            //        {
            //            menuData.ParentMenuId = tempMapping[newMenuItem.ParentMenuId.Value];
            //            try
            //            {
            //                UpdateParentMenuOnly(newMenuData, newRequestProfile.AuditId);
            //            }
            //            catch { }
            //        }
            //    }
            //}
        }
Exemplo n.º 4
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);
                    }
                }
            }
        }