public ActionResult Edit(Passenger passenger) { if (ModelState.IsValid) { db.Entry(passenger).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(passenger)); }
public JsonResult BookTicket(string TrainId, string TrainSeatType, string DateOfJourney, string NameOfPassenger, string PanNumber, bool IsPaymentSuccessful) { var trainSeat = db.TrainSeats.FirstOrDefault(ts => ts.TrainId.Equals(TrainId) && ts.SeatType.Equals(TrainSeatType) && ts.IsReserved.Equals(false)); if (trainSeat != null) { var passengerInfo = new PassengerInformation { SeatNumber = trainSeat.SeatNumber, PanNumber = PanNumber, NameOfPassenger = NameOfPassenger, IsPaymentSuccessful = IsPaymentSuccessful, IsPaymentReturned = false, IsTicketCanceled = false }; db.PassengerInfo.Add(passengerInfo); db.SaveChanges(); var trainSeatReserve = new TrainSeat { Id = trainSeat.Id, IsReserved = true, SeatNumber = trainSeat.SeatNumber, SeatType = trainSeat.SeatType, TrainId = trainSeat.TrainId, TrainScheduledDateTime = trainSeat.TrainScheduledDateTime }; //db.Entry(trainSeatReserve).State = EntityState.Modified; db.Entry(trainSeat).CurrentValues.SetValues(trainSeatReserve); db.SaveChanges(); } return(Json(new { SeatNumber = trainSeat != null ? trainSeat.SeatNumber : "No seats available", PanNumber = PanNumber, NameOfPassenger = NameOfPassenger, IsPaymentSuccessful = IsPaymentSuccessful, IsPaymentReturned = false, IsTicketCanceled = false, Confirmed = trainSeat != null ? "Yes" : "No" }, JsonRequestBehavior.AllowGet)); }