コード例 #1
0
        public async Task <IActionResult> GetConfigScreenByCompanyByScreen([FromRoute] int roleId, int screenId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            List <RoleActionViewModel> listIndex = new List <RoleActionViewModel>();


            var configScreen = await _context.SecurityRoleActions.Where(x => x.SecurityRoleId == roleId).Include(x => x.SecurityAction).ThenInclude(x => x.SystemAction).Select(x => new { x.Id, x.SecurityActionId, x.SecurityAction.SystemAction.Code, x.SecurityRoleId, x.SecurityAction.ConfigScreenId }).ToListAsync();

            foreach (var item in configScreen.Where(x => x.ConfigScreenId == screenId))
            {
                RoleActionViewModel viewModel = new RoleActionViewModel();
                viewModel.Id             = item.Id;
                viewModel.ActionId       = item.SecurityActionId;
                viewModel.ActionCode     = item.Code;
                viewModel.SecurityRoleId = item.SecurityRoleId;

                listIndex.Add(viewModel);
            }
            ;



            if (listIndex == null)
            {
                return(NotFound());
            }

            return(Ok(listIndex));
        }
コード例 #2
0
        public async Task <ActionResult> Action(RoleActionViewModel model)
        {
            IdentityResult result = null;

            if (!string.IsNullOrEmpty(model.Id)) // edit a accommodation type
            {
                var role = await RoleManager.FindByIdAsync(model.Id);

                role.Name = model.Name;


                result = await RoleManager.UpdateAsync(role);
            }
            else // create a new accommodation type
            {
                var role = new IdentityRole();

                role.Name = model.Name;

                result = await RoleManager.CreateAsync(role);
            }


            return(Json(new { success = result.Succeeded, message = string.Join("</br>", result.Errors) },
                        JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public IEnumerable <RoleActionViewModel> GetSystemRoleAction()
        {
            List <SystemAction>     listactions    = _context.SystemAction.Where(x => x.Enabled == true).ToList();
            List <SystemRole>       listroles      = _context.SystemRole.ToList();
            List <SystemRoleAction> listroleaction = _context.SystemRoleAction.ToList();

            List <RoleActionViewModel> listvm = new List <RoleActionViewModel>();

            foreach (var rol in listroles)
            {
                foreach (var action in listactions)
                {
                    //Busco si tiene algun rol asociad
                    RoleActionViewModel model = new RoleActionViewModel
                    {
                        ActionCode        = action.Code,
                        ActionDescription = action.Description,
                        SystemActionId    = action.Id,
                        SystemRoleId      = rol.Id,
                        SystemScreenId    = action.SystemScreenId,
                        Enabled           = listroleaction.Where(x => x.SystemActionId == action.Id && x.SystemRoleId == rol.Id).Any()
                    };
                    listvm.Add(model);
                }
            }

            return(listvm);
        }
コード例 #4
0
        public async Task <ActionResult> Delete(string id)
        {
            var role = await RoleManager.FindByIdAsync(id);

            var model = new RoleActionViewModel()
            {
                Id = role.Id
            };

            return(PartialView("_Delete", model));
        }
コード例 #5
0
        public async Task <ActionResult> Delete(RoleActionViewModel model)
        {
            IdentityResult result = null;

            if (!string.IsNullOrEmpty(model.Id))
            {
                var role = await RoleManager.FindByIdAsync(model.Id);

                result = await RoleManager.DeleteAsync(role);

                return(Json(new { success = result.Succeeded, message = string.Join("</br>", result.Errors) },
                            JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { success = false, message = "invalid user" }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #6
0
        // GET: RoleAction
        public ActionResult Index()
        {
            var rolesid = RoleManager.Roles;
            var role    = _dbContext.RoleActions.Select(a => a.Action.Id).ToList();
            var temp    = _dbContext.RoleActions.ToList();
            var model   = new RoleActionViewModel()
            {
                Role            = rolesid,
                ActionRolesList = _dbContext.RoleActions.Select(x => new SelectListItem()
                {
                    Selected = role.Contains(x.ActionId),
                    Text     = x.RoleId,
                    Value    = x.ActionId
                }).Where(a => a.Selected).ToList()
            };

            return(View(model));
        }
コード例 #7
0
        public async Task <ActionResult> Action(string id)
        {
            if (string.IsNullOrEmpty(id)) //create form
            {
                var model = new RoleActionViewModel();
                return(PartialView("_Action", model));
            }
            else // edit form
            {
                var role = await RoleManager.FindByIdAsync(id);

                var model = new RoleActionViewModel()
                {
                    Id   = role.Id,
                    Name = role.Name
                };
                return(PartialView("_Action", model));
            }
        }