예제 #1
0
        public async Task <IActionResult> Post([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

            EnterFlightCommand enterFlightCommand = new EnterFlightCommand()
            {
                DepartureAirportId   = viewModel.DepartureAirportId,
                DestinationAirportId = viewModel.DestinationAirportId,
                FlightTime           = viewModel.FlightTime,
                TakeoffEffort        = viewModel.TakeoffEffort
            };

            int commandResultEntityId = await _mediator.Send(enterFlightCommand);

            if (commandResultEntityId <= 0)
            {
                return((IActionResult)BadRequest());
            }

            ClearCache();

            return(CreatedAtAction("Get", new { id = commandResultEntityId }, null));
        }
예제 #2
0
        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());
        }