public virtual ActionResult GrantModulesToRole(string RoleId, string Modules)
        {
            JsonResponse response = new JsonResponse();

            response.Messages = new List <ResponseItem>();

            string[]      moduleIds = Modules.Split(',');
            StringBuilder sb        = new StringBuilder();

            ResponseItem item = null;

            try
            {
                roleRepo.AddModuleAndAction(moduleIds, RoleId);

                item              = new ResponseItem();
                item.Success      = true;
                response.Message  = "modules was added successfully!";
                response.CssClass = "green";
                response.Messages.Add(item);
            }
            catch (Exception ex)
            {
                item              = new ResponseItem();
                item.Success      = false;
                response.Success  = false;
                response.Message  = ex.Message;
                response.CssClass = "red";
                response.Messages.Add(item);
            }
            return(Json(response));
        }
Esempio n. 2
0
        public virtual ActionResult AddModulesToRole(string[] modules, string roleName)
        {
            JsonResponse response = new JsonResponse();

            try
            {
                roleRepo.AddModuleAndAction(modules, roleName);

                if (Request.IsAjaxRequest())
                {
                    response.Success  = true;
                    response.Message  = "Module added successfully!";
                    response.CssClass = "green";

                    return(Json(response));
                }

                return(RedirectToAction("AddModule"));
            }
            catch (Exception ex)
            {
                if (Request.IsAjaxRequest())
                {
                    response.Success  = false;
                    response.Message  = ex.Message + "\r\n" + ex.StackTrace + "\r\n" + ex.InnerException.Message + "\r\n" + ex.InnerException.StackTrace;
                    response.CssClass = "red";

                    return(Json(response));
                }

                ModelState.AddModelError("", ex.Message);
            }

            return(RedirectToAction("AddModule"));
        }