public async Task <bool> Execute(AddClaimParameter request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (string.IsNullOrWhiteSpace(request.Code))
            {
                throw new ArgumentNullException(nameof(request.Code));
            }

            if (request.IsIdentifier)
            {
                throw new IdentityServerManagerException(ErrorCodes.InvalidRequestCode, ErrorDescriptions.CannotInsertClaimIdentifier);
            }

            var claim = await _claimRepository.GetAsync(request.Code);

            if (claim != null)
            {
                throw new IdentityServerManagerException(ErrorCodes.InvalidRequestCode, ErrorDescriptions.ClaimExists);
            }

            return(await _claimRepository.InsertAsync(request));
        }
        public async Task <bool> InsertAsync(AddClaimParameter claim)
        {
            if (claim == null)
            {
                throw new ArgumentNullException(nameof(claim));
            }

            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    var newClaim = new Models.Claim
                    {
                        Code           = claim.Code,
                        IsIdentifier   = false, //claim.IsIdentifier,
                        CreateDateTime = DateTime.UtcNow,
                        UpdateDateTime = DateTime.UtcNow
                    };

                    _context.Claims.Add(newClaim);
                    await _context.SaveChangesAsync().ConfigureAwait(false);

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    _managerEventSource.Failure(ex);
                    transaction.Rollback();
                    return(false);
                }
            }

            return(true);
        }
        public Task <bool> InsertAsync(AddClaimParameter claim)
        {
            if (claim == null)
            {
                throw new ArgumentNullException(nameof(claim));
            }

            _claims.Add(new ClaimAggregate
            {
                Code           = claim.Code,
                CreateDateTime = DateTime.UtcNow,
                UpdateDateTime = DateTime.UtcNow
            });
            return(Task.FromResult(true));
        }
Ejemplo n.º 4
0
 public Task <bool> Add(AddClaimParameter request)
 {
     return(_addClaimAction.Execute(request));
 }