public async Task <IActionResult> CreateRouteAsync([FromBody] Client.RouteCreationInfo creationInfo,
                                                           CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (creationInfo == null)
            {
                var error = ErrorResponsesService.BodyIsMissing(nameof(creationInfo));
                return(BadRequest(error));
            }

            var modelCreationInfo = Converter.RouteCreationInfoConverter.Convert(creationInfo);
            var modelRoute        = await routeRepository.CreateAsync(modelCreationInfo, cancellationToken).ConfigureAwait(false);

            var modelCheckpoints = await checkpointRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);

            var clientRoute = Converter.RouteConverter.Convert(modelRoute, modelCheckpoints);

            return(CreatedAtRoute("GetRouteRoute", new { id = clientRoute.Id }, clientRoute));
        }
        public async Task <DomainResult <ObjectId> > Handle(CreateRouteCommand command, CancellationToken cancellationToken)
        {
            var origin = await _pointRepository.FindAsync(command.OriginPointId);

            var destination = await _pointRepository.FindAsync(command.DestinationPointId);

            if (origin is null || destination is null)
            {
                return(DomainResult.Failure <ObjectId>("Origin or Destination not found"));
            }

            var route = Route.Create(origin, destination);

            if (await _routeRepository.AlreadyExistsAsync(x => route.IsTheSame(x)))
            {
                return(DomainResult.Failure <ObjectId>("Route already exists", HttpStatusCode.Conflict));
            }

            await _routeRepository.CreateAsync(route);

            await _mediator.Publish(new RouteCreatedEvent(route));

            return(DomainResult.Ok(route.Id));
        }
Exemple #3
0
 public async Task <bool> CreateAsync(Route entity, string dataBaseName = null)
 {
     return(await RouteRepo.CreateAsync(entity, dataBaseName));
 }