public async Task <ActionResult> CreateRole(PoolRoleViewModel model)
        {
            if (ModelState.IsValid)
            {
                var            role = model.ProjectTo <Role>();
                IdentityResult result;

                if (string.IsNullOrEmpty(model.Id))
                {
                    result = await _roleManager.CreateAsync(role);
                }
                else
                {
                    result = await _roleManager.UpdateAsync(role);
                }

                if (!result.Succeeded)
                {
                    return(BadRequest(String.Join(". ", result.Errors.Select(x => x.Description).ToArray())));
                }

                return(Ok(model));
            }

            return(BadRequest(ModelState));
        }
Esempio n. 2
0
        public async Task <IViewComponentResult> InvokeAsync(string clientId)
        {
            var client = await _clientManager.GetByIdAsync(clientId);

            var model = new PoolRoleViewModel()
            {
                PoolId    = client.SecurityPoolId,
                IsDefault = false,
                IsLocked  = false
            };

            ViewData["clientId"] = clientId;

            return(View(model));
        }
Esempio n. 3
0
        public async Task <IViewComponentResult> InvokeAsync(string siteId)
        {
            var site = await _siteManager.GetByIdAsync(siteId);

            var model = new PoolRoleViewModel()
            {
                PoolId    = site.SecurityPoolId,
                IsDefault = false,
                IsLocked  = false
            };

            ViewData["siteId"] = siteId;

            return(View(model));
        }
Esempio n. 4
0
        public async Task <IViewComponentResult> InvokeAsync(string poolId = "")
        {
            if (string.IsNullOrEmpty(poolId))
            {
                return(new ViewComponentPlaceholder());
            }

            var model = new PoolRoleViewModel()
            {
                PoolId    = poolId,
                IsDefault = false,
                IsLocked  = false
            };

            return(View("PoolRoleCreate", model));
        }
Esempio n. 5
0
        public async Task <IViewComponentResult> InvokeAsync(string clientId = "", string roleId = "")
        {
            var client = await _clientManager.GetByIdAsync(clientId);

            var role = await _roleManager.GetByIdAsync(roleId);

            var model = new PoolRoleViewModel()
            {
                Id        = role.Id,
                Name      = role.Name,
                IsDefault = role.IsDefault,
                IsLocked  = role.IsLocked,
                PoolId    = client.SecurityPoolId
            };

            ViewData["clientId"] = clientId;

            return(View(model));
        }
Esempio n. 6
0
        public async Task <IViewComponentResult> InvokeAsync(string poolId = "", string roleId = "")
        {
            if (string.IsNullOrEmpty(poolId) || string.IsNullOrEmpty(roleId))
            {
                return(new ViewComponentPlaceholder());
            }

            var role = await _roleManager.GetByIdAsync(roleId);

            var model = new PoolRoleViewModel()
            {
                Id        = role.Id,
                Name      = role.Name,
                IsDefault = role.IsDefault,
                IsLocked  = role.IsLocked,
                PoolId    = poolId
            };

            return(View("PoolRoleEdit", model));
        }