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))); }