Beispiel #1
0
        public static void Register(HttpConfiguration config)
        {
            try
            {
                // Web API configuration and services
                // Configure Web API to use only bearer token authentication.
                config.SuppressDefaultHostAuthentication();
                config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

                var cors = new EnableCorsAttribute("*", "*", "*");
                config.EnableCors(cors);

                // Web API routes
                config.MapHttpAttributeRoutes();

                config.Routes.MapHttpRoute(
                    name: "DefaultApi",
                    routeTemplate: "{controller}/{id}",
                    defaults: new { id = RouteParameter.Optional }
                    );
            }
            catch (Exception ex)
            {
                CatchError.Log4Net("ERROR", ex);
            }
        }
Beispiel #2
0
 public static List <Flight> GetAll()
 {
     try
     {
         using (var db = Configuration.Instance().ContextDB())
         {
             return(db.Flights.Include(x => x.ArrivalCity).Include(x => x.DepartureCity).ToList());
         }
     }
     catch (Exception ex)
     {
         CatchError.Log4Net("ERROR", ex);
         return(null);
     }
 }
Beispiel #3
0
 public static DateTime GetDateTimeNow()
 {
     try
     {
         using (var db = Utilities.Configuration.Instance().ContextDB())
         {
             var      dateQuery   = db.Database.SqlQuery <DateTime>("SELECT GETDATE() ");
             DateTime dateFromSql = dateQuery.AsEnumerable().First();
             return(dateFromSql);
         }
     }
     catch (Exception ex)
     {
         CatchError.Log4Net("ERROR", ex);
         return(DateTime.MinValue);
     }
 }
Beispiel #4
0
        public IHttpActionResult Update(Booking booking)
        {
            try
            {
                DaoBooking.Update(booking);

                var respuesta = new
                {
                    errorCode    = 0,
                    messageError = "Se actualizo correctamente"
                };

                return(Ok(respuesta));
            }
            catch (Exception ex)
            {
                CatchError.Log4Net("ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Beispiel #5
0
        public IHttpActionResult GetByHourFilter(FlightFilter filter)
        {
            try
            {
                var result = DaoFlight.GetByHour(filter);

                var respuesta = new
                {
                    errorCode    = 0,
                    messageError = "Consulta correcta.",
                    flights      = result
                };

                return(Ok(respuesta));
            }
            catch (Exception ex)
            {
                CatchError.Log4Net("ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Beispiel #6
0
        public IHttpActionResult GetByCode(CityFilter filter)
        {
            try
            {
                var result = DaoCity.GetByCode(filter.IATACode);

                var respuesta = new
                {
                    errorCode    = 0,
                    messageError = "Consulta correcta.",
                    city         = result
                };

                return(Ok(respuesta));
            }
            catch (Exception ex)
            {
                CatchError.Log4Net("ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Beispiel #7
0
        public IHttpActionResult Save(Booking booking)
        {
            try
            {
                booking.BookingNumber = RandomString(7);
                DaoBooking.Save(booking);

                var respuesta = new
                {
                    errorCode    = 0,
                    messageError = "Se guardo correctamente"
                };

                return(Ok(respuesta));
            }
            catch (Exception ex)
            {
                CatchError.Log4Net("ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Beispiel #8
0
        public IHttpActionResult GetById(int id)
        {
            try
            {
                var result = DaoBooking.GetById(id);

                var respuesta = new
                {
                    errorCode    = 0,
                    messageError = "Consulta correcta.",
                    booking      = result
                };

                return(Ok(respuesta));
            }
            catch (Exception ex)
            {
                CatchError.Log4Net("ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Beispiel #9
0
        public IHttpActionResult Save(Flight flight)
        {
            try
            {
                var departureCity = flight.DepartureCity;
                var arrivalCity   = flight.ArrivalCity;
                DaoFlight.Save(flight);

                var respuesta = new
                {
                    errorCode    = 0,
                    messageError = $"Se guardo correctamente el vuelo {flight.FlightNumber} de {departureCity.IATACode} a {arrivalCity.IATACode}.",
                    flight       = flight
                };

                return(Ok(respuesta));
            }
            catch (Exception ex)
            {
                CatchError.Log4Net("ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }