Ejemplo n.º 1
0
        public async Task <IndicatorResponse> UpdateIndicator(UpdateIndicatorRequest request)
        {
            // Get indicator
            var indicator = await _indicatorRepository.GetSingle(request.IndicatorId);

            // Throw NotFoundException if it does not exist
            if (indicator == null)
            {
                throw new NotFoundException(IndicatorMessage.IndicatorNotFound);
            }

            // Build dependencies
            var newDependencies = await BuildDependencies(request.IndicatorId, request.Dependencies);

            // Update dependencies
            var currentDependencies = await _indicatorDependencyRepository.GetAll(IndicatorDependencyExpression.IndicatorDependencyFilter(indicator.IndicatorId, null));

            _indicatorDependencyRepository.UpdateCollection(currentDependencies, newDependencies);

            // Update indicator
            indicator.Update(request.Name, request.Description, request.Formula, newDependencies);
            _indicatorRepository.Update(indicator);

            // Save
            await _mainDbContext.SaveChangesAsync();

            // Log into Splunk
            _logger.LogSplunkRequest(request);

            // Response
            var response = _mapper.Map <IndicatorResponse>(indicator);

            // Return
            return(response);
        }
Ejemplo n.º 2
0
        private async Task SetIndicatorDependencies(List <Indicator> indicators)
        {
            foreach (var indicator in indicators)
            {
                var dependencies = await _indicatorDependencyRepository.GetAll(IndicatorDependencyExpression.IndicatorDependencyFilter(indicator.IndicatorId, null));

                indicator.SetDependencies(dependencies);
            }
        }
Ejemplo n.º 3
0
        public async Task <Responses.Indicator> GetIndicator(string indicatorId)
        {
            // Get indicator
            var indicator = await _indicatorRepository.GetSingle(indicatorId);

            // Throw NotFound if it does not exist
            if (indicator == null)
            {
                throw new NotFoundException(IndicatorMessage.IndicatorNotFound);
            }

            // Get all indicator dependencies
            var indicatorDependencies = await _indicatorDependencyRepository.GetAll(IndicatorDependencyExpression.IndicatorDependencyFilter(indicatorId));

            // Set indicator dependencies
            indicator.SetDependencies(indicatorDependencies);

            // Response
            var response = _mapper.Map <Responses.Indicator>(indicator);

            // Return
            return(response);
        }
Ejemplo n.º 4
0
        public async Task <Responses.Indicator> UpdateIndicator(UpdateIndicator request)
        {
            // Get indicator
            var indicator = await _indicatorRepository.GetSingle(request.IndicatorId);

            // Throw NotFound if it does not exist
            if (indicator == null)
            {
                throw new NotFoundException(IndicatorMessage.IndicatorNotFound);
            }

            // Get dependencies
            var newDependencies = await GetDependencies(request.Dependencies);

            // Build new indicator dependencies
            var newIndicatorDependencies = IndicatorDependencyBuilder.BuildIndicatorDependencies(indicator.IndicatorId, newDependencies);

            // Get current indicator dependencies
            var currentIndicatorDependencies = await _indicatorDependencyRepository.GetAll(IndicatorDependencyExpression.IndicatorDependencyFilter(indicator.IndicatorId));

            // Update dependencies
            _indicatorDependencyRepository.UpdateCollection(currentIndicatorDependencies, newIndicatorDependencies);

            // Update indicator
            indicator.Update(request.Name, request.Description, request.Formula);

            // Update
            _indicatorRepository.Update(indicator);

            // Set dependencies
            indicator.SetDependencies(newIndicatorDependencies);

            // Save
            await _dbContext.SaveChangesAsync();

            // Log into Splunk
            _logger.LogSplunkInformation(request);

            // Response
            var response = _mapper.Map <Responses.Indicator>(indicator);

            // Return
            return(response);
        }
Ejemplo n.º 5
0
        private async Task GetDependencies(Indicator indicator)
        {
            var dependencies = await _indicatorDependencyRepository.GetAll(IndicatorDependencyExpression.IndicatorDependencyFilter(indicator.IndicatorId, null));

            indicator.SetDependencies(dependencies);
        }