Ejemplo n.º 1
0
        public async Task <Step> CreateAsync(Step step)
        {
            // Error if start and end are the same point
            PointsValidation.ValidateEqualPointsAsync(step.Start?.Description, step.End?.Description);

            // Error if point description does not exist
            var start = await PointsValidation.ValidatePointExistsAsync(_pointRepository, step.Start?.Description);

            var end = await PointsValidation.ValidatePointExistsAsync(_pointRepository, step.End?.Description);

            var stepToAdd = new Step
            {
                Start = start,
                End   = end
            };

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

            // Error if time/cost is zero or less
            ValidatePositiveTimeCost(step.Cost);
            ValidatePositiveTimeCost(step.Time);

            stepToAdd.Cost = step.Cost;
            stepToAdd.Time = step.Time;

            await _stepRepository.AddAsync(stepToAdd);

            _cacheManager.RemoveBulkWithExpression(CacheKeys.Route);

            return((await _stepRepository.GetAsync()).FirstOrDefault(x =>
                                                                     (x.Start?.Description?.Equals(stepToAdd.Start.Description) == true || x.StartId == stepToAdd.Start.Id) &&
                                                                     (x.End?.Description?.Equals(stepToAdd.End.Description) == true || x.EndId == stepToAdd.End.Id)));
        }
Ejemplo n.º 2
0
 /// <summary>Validates if there is any step that starts with the origin point of the route.</summary>
 /// <param name="point">The point to check.</param>
 private async Task ValidateStepStartExistsAsync(Point point)
 {
     if (!(await _stepRepository.GetAsync(new Step {
         Start = point
     })).Any())
     {
         throw AppCustomExceptions.StepBeginRouteNotFound;
     }
 }
Ejemplo n.º 3
0
        /// <summary>Gets all the steps started by each point.</summary>
        private async Task GetAllPointSteps()
        {
            var allPoints = await _pointRepository.GetAsync();

            foreach (var point in allPoints)
            {
                var steps = await _stepRepository.GetAsync(new Step { Start = point });

                _pointStepsList.Add(new PointSteps
                {
                    Point = point,
                    Steps = steps.ToList()
                });
            }
        }
Ejemplo n.º 4
0
        /// <summary>Gets all the steps started by each point.</summary>
        private async Task GetAllPointSteps()
        {
            var allPoints = await _pointRepository.GetAsync();

            foreach (var point in allPoints)
            {
                var steps = await _stepRepository.GetAsync(new Step { Start = point });

                _pointStepsList.Add(new PointSteps
                {
                    Point = point,
                    Steps = _pathOption.Equals(PathPerformanceOptions.Cost) ? steps.OrderBy(x => x.Cost).ToList() : steps.OrderBy(x => x.Time).ToList()
                });
            }
        }