Example #1
0
        public async ValueTask <Capability> Create(string name, string description)
        {
            var existingCapabilities = await _capabilityRepository.GetAll();

            var capabilitiesWithSameName = existingCapabilities.Where(c => c.Name == name);

            if (capabilitiesWithSameName.Any())
            {
                throw  new CapabilityWithSameNameExistException(name);
            }

            return(await _inner.Create(name, description));
        }
        private async Task <IEnumerable <Capability> > QueryCapabilities(
            FindConnectionsByClientTypeClientIdChannelTypeChannelId query)
        {
            if (query.ChannelType != null && !query.ChannelType.IsEmpty && !(query.ChannelType is ChannelTypeSlack))
            {
                return(Enumerable.Empty <Capability>());
            }

            if (query.ClientType != null && !query.ClientType.IsEmpty && !(query.ClientType is ClientTypeCapability))
            {
                return(Enumerable.Empty <Capability>());
            }

            var capabilities = await _capabilityRepository.GetAll();

            if (query.ChannelId != null && !query.ChannelId.IsEmpty)
            {
                capabilities = capabilities
                               .Where(c =>
                                      c.SlackChannelId.Equals(query.ChannelId)
                                      );
            }

            if (query.ClientId == null || query.ClientId.IsEmpty)
            {
                return(capabilities);
            }


            Guid capabilityId;
            var  capabilityIdIsValid = Guid.TryParse(query.ClientId, out capabilityId);

            if (capabilityIdIsValid == false)
            {
                throw new ValidationException(
                          $"The given capability id: '{query.ClientId}' is not valid. Expected format is Guid with 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).");
            }

            capabilities = capabilities
                           .Where(c =>
                                  c.Id.Equals(capabilityId));


            return(capabilities);
        }
Example #3
0
 public Task <IEnumerable <Capability> > GetAllCapabilities() => _capabilityRepository.GetAll();