public async Task <ActionResult> AddPassenger(PassengerDetail e, Bookingdetails booking)
        {
            int    id    = (int)TempData.Peek("Tno");
            string email = (string)TempData.Peek("mail");

            e.TrainNo = id;
            e.EmailId = email;

            PassengerDetail Passobj = new PassengerDetail();

            using (var httpClient = new HttpClient())
            {
                StringContent content = new StringContent(JsonConvert.SerializeObject(e), Encoding.UTF8, "application/json");

                using (var response = await httpClient.PostAsync("https://localhost:44337/api/PassengerDetails", content))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    if (apiResponse != null)
                    {
                        Passobj = JsonConvert.DeserializeObject <PassengerDetail>(apiResponse);
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> AddBookingDetail(Bookingdetails booking, TrainDetail train, Register register)
        {
            string email  = (string)TempData.Peek("mail");
            int    id     = (int)TempData.Peek("Tno");
            string from   = (string)TempData.Peek("Tf");
            string to     = (string)TempData.Peek("Tt");
            int    ClassA = (int)TempData.Peek("classA");
            int    ClassB = (int)TempData.Peek("classB");
            int    ClassC = (int)TempData.Peek("classC");

            booking.FromStation = from;
            booking.TrainNo     = id;
            booking.ToStation   = to;
            train.SeatAvailA    = ClassA - booking.NoOfSeats;
            train.SeatAvailB    = ClassB - booking.NoOfSeats;
            train.SeatAvailC    = ClassC - booking.NoOfSeats;


            using (var httpClient = new HttpClient())
            {
                StringContent content = new StringContent(JsonConvert.SerializeObject(booking), Encoding.UTF8, "application/json");

                using (var response = await httpClient.PostAsync("https://localhost:44381/api/BookingDetails", content))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    book = JsonConvert.DeserializeObject <Bookingdetails>(apiResponse);
                }
            }
            return(RedirectToAction("BookingDetails"));
        }
 public bool DateCheck(Bookingdetails book)
 {
     if (book.JourneyDate < DateTime.Today)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
        public ShowInfo BookTickets(BookingInformation bookinginformation)
        {
            Bookingdetails obj = new Bookingdetails();

            Shows obj1    = new Shows();
            var   showobj = (from s in context.Shows where s.ShowId == bookinginformation.ShowId select s).FirstOrDefault();



            obj.Customerid    = bookinginformation.CustomerId;
            obj.Showid        = bookinginformation.ShowId;
            obj.Paymentmethod = bookinginformation.Paymentmode;
            obj.Paymentdate   = DateTime.Now;
            obj.Totalprice    = bookinginformation.Seatno.Length * (int)showobj.Price;
            obj.Paymenttime   = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);

            context.Bookingdetails.Add(obj);
            context.SaveChanges();

            //--------------------------------------------------
            Bookedseat temp;

            foreach (string seat in bookinginformation.Seatno)
            {
                temp = new Bookedseat()
                {
                    Seatno = seat, Bookingid = obj.Bookingid
                };
                context.Bookedseat.Add(temp);
            }
            showobj.BookedSeat += bookinginformation.Seatno.Length;
            context.SaveChanges();

            var ticketNosForInvoice = (from b in context.Bookedseat where b.Bookingid == obj.Bookingid select b).ToArray();
            var info = (from s in context.Shows
                        join m in context.Multiplex on s.MultiplexId equals m.MultiplexId
                        join h in context.MultiplexHall on m.MultiplexId equals h.MultiplexId
                        where s.ShowId == showobj.ShowId
                        select new ShowInfo()
            {
                MultiplexName = m.MultiplexName, HallName = h.HallName
            }).FirstOrDefault();

            for (int i = 0; i < ticketNosForInvoice.Length; i++)
            {
                ticketNosForInvoice[i].Booking = null;
            }
            info.Seats = ticketNosForInvoice;
            var moviename = (from s in context.Shows join m in context.Movie on s.MovieId equals m.MovieId where s.ShowId == showobj.ShowId select m.MovieName).FirstOrDefault();

            info.MovieName = moviename;
            return(info);
        }
        // [ActionName("DeleteEmployee")]
        public async Task <ActionResult> CancelTicket(Bookingdetails book)
        {
            int BookingId = Convert.ToInt32(TempData["BookingId"]);

            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.DeleteAsync("https://localhost:44381/api/BookingDetails/" + BookingId))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();
                }
            }

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> GetBookById(int id)
        {
            List <Bookingdetails> book = new List <Bookingdetails>();

            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.GetAsync("https://localhost:44381/api/BookingDetails/" + id))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    book = JsonConvert.DeserializeObject <List <Bookingdetails> >(apiResponse);
                }
            }
            return(View(book));
        }
        public async Task <ActionResult> CancelTicket(int id)
        {
            TempData["BookingId"] = id;
            Bookingdetails e = new Bookingdetails();

            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.GetAsync("https://localhost:44381/api/BookingDetails" + id))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    e = JsonConvert.DeserializeObject <Bookingdetails>(apiResponse);
                }
            }
            return(View(e));
        }