public IHttpActionResult CreateNewAirlineCompany([FromBody] HTTPAirlineCompany airlineCompany) { if (airlineCompany.AirlineName == null | airlineCompany.Username == null | airlineCompany.Password == null | airlineCompany.CountryID <= 0) { return(BadRequest()); } LoginToken <Administrator> token = (LoginToken <Administrator>)Request.Properties["User"]; LoggedInAdministratorFacade facade = (LoggedInAdministratorFacade)(FlyingCenterSystem.GetFlyingCenterSystem().GetFacade(token)); try { facade.CreateNewAirline(token, new AirlineCompany(-1, airlineCompany.AirlineName, airlineCompany.Username, airlineCompany.Password, airlineCompany.CountryID)); } catch (UsernameAlreadyExistsException) { return(StatusCode(HttpStatusCode.Conflict)); } return(Ok()); }
public IHttpActionResult UpdateAirlineCompany(int airlineCompanyID, [FromBody] HTTPAirlineCompany airlineCompany) { if (airlineCompany.AirlineName == null & airlineCompany.Username == null & airlineCompany.Password == null & airlineCompany.CountryID <= 0) { return(BadRequest()); } LoginToken <Administrator> token = (LoginToken <Administrator>)Request.Properties["User"]; LoggedInAdministratorFacade facade = (LoggedInAdministratorFacade)(FlyingCenterSystem.GetFlyingCenterSystem().GetFacade(token)); AirlineCompany original = facade._airlineDAO.Get(airlineCompanyID); HTTPAirlineCompany tempAirline = new HTTPAirlineCompany(original); if (airlineCompany.AirlineName != null) { tempAirline.AirlineName = airlineCompany.AirlineName; } if (airlineCompany.Username != null) { tempAirline.Username = airlineCompany.Username; } if (airlineCompany.Password != null) { tempAirline.Password = airlineCompany.Password; } if (airlineCompany.CountryID > 0) { tempAirline.CountryID = airlineCompany.CountryID; } try { facade.UpdateAirlineDetails(token, new AirlineCompany(airlineCompanyID, tempAirline.AirlineName, tempAirline.Username, tempAirline.Password, tempAirline.CountryID)); } catch (UsernameAlreadyExistsException) { return(StatusCode(HttpStatusCode.Conflict)); } return(Ok()); }