public ActionResult Index(Models.OrderLocation postback, Nullable <int> OrderId) { if (OrderId == null) { if (this.ModelState.IsValid) { var currentcart = Models.ShoppingCart.CartActions.CurrentShoppingCart(); var userId = HttpContext.User.Identity.GetUserId(); var userName = HttpContext.User.Identity.GetUserName(); using (DAL.BarContext db = new DAL.BarContext()) { var order = new Models.Order() { UserId = userId, UserName = userName, TableNumber = postback.TableNumber, }; db.Orders.Add(order); db.SaveChanges(); var orderDetails = currentcart.ToOrderDetailList(order.Id); db.OrderDetails.AddRange(orderDetails); db.SaveChanges(); } return(View("~/Views/Home/Index.cshtml")); } } //Handle Add-on Item else { if (this.ModelState.IsValid) { var currentcart = Models.ShoppingCart.CartActions.CurrentShoppingCart(); using (DAL.BarContext db = new DAL.BarContext()) { var orderDetails = currentcart.ToOrderDetailList(OrderId.GetValueOrDefault()); db.OrderDetails.AddRange(orderDetails); db.SaveChanges(); } return(View("~/Views/Home/Index.cshtml")); } } return(View()); }
public ActionResult Edit(Models.Item postback) { //verify the user input if (this.ModelState.IsValid) { using (DAL.BarContext db = new DAL.BarContext()) { //catch Item.Id and postback the data of Id var result = (from s in db.Items where s.Id == postback.Id select s).FirstOrDefault(); //Save the change into Database result.Name = postback.Name; result.Price = postback.Price; result.Description = postback.Description; result.OnShelf = postback.OnShelf; result.DefaultImageURL = postback.DefaultImageURL; result.Category = postback.Category; result.ImageAlt = postback.ImageAlt; //Save the change db.SaveChanges(); //Pop-up "edit successfully" msg and direct to Index TempData["Message"] = String.Format("Item [{0}] is edited ", postback.Name); return(RedirectToAction("Index")); } } else { return(View(postback)); } }
public ActionResult Add(Models.OrderDetail postback) { if (this.ModelState.IsValid) { using (DAL.BarContext db = new DAL.BarContext()) { //Post back data and add to Item table db.OrderDetails.Add(postback); //Save Change db.SaveChanges(); return(RedirectToAction("Index")); } } else { ViewBag.Message = "The data entry is not correct."; return(View(postback)); } }
public ActionResult Create(Models.Item postback) { if (this.ModelState.IsValid) { using (DAL.BarContext db = new DAL.BarContext()) { //Post back data and add to Item table db.Items.Add(postback); //Save Change db.SaveChanges(); //Item Create Sucessfully TempData["Message"] = String.Format("Item[{0}] is created", postback.Name); return(RedirectToAction("Index")); } } else { ViewBag.Message = "The data entry is not correct."; return(View(postback)); } }