Ejemplo n.º 1
0
        public async Task UpdateAsync(Step stepUpdate)
        {
            var step = await ValidateStepExistsAsync(stepUpdate.Id);

            // Error if start and end are the same point
            PointsValidation.ValidateEqualPointsAsync(stepUpdate.Start?.Description, stepUpdate.End?.Description);

            if (!string.IsNullOrWhiteSpace(stepUpdate.Start?.Description))
            {
                // Error if point description does not exist
                var start = await PointsValidation.ValidatePointExistsAsync(_pointRepository, stepUpdate.Start.Description);

                step.Start = start;
            }

            if (!string.IsNullOrWhiteSpace(stepUpdate.End?.Description))
            {
                // Error if point description does not exist
                var end = await PointsValidation.ValidatePointExistsAsync(_pointRepository, stepUpdate.End.Description);

                step.End = end;
            }

            // Error if step with such points already exists
            await ValidateStepAlreadyExistsAsync(step);

            if (stepUpdate.Cost > 0)
            {
                step.Cost = stepUpdate.Cost;
            }
            if (stepUpdate.Time > 0)
            {
                step.Time = stepUpdate.Time;
            }

            await _stepRepository.UpdateAsync(step);

            _cacheManager.RemoveBulkWithExpression(CacheKeys.Route);
        }