public async Task <ResourceRoot> AddResourceAsync(IDesiredState desiredState, CancellationToken cancellationToken = default)
        {
            var resource = _resourceRepository.Add(new ResourceRoot((DesiredState)desiredState));

            await _resourceRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

            return(resource);
        }
        public async Task <IEnumerable <IAggregateRoot> > GetAggregatesByState(IDesiredState desiredState)
        {
            var resources = await _resourceRepository.GetAsync(o => o.DesiredState.Equals(desiredState));

            var environments = await _environmentRepository.GetAsync(o => o.DesiredState.Equals(desiredState));

            return(resources.Cast <IAggregateRoot>().Concat(environments));
        }
        public async Task <EnvironmentRoot> AddEnvironmentAsync(IDesiredState desiredState, CancellationToken cancellationToken = default)
        {
            var environment = _environmentRepository.Add(new EnvironmentRoot((DesiredState)desiredState));

            await _environmentRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

            return(environment);
        }
        public async Task <ResourceRoot> UpdateResourceAsync(Guid resourceId, IDesiredState desiredState, CancellationToken cancellationToken = default)
        {
            var resource = await GetResourceByIdAsync(resourceId);

            resource.SetDesiredState((DesiredState)desiredState);

            _resourceRepository.Update(resource);

            await _resourceRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

            return(resource);
        }
        public async Task <EnvironmentRoot> UpdateEnvironmentAsync(Guid environmentId, IDesiredState desiredState, CancellationToken cancellationToken = default)
        {
            var environment = await GetEnvironmentByIdAsync(environmentId);

            environment.SetDesiredState((DesiredState)desiredState);

            _environmentRepository.Update(environment);

            await _environmentRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

            return(environment);
        }