コード例 #1
0
        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);
            }
        }
コード例 #2
0
 public ActionResult <Entity> Post([FromBody] Flight flight)
 {
     // Console.WriteLine("entro al try");
     try
     {
         var validator = new FlightValidator(flight);
         validator.Validate();
         FlightMapper     _flightMapper     = MapperFactory.createFlightMapper();
         FlightDTO        _flight           = _flightMapper.CreateDTO(flight);
         AddFlightCommand _addFlightCommand = CommandFactory.AddFlightCommand(_flight);
         _addFlightCommand.Execute();
         return(Ok(new { Message = "¡Vuelo creado con éxito!" }));
     }
     catch (ValidationErrorException ex)
     {
         return(BadRequest(new { ex.Message }));
     }
     catch (DbErrorException ex)
     {
         return(BadRequest(new { ex.Message }));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         return(null);
     }
 }