public string GetSpartanModules(string roleID)
        {
            if (!_tokenManager.GenerateToken())
            {
                return(null);
            }
            _ISpartanModuleApiConsumer.SetAuthHeader(_tokenManager.Token);

            var result = _ISpartanModuleApiConsumer.SelAll(false).Resource;

            lstUserRoleModules = GetSpartaneUserRoleModules(Convert.ToInt32(roleID));

            if (result != null)
            {
                lstFlatObject = CreateModuleHierarchy(result);
            }

            List <RecursiveObject> lstRecursieveObjects;

            lstRecursieveObjects = FillRecursive(lstFlatObject, 0);

            lstRecursieveObjects = lstRecursieveObjects.OrderBy(m => m.moduleOrder).ThenBy(m => m.originalOrder).ToList();

            string myjsonmodel = new JavaScriptSerializer().Serialize(lstRecursieveObjects);

            string jsonData = myjsonmodel.Replace("selected", "checked");

            return(jsonData);
        }
예제 #2
0
        /// <summary>
        /// Used to get the latest version of the menu
        /// </summary>
        public static void GetLatestMenu()
        {
            //new Thread(() =>
            //{
            if (!_tokenManager.GenerateToken("admin", "admin"))
            {
                throw new ArgumentException("Unable to Authorize the application");
            }

            //Adding Token in each request
            _userRoleApiConsumer.SetAuthHeader(_tokenManager.Token);
            _spartaneModuleApiConsumer.SetAuthHeader(_tokenManager.Token);
            _spartanUserRoleModuleApiConsumer.SetAuthHeader(_tokenManager.Token);
            _spartaneObjectApiConsumer.SetAuthHeader(_tokenManager.Token);
            _spartaneUserRoleModuleObjectApiConsumer.SetAuthHeader(_tokenManager.Token);


            var userRoles = _userRoleApiConsumer.SelAll(true).Resource;

            if (!userRoles.Any())
            {
                return;
            }

            //Getting all as the _spartanUserRoleModuleApiConsumer GETByKey method not working
            var userRoleModuleAll = _spartanUserRoleModuleApiConsumer.SelAll(true).Resource;

            if (!userRoleModuleAll.Any())
            {
                return;
            }

            _SpartaneUserRoleModuleObject = _spartaneUserRoleModuleObjectApiConsumer.SelAll(true).Resource.OrderBy(m => m.Order_Shown).ToList();
            if (!_SpartaneUserRoleModuleObject.Any())
            {
                return;
            }
            //Itrating over the list of userRoles for getting the respective menus
            //List<SpartaneUserRoleModule> userRoleModules;

            //Initializing Menu Order
            MenuOrder = new Dictionary <int, List <RecursiveObject> >();

            int languageId = SessionHelper.languageid;

            foreach (var userRole in userRoles)
            {
                var UserAdditionalMenu = _spartaneUserRoleModuleObjectApiConsumer.GetAdditionalMenu(userRole.User_Role_Id, languageId).Resource.ToList();
                lstUserRoleModules = userRoleModuleAll.Where(m => m.Spartan_User_Role == userRole.User_Role_Id).OrderBy(m => m.Order_Shown).ToList();
                if (!lstUserRoleModules.Any())
                {
                    continue;
                }
                var modules = new List <SpartanModule>();

                foreach (var userRoleModule in lstUserRoleModules)
                {
                    modules.Add(_spartaneModuleApiConsumer.GetByKey(userRoleModule.Module_Id, true).Resource);
                }

                var additionalMenu = CreateUserAdditionalMenuHierachy(UserAdditionalMenu);
                var flatObjects    = CreateModuleHierarchy(modules.Where(m => m.Status == 1).ToList());

                var RecursirveAdditionalMenu = GetRecursiveAdditionalMenu(additionalMenu, UserAdditionalMenu);

                MenuOrder.Add(userRole.User_Role_Id, FillRecursive(flatObjects, 0, userRole.User_Role_Id));
                MenuOrder[userRole.User_Role_Id].AddRange(RecursirveAdditionalMenu);

                lstUserRoleModules = null;
            }

            _SpartaneUserRoleModuleObject = null;
        }