public string Get(Guid id) { Ticket t = TicketStorage.getInstance().getPassengerTicket(id); if (t == null) { return("0"); //passenger with this id didn't buy ticket } else { string json = JsonConvert.SerializeObject(t); return(json); } }
public string Get(int id, string ps, string fl) { Flight f = JsonConvert.DeserializeObject <Flight>(fl); FlightPassenger p = JsonConvert.DeserializeObject <FlightPassenger>(ps); int passnumber = 0; //number of passengers in the plain int flightID = f.reisNumber; string ticketJson = null; string scheduleData = ScheduleHttpClient.ScheduleRequest(flightID); int scheduleInt = Convert.ToInt32(scheduleData); if (scheduleInt >= 0) { passnumber = scheduleInt; if (TicketStorage.getInstance().fingPassenger(p.Passport.Guid)) { return("2"); //passenger with this id has already buy a ticket } else { if (TicketStorage.getInstance().flightCount(flightID) < passnumber) { Ticket t = new Ticket(p.Passport.Guid, flightID, f.to, p.Passport.Surname, p.Passport.GivenNames, p.Passport.Sex); TicketStorage.getInstance().Add(t); ticketJson = JsonConvert.SerializeObject(t); return(ticketJson); } else { return("3"); //there are no more tickets for this flight } } } else { if (scheduleInt == -3) { return("4"); //flight registration } else if (scheduleInt == -4 || scheduleInt == -2 || scheduleInt == -1) { return("1"); //flight to this city doesn't exist or plain has already landed or there is no plain for this flight - can not buy a ticket } else { return("1"); } } }