/// <summary>
        /// Used to get the user Role
        /// </summary>
        /// <returns></returns>
        public JsonResult GetUserRoles()
        {
            if (!_tokenManager.GenerateToken())
            {
                return(null);
            }
            _IUserRoleApiConsumer.SetAuthHeader(_tokenManager.Token);

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

            foreach (var r in result)
            {
                string roleDescription = Roles.GetRoleValueById(r.User_Role_Id);

                r.Description = roleDescription;
            }

            return(Json(result == null ? null : result.Select(m => new { Text = m.Description, Value = m.User_Role_Id, Status = m.Status }), JsonRequestBehavior.AllowGet));
        }
Exemple #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;
        }