public ActionResult Confirm([Bind(Include = "Time,TableId")] Booking booking) { var currentUser = db.Users.Where(e => e.UserName == User.Identity.Name).FirstOrDefault(); if (currentUser != null) { booking.UserId = currentUser.Id; booking.Status = false; var bookingdetails = new List<BookingDetail>(); foreach (var item in ShoppingCart.Instance.Items) { BookingDetail newItem = new BookingDetail(); newItem.Meal = db.Meals.First(e => e.Id == item.ItemId); newItem.Number = item.Quantity; bookingdetails.Add(newItem); } booking.BookingDetails = bookingdetails; if (ModelState.IsValid) { db.Bookings.Add(booking); db.SaveChanges(); ShoppingCart.Instance.ClearCart(); return RedirectToAction("Index"); } ViewBag.TableId = new SelectList(db.Tables, "Id", "Feature", booking.TableId); } //ViewBag.UserId = new SelectList(db.ApplicationUsers, "Id", "FullName", booking.UserId); return RedirectToAction("Index"); }
public ActionResult Create() { var booking = new Booking(); var bookingdetails = new List<BookingDetail>(); foreach (var item in ShoppingCart.Instance.Items) { BookingDetail newItem = new BookingDetail(); newItem.Meal = db.Meals.First(e => e.Id == item.ItemId); newItem.Number = item.Quantity; bookingdetails.Add(newItem); } booking.BookingDetails = bookingdetails; return View(booking); }