public IActionResult UpdateVehicle([FromBody] VehicleDTO vehicleDTO)
 {
     _logger?.LogInformation($"Inicio del servicio: [PUT] https://localhost:5001/api/vehicles ");
     try{
         VehicleMapper vehicleMapper = MapperFactory.CreateVehicleMapper();
         Entity        entity        = vehicleMapper.CreateEntity(vehicleDTO);
         _logger?.LogInformation($" Se transformó de DTO a Entity ");
         UpdateVehicleCommand command = CommandFactory.CreateUpdateVehicleCommand((Vehicle)entity);
         _logger?.LogInformation($" Ejecución del comando ");
         command.Execute();
         if (command.GetResult())
         {
             return(Ok("La modificación fue realizada exitosamente"));
         }
         else
         {
             return(StatusCode(400));
         }
     } catch (VehicleNotFoundException ex) {
         _logger?.LogWarning("Vehiculo con Id : " + ex.VehicleId + "no encontrado");
         return(StatusCode(404, ex.Message + ex.VehicleId));
     } catch (ModelNotFoundException ex) {
         _logger?.LogWarning("Modelo con Id : " + ex.ModelId + "no encontrado");
         return(StatusCode(404, ex.Message + ex.ModelId));
     } catch (LocationNotFoundException ex) {
         _logger?.LogWarning("Lugar no encontrado");
         return(StatusCode(404, ex.Message));
     }  catch (InternalServerErrorException ex) {
         _logger?.LogError("Error: " + ex.Ex.Message);
         return(StatusCode(500, ex.Message));
     } catch (Exception) {
         _logger?.LogError("Error inesperado");
         return(StatusCode(400));
     }
 }
        private async Task BuildUpdateCommandHandlerSuccess()
        {
            UpdateVehicleCommand saveVehicle = (UpdateVehicleCommand)validVehicle;
            bool result = await handlerSuccess.Handler(saveVehicle);

            SuccessTests(handlerSuccess.Invalid, result, handlerSuccess.Notifications);
        }
        private async Task BuildUpdateCommandHandlerError()
        {
            UpdateVehicleCommand saveVehicle = (UpdateVehicleCommand)validVehicle;
            bool result = await handlerError.Handler(saveVehicle);

            ErrorTests(handlerError.Invalid, result, handlerError.Notifications);
        }
Beispiel #4
0
 public Vehicle(UpdateVehicleCommand updateVehicle)
 {
     Id    = updateVehicle.Id;
     Brand = updateVehicle.Brand;
     Model = updateVehicle.Model;
     Color = updateVehicle.Color;
     Plate = updateVehicle.Plate;
     Type  = updateVehicle.Type;
 }
Beispiel #5
0
        public async Task <ActionResult> UpdateVehicle(int id, UpdateVehicleCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            await _mediator.Send(command);

            return(NoContent());
        }
Beispiel #6
0
        public async Task <ActionResult> Details(UpdateVehicleCommand updateVehicleCommand, CancellationToken cancellationToken)
        {
            try
            {
                await Mediator.Send(updateVehicleCommand, cancellationToken);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
        public async Task <bool> Handler(UpdateVehicleCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                AddNotifications(command);
                return(false);
            }
            Vehicle vehicle = command;

            if (!await _repository.Update(vehicle))
            {
                AddNotification("", "Erro ao atualizar o veículo");
                return(false);
            }
            return(true);
        }
        public Task <bool> Handle(UpdateVehicleCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(Task.FromResult(false));
            }

            var vehicle = new Vehicle(Guid.NewGuid(), message.VehicleId, message.RegNumber, message.CustomerId);

            _vehicleRepository.Update(vehicle);

            if (Commit())
            {
                _bus.RaiseEvent(new VehicleUpdatedEvent(vehicle.Id, vehicle.VehicleId, vehicle.RegNumber, vehicle.CustomerId));
            }

            return(Task.FromResult(true));
        }
        public Task <HttpResponseMessage> Put(UpdateVehicleCommand vehicle)
        {
            HttpResponseMessage response = new HttpResponseMessage();

            try
            {
                _service.Update(vehicle);
                response = Request.CreateResponse(HttpStatusCode.OK, new { name = vehicle.Model });
            }
            catch (Exception ex)
            {
                response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
            }

            var tsc = new TaskCompletionSource <HttpResponseMessage>();

            tsc.SetResult(response);
            return(tsc.Task);
        }
Beispiel #10
0
        public async Task <ActionResult> UpdateVehicle([FromBody] UpdateVehicleCommand command)
        {
            await _Mediator.Send(command);

            return(NoContent());
        }
        public Task <IActionResult> Put([FromBody] UpdateVehicleCommand vehicleCommand)
        {
            var result = _handler.Handler(vehicleCommand);

            return(Response(result, _handler.Notifications));
        }