/// <summary>
        /// Get Spratane Module by UserRole
        /// </summary>
        /// <param name="id"></param>
        /// <remarks>
        /// TODO:
        /// Correct GetByID Method of WebAPI Spartan_User_Role_Module (Ask Ricardo)
        /// </remarks>
        /// <returns></returns>

        public JsonResult GetSpartanUserRoleModuleByID(string id)
        {
            if (!_tokenManager.GenerateToken())
            {
                return(null);
            }
            _ISpartanUserRoleModuleApiConsumer.SetAuthHeader(_tokenManager.Token);

            var result = _ISpartanUserRoleModuleApiConsumer.GetByKey(1, false).Resource;

            return(Json(result == null ? null : (new { ModuleID = result.Module_Id, OrderShown = result.Order_Shown, SpartanUserRole = result.Spartan_User_Role })
                        , JsonRequestBehavior.AllowGet));
        }
Beispiel #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;
        }