public IHttpActionResult CancelFlight(Flight flight) { try { LoginToken <AirlineCompany> airlineToken = helpClass.GetAirlineToken(); if (airlineCompanyFacade.GetFlightById((int)flight.ID) == null) { return(NotFound()); } airlineCompanyFacade.CancelFlight(airlineToken, flight); return(Ok(airlineCompanyFacade.GetFlightById((int)flight.ID))); } catch (Exception) { return(BadRequest()); } }
public void PurchaseTicket() { Flight additionalFlight = new Flight(1, 1, 1, new DateTime(2000, 01, 01), new DateTime(2000, 01, 01), 1); additionalFlight.Id = 1; customerFacade.PurchaseTicket(customer_token, additionalFlight); Flight new_flight = airlineFacade.GetFlightById(1); Assert.AreEqual(additionalFlight, new_flight); }
public IHttpActionResult CancelFlight(int id) { GetLoginToken(); try { Flight flight = airlineFacade.GetFlightById(id); airlineFacade.CancelFlight(loginToken, flight); if (airlineFacade.GetFlightById(id).Id == 0 && flight.Id != 0) { return(Ok()); } return(NotFound()); } catch (Exception) { return(BadRequest()); } }
public void AirlineFacade_UpdateFlight() { LoggedInAirlineFacade facade = FlyingCenterSystem.GetInstance().Login(TestResource.AIRLINE_USERNAME, TestResource.AIRLINE_PASSWORD, out LoginTokenBase login) as LoggedInAirlineFacade; Flight flight = facade.GetFlightById(38); flight.DestinationCountryCode = 1; facade.UpdateFlight(login as LoginToken <AirlineCompany>, flight); }
public IHttpActionResult UpdateAirlineCompany(int flightID, [FromBody] HTTPFlight flight) { if ((flight.AirlineCompanyID <= 0 & flight.OriginCountryID <= 0 & flight.DestinationCountryID <= 0 & flight.DepartureTime == null & flight.LandingTime == null & flight.RemainingTickets < 0 & flight.MaxTickets <= 0)) { return(BadRequest()); } LoginToken <AirlineCompany> token = (LoginToken <AirlineCompany>)Request.Properties["User"]; LoggedInAirlineFacade facade = (LoggedInAirlineFacade)(FlyingCenterSystem.GetFlyingCenterSystem().GetFacade(token)); Flight original = facade.GetFlightById(flightID); if (!CheckUpdateFlightInput(original, flight, token, facade)) { return(BadRequest()); } HTTPFlight tempFlight = new HTTPFlight(original); if (flight.AirlineCompanyID > 0) { tempFlight.AirlineCompanyID = flight.AirlineCompanyID; } if (flight.OriginCountryID > 0) { tempFlight.OriginCountryID = flight.OriginCountryID; } if (flight.DestinationCountryID > 0) { tempFlight.DestinationCountryID = flight.DestinationCountryID; } if (flight.DepartureTime != DateTime.MinValue) { tempFlight.DepartureTime = flight.DepartureTime; } if (flight.LandingTime != DateTime.MinValue) { tempFlight.LandingTime = flight.LandingTime; } if (flight.RemainingTickets > 0) { tempFlight.RemainingTickets = flight.RemainingTickets; } if (flight.MaxTickets > 0) { tempFlight.MaxTickets = flight.MaxTickets; } facade.UpdateFlight(token, new Flight(flightID, tempFlight.AirlineCompanyID, tempFlight.OriginCountryID, tempFlight.DestinationCountryID, tempFlight.DepartureTime, tempFlight.LandingTime, tempFlight.RemainingTickets, tempFlight.MaxTickets)); return(Ok()); }
public IHttpActionResult CancelFlight([FromUri] int id) { GetLoginToken(); if (AirLineToken != null) { Flight flight = F.GetFlightById(id); F.CancelFlight(AirLineToken, flight); return(Ok($"Flight:{flight.ID} airline company:{flight.AirLineCompanyID} has been canceled!")); } return(NotFound()); }
public IHttpActionResult CancelFlight([FromUri] int id) { LoginToken <AirlineCompany> airlineToken = (LoginToken <AirlineCompany>)Request.Properties["airlineToken"]; LoggedInAirlineFacade airlineFacade = (LoggedInAirlineFacade)Request.Properties["airlineFacade"]; Flight flight = airlineFacade.GetFlightById(id); if (flight == null || flight.ID <= 0) { return(NotFound()); } airlineFacade.CancelFlight(airlineToken, flight); return(Ok(flight)); }
public IHttpActionResult CancelFlight([FromUri] int flightID) { LoginToken <AirlineCompany> token = (LoginToken <AirlineCompany>)Request.Properties["User"]; LoggedInAirlineFacade facade = (LoggedInAirlineFacade)(FlyingCenterSystem.GetFlyingCenterSystem().GetFacade(token)); Flight flight = facade.GetFlightById(flightID); if (flight == null) { return(BadRequest()); } else if (flight.AirlineCompanyID != token.User.ID) { return(Unauthorized()); } facade.CancelFlight(token, flight); return(Ok()); }
public async Task <ActionResult <Flight> > GetFlightById(int flight_id) { FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password, out LoginToken <Object> l, out FacadeBase f); facade = f as LoggedInAirlineFacade; Flight result = null; try { result = await Task.Run(() => facade.GetFlightById(flight_id)); } catch (IllegalFlightParameter ex) { return(StatusCode(400, $"{{ error: \"{ex.Message}\" }}")); } if (result.Id == 0) { return(StatusCode(204, $"{{there is no flight with the id \"{result.Id}\"}}")); } return(Ok(result)); }
public IHttpActionResult UpdateFlight([FromBody] Flight flight) { bool isAuthorized = false; bool isUpdated = false; bool isFound = false; Action act = () => { isAuthorized = GetInternalLoginTokenInternal <AirlineCompany>(out LoginToken <AirlineCompany> loginTokenAirline); if (isAuthorized) { isUpdated = _loggedInAirlineFacade.UpdateFlight(loginTokenAirline, flight, out isFound); } }; ProcessExceptions(act); if (!isAuthorized) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, $"Sorry, but you're not an Airline Company. Your accsess is denied."))); } if (!isFound) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"Sorry, but the flight number \"{flight.ID}\" can't be update beause it don't exists in the system in the first place."))); } if (!isUpdated) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotModified, $"Sorry, but the flight number \"{flight.ID}\" doesn't updated."))); } return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, $"The flight number \"{flight.ID}\" has been updated. Now it seems like that: \n\n {_loggedInAirlineFacade.GetFlightById(flight.ID)}\n\nEnjoy it!"))); }