//    [HttpPost]
        // public ActionResult Edit([Bind(Include="BOOKINGID,SESSIONID,BOOKEDSEATS,Emailid")] Booking booking)
        public ActionResult Editdetails()
        {
            float price = 0;
              /// Booking booking = new Booking();
               Booking booking1=new Booking();
            Booking currentbooking = new Booking();
            Session session = new Session();
            if (Session["editdetails"] != null)
            {
               /* FormCollection form = (FormCollection)Session["editdetails"];
               string s= form.Get(0).ToString();
                int bookingid=int.Parse(form.Get(0).ToString());
                int sessionid = int.Parse(form.Get(1).ToString());
                int newseats = int.Parse(form.Get(2).ToString());
                string emailid= form.Get(3).ToString();*/
                booking1= (Booking)Session["editdetails"];
                int bookingid = (int)booking1.BOOKINGID;
                int sessionid = (int)booking1.SESSIONID;
                int newseats = (int)booking1.BOOKEDSEATS;
                string emailid = (string)booking1.Emailid;
                foreach (Booking b in db.Bookings)
                {
                    if (bookingid == (int)b.BOOKINGID)
                    {
                        currentbooking=b;
                        break;
                    }
                }

                foreach (Session sess in db.Sessions)
                {
                    if (sessionid== (int)sess.SESSIONID)
                    {
                        session=sess;
                        break;
                    }
                }

                int currentseats = (int)currentbooking.BOOKEDSEATS;

                if (newseats > 20)
                {
                    ModelState.AddModelError("Bookingerror", "bookeseats cannot be greater than maximum seats ");
                }

                else if (newseats <= currentseats || newseats <= 20)
                {

                  float price1= (float)session.Movie.Price;
                  currentbooking.PRICE = price1 * newseats;
                    //seats are added to booking
                    if (currentseats < newseats)
                    {
                        session.SEAT = (int)session.SEAT - (newseats - currentseats);
                        currentbooking.BOOKEDSEATS = newseats;
                    }
                        //new seats are less means seats deleted from booking
                    else if (currentseats > newseats)
                    {
                        session.SEAT = (int)session.SEAT + (currentseats - newseats);
                        currentbooking.BOOKEDSEATS = newseats;

                    }

                }

                if (ModelState.IsValid)
                {
                    db.Entry(currentbooking).State = EntityState.Modified;
                    db.Entry(session).State = EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("index");

                }
            }
            ViewBag.SESSIONID = new SelectList(db.Sessions, "SESSIONID", "DAY", currentbooking.SESSIONID);
            return View(currentbooking);
        }
        // POST: /Booking/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        //[HttpPost]
        // [ValidateAntiForgeryToken]
        // public ActionResult Create([Bind(Include="BOOKINGID,SESSIONID,BOOKEDSEATS,Emailid")] Booking booking)
        // public ActionResult Createpayment()
        public ActionResult Create()
        {
            List<Booking>  lstBooking=new List<Booking>();
              string sessid="",bookseats,bookngprice;
              int[] ids=new int[100], bookingseats=new int[100];
              float[] bookingprices=new float[100];
              string[] id, bookingseat, bookingprice,bookingform;
             string bookform;

              ids[0] = 0;
            bookingseats[0] = 0;
            bookingprices[0] = 0;
              Booking booking=null;
              if (Session["booking"] != null)
              {
                bookform = (string)Session["bookingdetails"];
                FormCollection f = (FormCollection)Session["booking"];
                bookingform = bookform.Split('>');
                string status = bookingform[2].ToString();
                sessid = f.Get(0).ToString();
                 bookseats = f.Get(3).ToString();
                bookngprice = f.Get(4).ToString();
                string email = bookingform[1].ToString();
              //means multiple booking
                  if (status.Equals("yes"))
                {

                    sessid = f.Get(0).ToString();
                    id = sessid.Split(',');
                    bookingseat = bookseats.Split(',');
                       bookingprice = bookngprice.Split(',');
                    for (int i = 0; i < id.Length; i++)
                    {
                        ids[i] = int.Parse(id[i].ToString());
                        bookingseats[i] = int.Parse(bookingseat[i].ToString());
                        bookingprices[i] = float.Parse(bookingprice[i].ToString());

                    }

                    for (int i = 0; i < ids.Length; i++)
                    {
                        if (ids != null)
                        {
                            foreach (Session s in db.Sessions)
                            {
                                if (s.SESSIONID == ids[i])
                                {
                                    if (bookingseats[i] <= 20)
                                    {
                                        if (bookingseats[i] <= s.SEAT)
                                        {
                                            booking = new Booking();
                                            booking.BOOKEDSEATS = bookingseats[i];
                                            booking.SESSIONID = s.SESSIONID;
                                            int seats = (int)s.SEAT;
                                            s.SEAT = seats - bookingseats[i];
                                            int booked = (int)booking.BOOKEDSEATS;
                                            booking.PRICE = bookingprices[i] * booked;
                                            booking.Emailid = email;
                                            lstBooking.Add(booking);
                                            if (ModelState.IsValid)
                                            {
                                                db.Bookings.Add(booking);
                                                db.Entry(s).State = EntityState.Modified;
                                                db.UPDSESSIONSEATS((int)s.SEAT, (int)s.SESSIONID);
                                                db.SaveChanges();
                                                //length of number of elements in the session
                                                if (i.Equals(id.Length-1))
                                                {
                                                    Session["currentbooking"] = null;
                                                    Session["currentbooking"] = lstBooking;
                                                    return RedirectToAction("Index");
                                                  //  break;
                                                }
                                            }
                                        }

                                    }

                                }

                            }

                        }

                    }
                      }

                  else if (status.Equals("no"))
                  {
                      string[] singlebookingdetails = bookingform[0].ToString().Split('|');
                      string session_id=singlebookingdetails[0];
                       string booking_seat =singlebookingdetails[1];
                      string  bookng_price=singlebookingdetails[2];

                  //    string[] bookingdet = singlebookingdetails[0].ToString().Split('|');

                      int singlessessionid = int.Parse(session_id);
                      int singlebookingseats = int.Parse(booking_seat);
                      float singlebookingprice = float.Parse(bookng_price);
                      foreach (Session sess in db.Sessions)
                      {
                          if (sess.SESSIONID ==singlessessionid)
                          {
                              if (singlebookingseats <= 20)
                              {
                                  if (singlebookingseats <=sess.SEAT)
                                  {
                                      booking = new Booking();
                                     booking.BOOKEDSEATS=singlebookingseats;
                                      int booked = (int)booking.BOOKEDSEATS;
                                      booking.PRICE = singlebookingprice * booked;
                                      booking.Emailid = email;
                                      int seats = (int)sess.SEAT;
                                      sess.SEAT = seats - booked;
                                      booking.SESSIONID = sess.SESSIONID;
                                      booking.Emailid = email;
                                      lstBooking.Add(booking);
                                      if (ModelState.IsValid)
                                      {
                                          db.Bookings.Add(booking);
                                          db.Entry(sess).State = EntityState.Modified;
                                          db.UPDSESSIONSEATS((int) sess.SEAT,(int)sess.SESSIONID);
                                          db.SaveChanges();
                                          Session["currentbooking"] = null;
                                          Session["currentbooking"]=lstBooking;
                                          return RedirectToAction("Index");
                                      }
                                  }

                              }
                          }
                      }
                  }

               /*   if (ModelState.IsValid)
                  {
                      db.Bookings.Add(booking);
                      db.SaveChanges();
                      Session["booking"] = booking;

                  }*/
              }
            ViewBag.SESSIONID = new SelectList(db.Sessions, "SESSIONID", "DAY", booking.SESSIONID);

            return View(booking);
        }