public string GetBookResult(EmployeeModel employee, CustomFlightDetailModel iter, string tripid) { BookResponse bookResponse; string Result = ""; try { WebRequest request = WebRequest.Create("http://online-corporate-traveller.amadeus.com/live/V17_2_0/webapi/api/FlightBook/RequestFlightBook1"); request.Method = "POST"; request.ContentType = "application/json"; Stream dataStream = request.GetRequestStream(); // getJson(date, direct, type, quantity, origin, desti); // JObject abc = new SearchRequest().GetJson(); byte[] byteArray = Encoding.UTF8.GetBytes(new BookingJsons().GetBookRequest(employee, iter, tripid, employee.TokenID)); request.ContentLength = byteArray.Length; dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (Stream receiveStream = Flight_Availability.GetStreamForResponse(response)) { StreamReader sr = new StreamReader(receiveStream); string responseFromServer = sr.ReadToEnd(); bookResponse = JsonConvert.DeserializeObject <BookResponse>(responseFromServer); if (bookResponse.ResultDescription != "") { Result = bookResponse.ResultDescription; } else { var c = bookResponse.PricedItinerary.FirstOrDefault().Flights.FirstOrDefault(); string Message = "Origin :" + c.DepartureCityName + " Desitination : " + bookResponse.PricedItinerary.FirstOrDefault().Flights.LastOrDefault().ArrivalCityName + " flight number :" + c.FlightNumber + " FareType : " + c.FareType + " ArrivalDate: " + c.ArrivalDate + "DepartureDate : " + c.DepartureDate + "DepartureTime :" + c.DepartureTime; // SendDetail(Message, employee.Email); //string Result = " DepCity : " + c.Flights.FirstOrDefault().DepartureCityName + " ArrivalCity : " + c.Flights.LastOrDefault().ArrivalCityName; Result = "Confirmed.The detail has been mailed to you on " + employee.Email; } } dataStream.Close(); response.Close(); } catch (Exception ex) { throw ex; } return(Result); }
public string BookFlight(JObject entities, string[] codes) { string Result = ""; SubmitResponse submitResponse; string x = ""; try { var bot = new EmptyBot(); List <CustomFlightDetailModel> detail = bot.GetIteneraries(); // new LoginIntent().Login(entities); List <CustomFlightDetailModel> iterlst = new List <CustomFlightDetailModel>(); EmployeeModel employee = bot.GiveEmployee(); if (entities.GetValue("FlightNumber") == null && codes.Length >= 1) { foreach (var c in codes) { string code = c.Remove(0, 3); iterlst.Add((from d in detail where d.FlightNumber == code select d).FirstOrDefault()); } } else { string alcode = entities.GetValue("FlightNumber").FirstOrDefault().ToString().Substring(0, 2); string fn = entities.GetValue("FlightNumber").FirstOrDefault().ToString().Substring(2); iterlst = (from d in detail where d.FlightNumber == fn select d).ToList(); } WebRequest request = WebRequest.Create("http://online-corporate-traveller.amadeus.com/live/V17_2_0/webapi/api/SBTMobile/SubmitFlightRequest"); request.Method = "POST"; request.ContentType = "application/json"; Stream dataStream = request.GetRequestStream(); // getJson(date, direct, type, quantity, origin, desti); // JObject abc = new SearchRequest().GetJson(); x = new BookingJsons().GetSubmitBookRequest(iterlst, employee.FirstName, employee.OffId, employee.CustId, employee.TokenID, employee.DeviceId); byte[] byteArray = Encoding.UTF8.GetBytes(x); request.ContentLength = byteArray.Length; dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (Stream receiveStream = Flight_Availability.GetStreamForResponse(response)) { StreamReader sr = new StreamReader(receiveStream); string responseFromServer = sr.ReadToEnd(); submitResponse = JsonConvert.DeserializeObject <SubmitResponse>(responseFromServer); if (employee.Approval_mail == "FALSE") { Result = GetBookResult(employee, iterlst.FirstOrDefault(), submitResponse.TripID); } else { //SendDetail("TripId : " + submitResponse.TripID, employee.Email); //return "Flight Details / Booking Details sent with tripid :" Result = "Flight Details/Booking Details sent with tripid : " + submitResponse.TripID + " successfully on " + employee.Email; // await _myStorage.DeleteAsync(new string[] { (DeviceId + "employee"), (DeviceId + "pricedIteneraries") },cancellationToken); } } dataStream.Close(); response.Close(); } catch (Exception ex) { // Result = ex.StackTrace + " " + x; } return(Result); }