public ActionResult Create(tBooking tbooking)
        {
            if (ModelState.IsValid)
            {
                db.tBooking.Add(tbooking);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.tScheduleId = new SelectList(db.tSchedule, "tScheduleId", "tScheduleId");
            return View();
        }
        public string AddToBooking(string scheduleid, string sectionid, string data)
        {
            int BookingDelayTime = Convert.ToInt32(System.Web.Configuration.WebConfigurationManager.AppSettings["BookingDelayTime"]);
            int schid = Convert.ToInt32(scheduleid);
            int secid = Convert.ToInt32(sectionid);
            var items = data.Split(',');

            var schedule = db.tSchedule.Single(a => a.tScheduleId == schid);
            var section = db.tSection.Single(a => a.tSectionId == secid );
            var product = db.Albums.Single(a => a.AlbumId == schedule.AlbumId);
            var cart = ShoppingCart.GetCart(this.HttpContext);
            string cartid = cart.GetCartId(this.HttpContext); //CartSessionKey

            foreach (string item in items)
            {
                var seat = db.tSeat.Single(a => a.tSectionId == section.tSectionId && a.Code == item);
                tBooking b = new tBooking
                {
                    ExpiryTime = DateTime.Now.AddMinutes(BookingDelayTime),
                    OrderDetailId=0,
                    tScheduleId = schedule.tScheduleId,
                    tSeatId = seat.tSeatId,
                    Pax = seat.Capacity,
                    CartId = cartid
                };
                db.tBooking.Add(b);
                //create cart item
                 //cart.AddToCartFromBooking(b);
                var cartitem = new Cart
                {
                    AlbumId = schedule.AlbumId,
                    CartId = cartid,
                    Count = b.Pax,
                    DateCreated = DateTime.Now,
                    t_ExpireTime = b.ExpiryTime,
                    t_Price = 1,
                    t_SeatClass = seat.tSeatClassId.ToString(),
                    t_SeatCode = seat.Code

                };
                db.Carts.Add(cartitem);

            }
                db.SaveChanges();

            return "PASS";
        }
Example #3
0
 public void AddToCartFromBooking(tBooking book)
 {
     //var books = storeDB.tBooking.Where(a => a.CartId == ShoppingCartId);
     //foreach (tBooking book in books.ToList())
     //{
         //var sch = storeDB.tSchedule.Single(a=>a.tScheduleId == book.tScheduleId);
         var cartItem = new Cart
         {
             AlbumId = book.tSchedule.AlbumId,
             CartId = ShoppingCartId,
             Count = book.Pax,
             DateCreated = DateTime.Now,
             t_ExpireTime = book.ExpiryTime,
             t_Price = 1,
             //t_SeatClass = book.
         };
         storeDB.Carts.Add(cartItem);
     //}
     //storeDB.SaveChanges();
 }