/// <summary> /// Logouts this instance. /// </summary> /// <param name="bookingId">The Booking ID.</param> /// <returns>Logout User Async</returns> public async Task <IActionResult> MyBookings(int?bookingId) { if (bookingId.HasValue) { MyBookingDescriptionViewModel model = await this.userDetailService.GetMyBookingDescriptionByBookingId(bookingId.Value); if (model.bookingFlightViewModel != null && model.bookingFlightViewModel.Count > 0) { model.ticketsViewModel = new List <TicketLCCResponse>(); foreach (var item in model.bookingFlightViewModel) { Ticket ticketRequest = new Ticket { EndUserIp = this.configuration.GetValue <string>("TBOCredentials:EndUserIp"), BookingId = Convert.ToInt64(item.TBOBookingId), PNR = item.PNR, TraceId = item.TraceId, TokenId = await this.tboController.GetTBOLoginToken() }; ApiResponse response = this.tboController.PostCustom( this.tboController.GetTboUrl(TboMethods.BookingDetails), JsonConvert.SerializeObject(ticketRequest, this.tboController.JsonIgnoreNullable), TboMethods.BookingDetails); if (response.IsSuccess) { TicketLCCResponse ticketLCCResponse = JsonConvert.DeserializeObject <TicketLCCResponse>(response.Response); model.ticketsViewModel.Add(ticketLCCResponse); } } model.ticketsViewModel = model.ticketsViewModel.OrderBy(x => DateTime.ParseExact(x.Response.FlightItinerary.Segments.FirstOrDefault().Origin.DepTime, "yyyy-MM-ddTHH:mm:ss", null)).ToList(); } return(this.View("MyBookingDetail", model)); } else { var claimInformation = this.HttpContext.User.Claims.FirstOrDefault(); if (claimInformation != null) { var userId = Convert.ToInt32(claimInformation.Value); List <MyBookingsListViewModel> myBookings = await this.userDetailService.GetDealBookingsByUserId(userId); return(this.View(myBookings)); } return(this.View(new List <MyBookingsListViewModel>())); } }
/// <summary> /// Posts the asynchronous. /// </summary> /// <param name="url">The URL.</param> /// <param name="content">The content.</param> /// <param name="methodName">Method Name</param> /// <returns> /// Post Request /// </returns> public HiTours.TBO.Models.ApiResponse PostCustom(string url, string content, string methodName) { HiTours.TBO.Models.ApiResponse result; string responseString = string.Empty; try { var httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; httpWebRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { streamWriter.Write(content); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { responseString = streamReader.ReadToEnd(); } result = new TBO.Models.ApiResponse { IsSuccess = true, Request = content, Response = responseString, Exception = string.Empty }; } catch (Exception ex) { result = new TBO.Models.ApiResponse { IsSuccess = false, Request = content, Response = ex.ToString(), Exception = ex.ToString() }; } this.CreateTBOLogs(result, url, methodName); return(result); }
/// <summary> /// Posts the asynchronous. /// </summary> /// <param name="result">The URL.</param> /// <param name="url">URL</param> /// <param name="methodName">The content.</param> public void CreateTBOLogs(TBO.Models.ApiResponse result, string url, string methodName) { try { if (this.configuration.GetValue <bool>("TBOCredentials:Logging")) { //// Logs Code Below string todayFolder = DateTime.Now.Date.ToString("dd/MM/yyyy"); string folderPath = Path.Combine(this.hostingEnvironment.WebRootPath, "Logs", "TBO", todayFolder); string fileName = string.Empty; string filePath = string.Empty; if (!Directory.Exists(folderPath)) { DirectoryInfo di = Directory.CreateDirectory(folderPath); } if (methodName == TboMethods.Authenticate) { fileName = "Login.Txt"; filePath = Path.Combine(folderPath, fileName); } else if (methodName == TboMethods.AgencyBalance) { fileName = "Balance.Txt"; filePath = Path.Combine(folderPath, fileName); } else { if (result.IsSuccess) { dynamic responseObject = JObject.Parse(result.Response); if (responseObject.Response != null) { fileName = responseObject.Response.TraceId.ToString() + ".Txt"; } else { responseObject = JObject.Parse(result.Request); if (responseObject.Response != null && responseObject.Response.TraceId != null) { fileName = responseObject.Response.TraceId.ToString() + ".Txt"; } else { fileName = "Exceptions.Txt"; } } } else { fileName = "Exceptions.Txt"; } filePath = Path.Combine(folderPath, fileName); } using (StreamWriter writer = System.IO.File.AppendText(filePath)) { writer.WriteLine("-----------------------------------------------------------------------------"); writer.WriteLine("Date : " + DateTime.Now.ToString()); writer.WriteLine("Request URL :" + url); writer.WriteLine("Method Name :" + methodName); writer.WriteLine(); writer.WriteLine("Request"); writer.WriteLine(this.FormatJson(result.Request)); writer.WriteLine(); writer.WriteLine("Response"); writer.WriteLine(this.FormatJson(result.Response)); } } } catch (Exception ex) { string filePath = Path.Combine(this.hostingEnvironment.WebRootPath, "Logs\\TBOError.txt"); using (StreamWriter writer = new StreamWriter(filePath, true)) { writer.WriteLine("-----------------------------------------------------------------------------"); writer.WriteLine("Date : " + DateTime.Now.ToString()); writer.WriteLine(); while (ex != null) { writer.WriteLine(ex.GetType().FullName); writer.WriteLine("Message : " + ex.Message); writer.WriteLine("StackTrace : " + ex.StackTrace); ex = ex.InnerException; } writer.WriteLine(); writer.WriteLine("URL : " + url); writer.WriteLine("Method : " + methodName); writer.WriteLine("Result : " + JsonConvert.SerializeObject(result)); } } }