public ActionResult Create(Passenger passenger)
        {
            if (ModelState.IsValid)
            {
                db.Passengers.Add(passenger);
                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));
        }
Esempio n. 3
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (IrctcDbContext db = new IrctcDbContext())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile {
                            UserName = model.UserName
                        });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }