Example #1
0
        // GET: Admin/Tag/Add
        public virtual ActionResult Add()
        {
            var createRoleViewModel = new RoleAccessAdd
            {
                Controllers = GetControllers()
            };

            return(View(createRoleViewModel));
        }
Example #2
0
        // Post: Admin/Tag/Add/id
        public virtual ActionResult Add(RoleAccessAdd model)
        {
            if (!ModelState.IsValid)
            {
                model.Controllers = GetControllers();
                return(View(model));
            }

            var role = new CustomRole
            {
                Title        = model.Title,
                Name         = Guid.NewGuid().ToString("N"),
                RoleAccesses = new List <RoleAccess>(),
                Description  = model.Description,
            };

            if (!string.IsNullOrEmpty(Request["RoleTotal"]))
            {
                var selected = Newtonsoft.Json.JsonConvert.DeserializeObject <List <ActionControllers> >(Request["RoleTotal"]);
                foreach (var item in selected)
                {
                    if (item.Controller == "#")
                    {
                    }
                    else
                    {
                        role.RoleAccesses.Add(new RoleAccess {
                            Controller = item.Controller, Action = item.Action
                        });
                    }
                }
                _roleService.CreateAsync(role);
                return(RedirectToAction("Index"));
            }
            else
            {
                model.Controllers = GetControllers();
                return(View(model));
            }
        }