public async Task <string> Execute(string clientId, IEnumerable <AddPermissionParameter> addPermissionParameters)
        {
            if (string.IsNullOrWhiteSpace(clientId))
            {
                throw new ArgumentNullException(clientId);
            }

            if (addPermissionParameters == null)
            {
                throw new ArgumentNullException(nameof(addPermissionParameters));
            }

            var json = addPermissionParameters == null ? string.Empty : JsonConvert.SerializeObject(addPermissionParameters);

            _umaServerEventSource.StartAddPermission(json);

            await CheckAddPermissionParameter(addPermissionParameters);

            var ticketLifetimeInSeconds = await _configurationService.GetTicketLifeTime();

            var ticket = new Ticket
            {
                Id                 = Guid.NewGuid().ToString(),
                ClientId           = clientId,
                CreateDateTime     = DateTime.UtcNow,
                ExpiresIn          = ticketLifetimeInSeconds,
                ExpirationDateTime = DateTime.UtcNow.AddSeconds(ticketLifetimeInSeconds)
            };
            var ticketLines = new List <TicketLine>();

            foreach (var addPermissionParameter in addPermissionParameters) // TH : ONE TICKET FOR MULTIPLE PERMISSIONS.
            {
                ticketLines.Add(new TicketLine
                {
                    Id            = Guid.NewGuid().ToString(),
                    Scopes        = addPermissionParameter.Scopes,
                    ResourceSetId = addPermissionParameter.ResourceSetId
                });
            }

            ticket.Lines = ticketLines;
            if (!await _ticketStore.AddAsync(ticket))
            {
                throw new BaseUmaException(ErrorCodes.InternalError, ErrorDescriptions.TheTicketAlreadyExists);
            }

            _umaServerEventSource.FinishAddPermission(json);
            return(ticket.Id);
        }
        public async Task<IEnumerable<string>> Execute(string clientId, IEnumerable<AddPermissionParameter> addPermissionParameters)
        {
            if (string.IsNullOrWhiteSpace(clientId))
            {
                throw new ArgumentNullException(clientId);
            }

            if (addPermissionParameters == null)
            {
                throw new ArgumentNullException(nameof(addPermissionParameters));
            }

            var json = addPermissionParameters == null ? string.Empty : JsonConvert.SerializeObject(addPermissionParameters);
            _umaServerEventSource.StartAddPermission(json);

            await CheckAddPermissionParameter(addPermissionParameters);
            var ticketLifetimeInSeconds = await _configurationService.GetTicketLifeTime();
            var tickets = new List<Ticket>();
            foreach(var addPermissionParameter in addPermissionParameters)
            {
                tickets.Add(new Ticket
                {
                    Id = Guid.NewGuid().ToString(),
                    ClientId = clientId,
                    ExpirationDateTime = DateTime.UtcNow.AddSeconds(ticketLifetimeInSeconds),
                    Scopes = addPermissionParameter.Scopes,
                    ResourceSetId = addPermissionParameter.ResourceSetId,
                    CreateDateTime = DateTime.UtcNow
                });
            }
            
            await _repositoryExceptionHelper.HandleException(
                ErrorDescriptions.AtLeastOneTicketCannotBeInserted,
                () => _ticketRepository.Insert(tickets));
            _umaServerEventSource.FinishAddPermission(json);
            return tickets.Select(t => t.Id);
        }