Exemple #1
0
        public static Model.VehicleCreationInfo Convert(Client.VehicleCreationInfo clientCreationInfo)
        {
            if (clientCreationInfo == null)
            {
                throw new ArgumentNullException(nameof(clientCreationInfo));
            }

            var modelCreationInfo = new Model.VehicleCreationInfo(clientCreationInfo.Mark, clientCreationInfo.GovNumber);

            return(modelCreationInfo);
        }
        public async Task <IActionResult> CreateVehicleAsync([FromBody] Client.VehicleCreationInfo creationInfo,
                                                             CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

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

            var modelCreationInfo = Converter.VehicleCreationInfoConverter.Convert(creationInfo);
            var modelVehicle      = await repository.CreateAsync(modelCreationInfo, cancellationToken).ConfigureAwait(false);

            var clientVehicle = Converter.VehicleConverter.Convert(modelVehicle);

            return(CreatedAtRoute("GetVehicleRoute", new { id = clientVehicle.Id }, clientVehicle));
        }