Example #1
0
            public async Task <IResult> Handle(UpdateGroupClaimCommand request, CancellationToken cancellationToken)
            {
                var entityToUpdate = new GroupClaim
                {
                    ClaimId = request.ClaimId,
                    GroupId = request.GroupId,
                    Id      = request.Id
                };
                await _groupClaimDal.UpdateAsync(entityToUpdate);

                return(new SuccessResult(Messages.GroupClaimUpdated));
            }
            public async Task <IResult> Handle(UpdateGroupClaimCommand request, CancellationToken cancellationToken)
            {
                var entityToUpdate = new GroupClaim
                {
                    ClaimId = request.ClaimId,
                    GroupId = request.GroupId,
                };

                _groupClaimRepository.Update(entityToUpdate);
                await _groupClaimRepository.SaveChangesAsync();

                return(new SuccessResult(Messages.GroupClaimUpdated));
            }
        public async Task<string> AddClaim(string clientId, string groupId, GroupClaim claim)
        {
            var group = await this.context.Groups
                .Include(g => g.GroupClaims)
                .FirstOrDefaultAsync(g => g.ClientId == clientId && g.Id == int.Parse(groupId));

            if (group == null)
            {
                throw new InvalidOperationException($"Could not find group {groupId} in client {clientId}");
            }

            var groupClaimDto = new GroupClaimDto { Type = claim.Type, Value = claim.Value, GroupId = int.Parse(groupId) };

            group.GroupClaims.Add(groupClaimDto);

            await this.context.SaveChangesAsync();

            return groupClaimDto.Id.ToString();
        }
        public async Task <string> AddClaim(string clientId, string groupId, GroupClaim claim)
        {
            var group = await this.context.Groups
                        .Include(g => g.GroupClaims)
                        .FirstOrDefaultAsync(g => g.ClientId == clientId && g.Id == int.Parse(groupId));

            if (group == null)
            {
                throw new InvalidOperationException($"Could not find group {groupId} in client {clientId}");
            }

            var groupClaimDto = new GroupClaimDto {
                Type = claim.Type, Value = claim.Value, GroupId = int.Parse(groupId)
            };

            group.GroupClaims.Add(groupClaimDto);

            await this.context.SaveChangesAsync();

            return(groupClaimDto.Id.ToString());
        }
        public async Task UpdateClaim(string clientId, string groupId, GroupClaim claim)
        {
            var group = await this.context.Groups
                        .Include(g => g.GroupClaims)
                        .FirstOrDefaultAsync(g => g.ClientId == clientId && g.Id == int.Parse(groupId));

            if (group == null)
            {
                throw new InvalidOperationException($"Could not find group {groupId} in client {clientId}");
            }

            var claimDto = group.GroupClaims.FirstOrDefault(c => c.Id == int.Parse(claim.Id));

            if (claimDto == null)
            {
                throw new InvalidOperationException($"Could not find claim {claim.Id} in group {groupId} in client {clientId}");
            }

            claimDto.Type  = claim.Type;
            claimDto.Value = claim.Value;

            await this.context.SaveChangesAsync();
        }
        public async Task UpdateClaim(string clientId, string groupId, GroupClaim claim)
        {
            var group = await this.context.Groups
                            .Include(g => g.GroupClaims)
                            .FirstOrDefaultAsync(g => g.ClientId == clientId && g.Id == int.Parse(groupId));

            if (group == null)
            {
                throw new InvalidOperationException($"Could not find group {groupId} in client {clientId}");
            }

            var claimDto = group.GroupClaims.FirstOrDefault(c => c.Id == int.Parse(claim.Id));

            if (claimDto == null)
            {
                throw new InvalidOperationException($"Could not find claim {claim.Id} in group {groupId} in client {clientId}");
            }

            claimDto.Type = claim.Type;
            claimDto.Value = claim.Value;

            await this.context.SaveChangesAsync();
        }