public IActionResult CancelTicket([FromBodyAttribute] cancelTicketRequest Request) { ErrorResponseOnCencel error = new ErrorResponseOnCencel(); if (!ModelState.IsValid || string.IsNullOrEmpty(Request.request.agentTxnId) || string.IsNullOrEmpty(Request.request.psgnToken) || string.IsNullOrEmpty(Request.request.reservationId)) { return(Ok(new Application_ResponseWrapper() { ResponseCode = "1000", ResponseMessage = "Invalid model", Status = "failed", ResponseResult = "" })); } if (string.IsNullOrEmpty(_irctcUrl) || string.IsNullOrEmpty(_irctc_userName) || string.IsNullOrEmpty(_irctc_password)) { return(Ok(new Application_ResponseWrapper() { ResponseCode = "1001", ResponseMessage = "No IRCTC configuration found", Status = "failed" })); } _irctcUrl = _irctcUrl + "tatktservices/cancel"; try { CommunicationLog("OxiRail", "cancelBookedTicket OUT->>" + JsonConvert.SerializeObject(Request).ToString(), Request.userSession); CancelTicketResponse Response = new CancelTicketResponse(); var response = _booking.CancelTicket(_irctcUrl, Request.request, Request.userSession, _authInfo); Response = (CancelTicketResponse)JsonConvert.DeserializeObject(response.ToString(), typeof(CancelTicketResponse)); if (Response.cancellationId != null) { CommunicationLog("OxiRail", "cancelBookedTicket IN->>" + JsonConvert.SerializeObject(Response).ToString(), Request.userSession); ITicketCancellationRepository objCan = new TicketCancellationRepository(_applicationDbContext); int[] psngrIndex = common.FindcharIndexInString(Request.request.psgnToken, 'Y'); IBookedTicketsRepository objBooked = new BookedTicketsRepository(_applicationDbContext); ITicketPassengersRepository psnger = new TicketPassengersRepository(_applicationDbContext); ICancelledTicketPassengersRepository PsngrLog = new CancelledTicketPassengersRepository(_applicationDbContext); var BookedTicket = objBooked.FindBy(x => x.pnrNumber == Response.pnrNo).SingleOrDefault(); List <TicketPassengers> PsngrList = psnger.FindBy(x => x.ticketOrderId == BookedTicket.ticketOrderId).OrderBy(x => x.Id).ToList <TicketPassengers>(); TicketCancellations objTicketCancel = objCan.AddCancelTicket(new TicketCancellations() { bookedTicketId = BookedTicket.Id, noOfPassenger = Convert.ToInt32(Response.noOfPsgn), ticketNumber = BookedTicket.ticketNumber, status = true, amountCollected = Convert.ToDecimal(Response.amountCollected), refundedAmount = Convert.ToDecimal(Response.refundAmount), cashDeducted = Convert.ToDecimal(Response.cashDeducted), cashCollected = Convert.ToDecimal(Response.amountCollected), amount = Convert.ToDecimal(Response.refundAmount), paymentGateways = 1, sessions = Request.userSession, date = DateTime.Now, cancelledDate = Response.cancelledDate }); objCan.Commit(); foreach (int index in psngrIndex) { long psngrId = PsngrList[index].Id;// To be inserted in Cancelled ticket Passenger objTicketCancel PsngrLog.Add(new CancelledTicketPassengers { ticketId = objTicketCancel.Id, passengerId = psngrId }); } PsngrLog.Commit(); return(Ok(new Application_ResponseWrapper() { ResponseCode = "0", ResponseMessage = "success", Status = "success", ResponseResult = Response })); } else { error = (ErrorResponseOnCencel)JsonConvert.DeserializeObject(response.ToString(), typeof(ErrorResponseOnCencel)); CommunicationLog("OxiRail", "cancelBookedTicket IN->>" + JsonConvert.SerializeObject(error).ToString(), Request.userSession); return(Ok(new Application_ResponseWrapper() { ResponseCode = "1000", ResponseMessage = error.message, Status = "Error", ResponseResult = "" })); } } catch (Exception e) { CommunicationLog("OxiRail", e.ToString(), Request.userSession); error.Dispose(); return(Ok(new Application_ResponseWrapper() { ResponseCode = "1000", ResponseMessage = "Api_Error", Status = "Error or IRCTC Service Down", ResponseResult = e })); } }