public async Task <bool> Handle(AdicionarDroneCommand message, CancellationToken cancellationToken) { if (!ValidarComando(message)) { return(false); } var drone = _mapper.Map <Drone>(message); await _droneRepository.Adicionar(drone); drone.AdicionarEvento(_mapper.Map <DroneAdicionadoEvent>(drone)); return(await _droneRepository.UnitOfWork.Commit()); }
public async Task <bool> Handle(AdicionarDroneCommand request, CancellationToken cancellationToken) { if (!request.EhValido()) { return(false); } var drone = new Drone(); drone.Capacidade = request.Capacidade; drone.Velocidade = request.Velocidade; drone.Autonomia = request.Autonomia; drone.Carga = request.Carga; drone.AutonomiaRestante = request.AutonomiaRestante; await _droneRepository.Adicionar(drone); var resultDrone = await _droneRepository.UnitOfWork.Commit(); if (resultDrone) { var droneItinerario = new DroneItinerario { DataHora = request.DataHora, Drone = drone, DroneId = drone.Id, StatusDrone = request.StatusDrone }; await _droneItinerarioRepository.Adicionar(droneItinerario); return(await _droneItinerarioRepository.UnitOfWork.Commit()); } else { return(false); } }
public async Task <bool> Insert(Drone drone) { await _droneRepository.Adicionar(drone); return(await _droneRepository.UnitOfWork.Commit()); }