Exemplo n.º 1
0
        public async Task UpdateClaim(
            IUserClaim userClaim,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            ThrowIfDisposed();
            cancellationToken.ThrowIfCancellationRequested();

            if (userClaim == null)
            {
                throw new ArgumentException("userClaim can't be null");
            }

            var claim = UserClaim.FromIUserClaim(userClaim);

            if (claim.Id == Guid.Empty)
            {
                throw new ArgumentException("userClaim must have a non empty id");
            }

            bool tracking = dbContext.ChangeTracker.Entries <UserClaim>().Any(x => x.Entity.Id == claim.Id);

            if (!tracking)
            {
                dbContext.UserClaims.Update(claim);
            }

            int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken)
                               .ConfigureAwait(false);
        }
Exemplo n.º 2
0
        public async Task CreateClaim(
            IUserClaim userClaim,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            ThrowIfDisposed();
            cancellationToken.ThrowIfCancellationRequested();

            if (userClaim == null)
            {
                throw new ArgumentException("userClaim cannnot be null");
            }
            if (userClaim.Id == Guid.Empty)
            {
                throw new ArgumentException("userClaim must have an id");
            }
            if (userClaim.SiteId == Guid.Empty)
            {
                throw new ArgumentException("userClaim must have n SiteId");
            }
            if (userClaim.UserId == Guid.Empty)
            {
                throw new ArgumentException("userClaim must have a UserId");
            }

            //await EnsureProjectId().ConfigureAwait(false);
            var projectId = userClaim.SiteId.ToString();

            var claim = UserClaim.FromIUserClaim(userClaim);

            await claimCommands.CreateAsync(
                projectId,
                claim.Id.ToString(),
                claim,
                cancellationToken).ConfigureAwait(false);
        }
Exemplo n.º 3
0
        public async Task CreateClaim(
            IUserClaim userClaim,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (userClaim == null)
            {
                throw new ArgumentException("userClaim can't be null");
            }

            var claim = UserClaim.FromIUserClaim(userClaim);

            if (claim.Id == Guid.Empty)
            {
                throw new ArgumentException("userClaim must have a non empty id");
            }

            using (var dbContext = _contextFactory.CreateContext())
            {
                dbContext.UserClaims.Add(claim);

                int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken)
                                   .ConfigureAwait(false);
            }
        }