/// <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
        public ActionResult Index()
        {
            bool token = _tokenManager.GenerateToken();

            try
            {
                if (!token)
                {
                    return(Json(null, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    _IUserRoleApiConsumer.SetAuthHeader(_tokenManager.Token);
                    ViewBag.combo = _IUserRoleApiConsumer.ListaSelAll(1, int.MaxValue, "", "").Resource.Spartan_User_Roles;
                    return(View());
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public ActionResult Create(int Id = 0, int consult = 0)
        {
            var permission = PermissionHelper.GetRoleObjectPermission(SessionHelper.Role, 101);

            ViewBag.Permission = permission;
            var varSpartan_User_Role = new Spartan_User_RoleModel();

            ViewBag.ObjectId  = "101";
            ViewBag.Operation = "New";

            ViewBag.IsNew = true;



            if ((Id.GetType() == typeof(string) && Id.ToString() != "") || ((Id.GetType() == typeof(int) || Id.GetType() == typeof(Int16) || Id.GetType() == typeof(Int32) || Id.GetType() == typeof(Int64) || Id.GetType() == typeof(short)) && Id.ToString() != "0"))
            {
                ViewBag.IsNew     = false;
                ViewBag.Operation = "Update";
                if (!_tokenManager.GenerateToken())
                {
                    return(Json(null, JsonRequestBehavior.AllowGet));
                }
                _ISpartan_User_RoleApiConsumer.SetAuthHeader(_tokenManager.Token);
                var Spartan_User_RoleData = _ISpartan_User_RoleApiConsumer.GetByKeyComplete(Id).Resource.Spartan_User_Roles[0];
                if (Spartan_User_RoleData == null)
                {
                    return(HttpNotFound());
                }

                varSpartan_User_Role = new Spartan_User_RoleModel
                {
                    User_Role_Id        = (int)Spartan_User_RoleData.User_Role_Id
                    , Description       = Spartan_User_RoleData.Description
                    , Status            = Spartan_User_RoleData.Status
                    , StatusDescription = (string)Spartan_User_RoleData.Status_Spartan_User_Role_Status.Description
                };
            }
            if (!_tokenManager.GenerateToken())
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }

            _ISpartan_User_Role_StatusApiConsumer.SetAuthHeader(_tokenManager.Token);
            var Spartan_User_Role_Statuss = _ISpartan_User_Role_StatusApiConsumer.SelAll(true);

            if (Spartan_User_Role_Statuss != null && Spartan_User_Role_Statuss.Resource != null)
            {
                ViewBag.Spartan_User_Role_Statuss = Spartan_User_Role_Statuss.Resource.Select(m => new SelectListItem
                {
                    Text = m.Description.ToString(), Value = Convert.ToString(m.User_Role_Status_Id)
                }).ToList();
            }


            ViewBag.Consult = consult == 1;
            if (consult == 1)
            {
                ViewBag.Operation = "Consult";
            }
            return(View(varSpartan_User_Role));
        }
Exemple #4
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;
        }