public void CustomerFacadeCancelTicketMethod() { ILoggedInAdministratorFacade adminFacade = (ILoggedInAdministratorFacade)TestConfig.fcs.Login(AirlineProjectConfig.ADMIN_USERNAME, AirlineProjectConfig.ADMIN_PASSWORD, out ILoginToken adminToken); adminFacade.CreateNewAirline((LoginToken <Administrator>)adminToken, TestData.airline1); adminFacade.CreateNewCustomer((LoginToken <Administrator>)adminToken, TestData.customer1); Flight flight1 = new Flight(0, 0, TestData.argentinaID, TestData.barbadosID, TestData.futureDate1, TestData.futureDate2, 200); ILoggedInAirlineFacade airlineFacade1 = (ILoggedInAirlineFacade)TestConfig.fcs.Login(TestData.airline1.UserName, TestData.airline1.Password, out ILoginToken airlineToken1); airlineFacade1.CreateFlight((LoginToken <AirlineCompany>)airlineToken1, flight1); IAnonymousUserFacade anonymousFacade = (IAnonymousUserFacade)TestConfig.fcs.Login("", "", out ILoginToken anonymousToken); //Assert.AreEqual(200, anonymousFacade.GetFlight(flight1.ID).RemainingTickets); ILoggedInCustomerFacade customerFacade1 = (ILoggedInCustomerFacade)TestConfig.fcs.Login(TestData.customer1.UserName, TestData.customer1.Password, out ILoginToken customerToken1); Ticket ticket1 = customerFacade1.PurchaseTicket((LoginToken <Customer>)customerToken1, flight1); Assert.AreEqual(199, anonymousFacade.GetFlight(flight1.ID).RemainingTickets); customerFacade1.CancelTicket((LoginToken <Customer>)customerToken1, ticket1); Assert.AreEqual(200, anonymousFacade.GetFlight(flight1.ID).RemainingTickets); Assert.AreEqual(0, customerFacade1.GetAllMyFlights((LoginToken <Customer>)customerToken1).Count); }
public IHttpActionResult RemoveCustomer([FromUri] long customerId) { IHttpActionResult res = null; Ticket ticket = null; GetLoginToken(); if (customerLoginToken == null) { return(Unauthorized()); } FCS = FlyingCenterSystem.GetFlyingCenterSystemInstance(); ILoggedInCustomerFacade customerFacade = FCS.GetFacade(customerLoginToken) as ILoggedInCustomerFacade; try { ticket = customerFacade.GetTicketByCustomerId(customerLoginToken, customerId); if (ticket != null) { customerFacade.CancelTicket(customerLoginToken, ticket); res = Ok($"Ticket with customer Id = {customerId} not found"); } } catch (Exception e1) { res = BadRequest("Ticket hadn't been deleted " + e1.Message); } return(res); }
public IActionResult CancelTicket(long id) { LoginToken <Customer> customer_token = DesirializeToken(); try { Ticket ticket = _loggedInCustomerFacade.GetTicketById(customer_token, id); if (ticket == null) { return(NotFound()); } if (ticket.Flight.DepartureTime <= DateTime.Now.AddMinutes(-15)) { return(Forbid()); } ticket.Customer.User = customer_token.User.User; _loggedInCustomerFacade.CancelTicket(customer_token, ticket); } catch (WrongCustomerException) { return(Forbid()); } return(NoContent()); }
public async Task <ActionResult> CancelTicketPurchase([FromBody] TicketDTO ticketDTO) { LoginToken <Customer> token = GetLoginToken(); Ticket ticket = m_mapper.Map <Ticket>(ticketDTO); try { await Task.Run(() => m_facade.CancelTicket(token, ticket)); } catch (Exception ex) { return(StatusCode(403, $"{{ error: \"{ex.Message}\" }}")); } return(Ok()); }