protected async Task <ApplicationAuthorizationPolicy> FindPolicyAsync(string policyName, CancellationToken cancellationToken)
        {
            var policyRequest = await _authorizationPolicyService.FindByNameAsync(policyName);

            var authorizationPolicy = new ApplicationAuthorizationPolicy
            {
                Description = policyRequest.Description,
                Name        = policyRequest.Name,
                Id          = policyRequest.Id
            };

            return(authorizationPolicy);
        }
示例#2
0
        public async Task <IActionResult> Create(AuthorizationPolicyModel model)
        {
            if (model.Id > 0)
            {
                return(RedirectToErrorPage());
            }

            var exist = await _authorizationPolicyService.FindByNameAsync(model.Name);

            if (exist != null)
            {
                return(RedirectToErrorPage());
            }

            if (model.PermissionMethod > 0)
            {
                var permissionMethod = (PolicyMethod)model.PermissionMethod;
                model.Name = $"{permissionMethod}{model.Name}";
            }

            var policy = new AuthorizationPolicyRequest
            {
                CreatedById   = LoggedUserId,
                CreatedDate   = model.CreatedDate,
                CreatedByName = model.CreatedByName,
                UpdatedById   = LoggedUserId,
                UpdatedDate   = model.CreatedDate,
                UpdatedByName = model.CreatedByName,
                Description   = model.Description,
                Name          = model.Name
            };

            var newId = _authorizationPolicyService.Create(policy);

            return(RedirectToAction(nameof(Detail), new { id = newId }));
        }