public ActionResult <Entity> Put([FromBody] Flight flight) { try { GetFindFlightCommand id = CommandFactory.GetFlightIdCommand((int)flight.Id); id.Execute(); if (id.GetResult().Equals(null)) { throw new ValidationErrorException("El vuelo que quiere editar no existe"); } FlightValidator validator = new FlightValidator(flight); validator.Validate(); UpdateFlightCommand _updateFlight = CommandFactory.UpdateFlightCommand(flight); _updateFlight.Execute(); return(Ok(new { Message = "¡Vuelo editado con éxito!" })); } catch (ValidationErrorException ex) { return(BadRequest(new { Message = ex.Message })); } catch (DbErrorException ex) { return(BadRequest(new { Message = ex.Message })); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(null); } }
public async Task <IActionResult> Update([FromBody] UpdateFlightModel model) { var userToUpdate = await _queryBus.RequestAsync <FlightByIdQuery, FlightByIdResponse>(new FlightByIdQuery { FlightId = model.FlightId }); if (userToUpdate == null || model == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } var command = new UpdateFlightCommand { DeparturePoint = model.DeparturePoint, DepartureTime = model.DepartureTime, FlightId = model.FlightId, Destination = model.Destination, Number = model.Number, TicketsId = model.TicketsId, TimeOfArrival = model.TimeOfArrival }; await _commandBus.ExecuteAsync(command); return(Ok()); }
public GenericCommandResult Update( [FromBody] UpdateFlightCommand command, [FromServices] FlightHandler handler ) { return((GenericCommandResult)handler.Handle(command)); }
public async Task <Result> Handle(UpdateFlightCommand request, CancellationToken cancellationToken) { try { // todo: This is not good practice. Todo: Get Airport Name from View var departureAirport = _airportRepository.GetByIataCode(request.DepartureAirportCode); var destinationAirport = _airportRepository.GetByIataCode(request.DestinationAirportCode); var flight = new Flight(request.Id, departureAirport.Id, departureAirport.Name, destinationAirport.Id, destinationAirport.Name, request.FlightTime, request.Distance, request.FuelNeeded, request.TakeOffEffort); _flightRepository.Update(flight); await _flightRepository.SaveChanges(); // Publish a Notification. Notification Handler will implement an Event Sourcing mechanism await _mediator.Publish(_mapper.Map <UpdateFlightEventLog>(flight)); return(new Result(true, string.Empty)); } catch (System.Exception ex) { return(new Result(false, ex.Message)); } }
public async Task Post([FromBody] ClubFlightModel value) { UpdateFlightCommand updateFlightCommand = new UpdateFlightCommand(); updateFlightCommand.ClubFlightViewModel = value; var ressult = _mediator.Send(updateFlightCommand); return; }
public static Flight Map(this UpdateFlightCommand command) { return(new Flight() { Id = command.Id, Destination = command.Destination, FlightNumber = command.FlightNumber, Origin = command.Origin, Status = command.Status }); }
public ICommandResult Handle(UpdateFlightCommand command) { command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Ops, this flight is wrong!", command.Notifications)); } var flight = new Flight(command.IcaoCode, command.FlightNumber, command.IcaoCode + command.FlightNumber, command.Eet, command.Eobt, command.Departure, command.Arrival, ConvertTimes.EobtToDateTime(command.Eobt, DateTime.Now.AddDays(1)), command.AircraftType); _repository.Update(flight); return(new GenericCommandResult(true, "Flight updated!", flight)); }
public async Task <IActionResult> Put(int id, [FromBody] EnterFlightViewModel viewModel) { //The command class could be used as API Model too. //Otherwise if any non-business info should come from the front-end as a meaning of validation //it is better create a ApiModel UpdateFlightCommand updateFlightCommand = new UpdateFlightCommand() { Id = id, DepartureAirportId = viewModel.DepartureAirportId, DestinationAirportId = viewModel.DestinationAirportId, FlightTime = viewModel.FlightTime, TakeoffEffort = viewModel.TakeoffEffort }; await _mediator.Send(updateFlightCommand); ClearCache(); return(Ok()); }
public async Task <(bool Success, string FailReason)> AllPassengersBoardedAsync(AllPassengersBoardedRequest request) { var flight = await m_FlightsReadRepository.GetByIdAsync(request.FlightId); var updateCommand = new UpdateFlightCommand() { Destination = flight.Destination, FlightNumber = flight.FlightNumber, Id = flight.Id, Origin = flight.Origin, Status = FlightStatus.AllBoarded }; var result = await m_Mediator.Send(updateCommand); if (result.Success) { return(true, string.Empty); } return(false, result.Error); }
public async Task <IActionResult> UpdateFlight(UpdateFlightCommand updateFlightCommand) { await Mediator.Send(updateFlightCommand); return(NoContent()); }
public async Task <IActionResult> Update([FromBody] UpdateFlightCommand command) => Ok((await m_Mediator.Send(command)));