public ActionResult Book(string dateString) { DateTime date; bool parseSuccesful = DateTime.TryParse(dateString, out date); if(!parseSuccesful) { return RedirectToAction("Index"); } //gets all jazz tickets for an event List<Jazz> JazzActs = repo.GetJazzActsByDay(date); Jazz passePartoutWeekend = repo.GetPassePartoutWeekend(); Jazz passePartoutDay = repo.GetPassePartoutDay(date); //converts jazz's into displayrecords OrderItem weekend = new OrderItem(passePartoutWeekend); OrderItem day = new OrderItem(passePartoutDay); List<OrderItem> events = new List<OrderItem>(); foreach (Jazz jazz in JazzActs) { OrderItem oi = new OrderItem(jazz); events.Add(oi); } JazzBook jazzBook = new JazzBook(day, weekend, events); //string hall = ((Jazz)dr.Event).Hall; return View(jazzBook); }
public ActionResult AddToSession(JazzBook FormResponse) { //parameter could possably be changed but i leave it here cause of problems in the past JazzBook book = FormResponse; CartModel cart; if((CartModel)Session["Cart"] == null) { cart = new CartModel(); } else { cart = (CartModel)Session["Cart"]; } //adds the passe-partouts if they are selected by customer if (book.DayPassePartout.Amount > 0) { book.DayPassePartout.Event = repo.GetJazzByID(book.DayPassePartout.Event.ID); cart.AddOrderItem(book.DayPassePartout); } if (book.WeekendPassePartout.Amount > 0) { book.WeekendPassePartout.Event = repo.GetJazzByID(book.WeekendPassePartout.Event.ID); cart.AddOrderItem(book.WeekendPassePartout); } //adds other jazz's if selected by customer foreach (OrderItem oi in book.DayEvents) { if (oi.Amount > 0) { oi.Event = repo.GetJazzByID(oi.Event.ID); cart.AddOrderItem(oi); } } Session["Cart"] = cart; //send user to basket after things are added to basket return RedirectToAction("Index", "Cart"); #region OLD DO NOT USE addToSession copy with extra documentation ////put this at the end of your book/reservation/buy post method ActionResult and add your records to session basket as described below ////please use the complete thing so it works the same in all places ////I use this method instead of "+=" because you can only use "+=" if there is already something in the cart ////and using this method you can also check if the contents of the cart are valid ////List that will be the new contents of the cart //List<Record> sessionBasket = new List<Record>(); ////you can put your records in like sessionBasket.Add(new Record(eventID, eventType); ////check if session contains records if so add them to new cart contents //try //{ // //adds valid records to sessionBasket // List<Record> basket = (List<Record>)Session["Cart"]; // foreach (Record record in basket) // { // sessionBasket.Add(record); // } //} //catch //{ // //when session contains invalid values it is cleared // Session["Cart"] = null; //} //finally //{ // //adds new contents to cart // Session["Cart"] = sessionBasket; //} ////send user to basket after things are added to basket //return RedirectToAction("Index", "Basket"); #endregion }