//ctor(order) public EventsData(Event _Event, bool OrderExist) { if (_Event != null) { try { //first get the full implement evnt = _Event; cartID = evnt.cartID; // get the movieShowTime via Event.MovieShowTimeID movieShowTime = db.MovieShowTimes.Find(Event.MovieShowTimeID); movie = MovieShowTime.Movie; // get the theatres item theaters = (from theat in db.Theaters where theat.MovieTheatersID == (from rw in db.Rows where rw.RowsID == (from hc in db.HallChairs where hc.HallChairsID == (from co in db.ChairsOrderd where co.EventID == Event.EventID select co).FirstOrDefault().HallChairID select hc).FirstOrDefault().RowID select rw).FirstOrDefault().TheatersID select theat).SingleOrDefault(); // get the TimeScreening item timeScreening = (from ts in db.TimeScreening where _Event.MovieShowTimeID == ts.MovieShowTimeID && ts.MovieTheatersID == theaters.MovieTheatersID select ts).SingleOrDefault(); ChairsNumber = new List<string>(); int[] ChairOrderID = Event.ChairsOrderds.Where(x=>x.EventID== Event.EventID).Select(x=>x.ChairsOrderdiD).ToArray(); ChairsNumber.AddRange(EcomLogic.GetChairNumbers(ChairOrderID,Event.ChairsOrderds)); getTotalChairsOrdered(); OrderDate = DateTime.Now; // if there is a order all fine.. if no , go to catch and make one. try { if (OrderExist == true) { order = (from odr in db.Orders where odr.EventID == evnt.EventID && odr.CartId == cartID select odr).SingleOrDefault(); } } catch (Exception) { ifEror = "Error by adding the Order."; } ifEror = null; } catch (Exception ex) { ifEror = "There is an error while adding detial's."+ex.Message; } } }
public ActionResult Create(string movieList, List<DateTime> ShowTime, [Bind(Include = "MovieShowTimeID,MovieID,ShowTime")] MovieShowTime movieshowtime) { if (ShowTime.Count != 0) { // create list of Movie Show Time List<MovieShowTime> MovieShowTimeList = new List<MovieShowTime>(); foreach (var item in ShowTime) { if (item.Date != Convert.ToDateTime("01/01/0001 00:00:00")) { MovieShowTime ShowTimeItem = new MovieShowTime(); // add Detials ShowTimeItem.MovieID = Convert.ToInt32(movieList); ShowTimeItem.ShowTime = item; // add Show Time Item's for the List MovieShowTimeList.Add(ShowTimeItem); } } //Add all the Item's to DB . if (ModelState.IsValid) { foreach (var item in MovieShowTimeList) { db.MovieShowTimes.Add(item); db.SaveChanges(); } return RedirectToAction("Index", "Movie"); } else { ViewBag.ErrorMessage = "Unable to add all the Time's"; return RedirectToAction("Create", "Movie"); } } else { ViewBag.ErrorMessage = "Unable to add Movie Show Time"; } return View(movieshowtime); }