public ActionResult EditRestaurant(Restaurant restaurants) { try { websitedbEntities db = new websitedbEntities(); Restaurant restaurant = db.Restaurant.Find(restaurants.ID); restaurant.OwnerID = restaurants.OwnerID; restaurant.PostalCode = restaurants.PostalCode; restaurant.City = restaurants.City; restaurant.StreetName = restaurants.StreetName; restaurant.HouseNo = restaurants.HouseNo; restaurant.TableAmount = restaurants.TableAmount; restaurant.Name = restaurants.Name; restaurant.Description = restaurants.Description; db.SaveChanges(); ViewBag.message = "Restaurant information updated successfully."; return(View(restaurant)); } catch (Exception e) { string s = string.Format("Fehler: {0}", e.Message); s = string.Format("Typ: {0}", e.GetType()); return(View()); } }
// If the order is finished the it saves the shopping cart in the database with orderstatus=1 which means that the order is set active. public ActionResult OrderFinished() { List <ShoppingCartViewModel> lscart = new List <ShoppingCartViewModel>(); lscart = (List <ShoppingCartViewModel>)Session["ShoppingCartViewModel"]; int tableidgive = 0; using (websitedbEntities db = new websitedbEntities()) { ShoppingCart shoppingCart = new ShoppingCart(); foreach (ShoppingCartViewModel cart in lscart) { shoppingCart.ProductIDs = cart.product.ProductID; shoppingCart.UserID = 1; shoppingCart.OrderStatus = 1; shoppingCart.ProductCount = cart.quantity; shoppingCart.RestaurantID = cart.product.RestaurantID; shoppingCart.RestaurantIDTable = cart.tableid; tableidgive = cart.tableid; db.ShoppingCart.Add(shoppingCart); db.SaveChanges(); } } return(RedirectToAction("ShowMenu", "Menu", new { tableid = tableidgive })); }
public ActionResult AddRestaurant(Restaurant restaurants) { try { using (websitedbEntities db = new websitedbEntities()) { Restaurant restaurant = new Restaurant(); restaurant.OwnerID = restaurants.OwnerID; restaurant.PostalCode = restaurants.PostalCode; restaurant.City = restaurants.City; restaurant.StreetName = restaurants.StreetName; restaurant.HouseNo = restaurants.HouseNo; restaurant.TableAmount = 0; restaurant.Name = restaurants.Name; restaurant.Description = restaurants.Description; db.Restaurant.Add(restaurant); db.SaveChanges(); } } catch (Exception e) { string s = string.Format("Fehler: {0}", e.Message); s = string.Format("Typ: {0}", e.GetType()); } return(RedirectToAction("ShowRestaurant")); }
// GET: Opens the EditRestaurant view and gives the user the option to reset the attributes. The restaurant id clearly identifies the product to change and // therefore the fields are auto completed public ActionResult EditRestaurant(int restaurantid) { if (!restaurantid.Equals(null)) { try { websitedbEntities db = new websitedbEntities(); var res = db.Restaurant.SingleOrDefault(x => x.ID == restaurantid); return(View(res)); } catch (Exception e) { string s = string.Format("Fehler: {0}", e.Message); s = string.Format("Typ: {0}", e.GetType()); return(View()); } } else { return(View()); } }
// GET: Gives out the restaurant tables for a specific restaurant based on the given restaurant id public ActionResult ShowRestaurantTable(int restaurantid) { try { var tempList = new List <RestaurantTable>(); using (websitedbEntities db = new websitedbEntities()) { foreach (RestaurantTable rt in db.RestaurantTable) { if (rt.RestaurantID == restaurantid) { tempList.Add(rt); } } } RestaurantTableViewModel rtvw = new RestaurantTableViewModel(); rtvw.ResID = restaurantid; rtvw.RestaurantTables = tempList; return(View(rtvw)); } catch (Exception e) { string s = string.Format("Fehler: {0}", e.Message); s = string.Format("Typ: {0}", e.GetType()); return(View()); } }
// Restaurant/Delete Deletes the product in the database based on the given product id public ActionResult DeleteRestaurant(int restaurantid) { using (websitedbEntities db = new websitedbEntities()) { db.Restaurant.Remove(db.Restaurant.Find(restaurantid)); db.SaveChanges(); } return(RedirectToAction("ShowRestaurant")); }
// GET: Gives out the products for a specific restaurant based on the given restaurant id public ActionResult ShowProduct(int?restaurantid) { if (restaurantid == null) { try { var tempList = new List <Product>(); using (websitedbEntities db = new websitedbEntities()) { foreach (Product p in db.Product) { tempList.Add(p); } } return(View(tempList)); } catch (Exception e) { string s = string.Format("Fehler: {0}", e.Message); s = string.Format("Typ: {0}", e.GetType()); return(View()); } } else { try { var tempList = new List <Product>(); using (websitedbEntities db = new websitedbEntities()) { foreach (Product p in db.Product) { if (p.RestaurantID == restaurantid) { tempList.Add(p); } } } using (websitedbEntities db = new websitedbEntities()) { ViewBag.RestaurantName = db.Restaurant.Find(restaurantid).Name; } return(View(tempList)); } catch (Exception e) { string s = string.Format("Fehler: {0}", e.Message); s = string.Format("Typ: {0}", e.GetType()); return(View()); } } }
// GET: Gives out the products ordered by the users. Additionally it gives information on the amount and the table ordered from public ActionResult ShowActiveOrder(int restaurantid) { List <ActiveOrderViewModel> tempList = new List <ActiveOrderViewModel> (); try { using (websitedbEntities db = new websitedbEntities()) { List <Product> productList = db.Product.ToList(); List <ShoppingCart> shoppingCarts = db.ShoppingCart.ToList(); List <RestaurantTable> restaurantTables = db.RestaurantTable.ToList(); foreach (ShoppingCart sc in shoppingCarts) { if (sc.OrderStatus == 1) { if (sc.RestaurantID == restaurantid) { foreach (Product p in productList) { if (p.ProductID == sc.ProductIDs) { ActiveOrderViewModel aovw = new ActiveOrderViewModel(); aovw.Tableid = db.RestaurantTable.Find(sc.RestaurantIDTable).RestaurantSeat; aovw.Productname = p.ProductName; aovw.Amount = sc.ProductCount; aovw.Status = sc.OrderStatus; aovw.OrderID = sc.ShoppingCartID; tempList.Add(aovw); } } } } } return(View(tempList)); } } catch (Exception e) { string s = string.Format("Fehler: {0}", e.Message); s = string.Format("Typ: {0}", e.GetType()); return(View()); } }
// GET: Gives out the menu for a specific restaurant based on the given table id. In the backend the table is stil stored public ActionResult ShowMenu(int tableid) { try { RestaurantTable restaurantTable = new RestaurantTable(); var tempList = new List <Product>(); using (websitedbEntities db = new websitedbEntities()) { List <Product> productList = db.Product.ToList(); List <RestaurantTable> tableList = db.RestaurantTable.ToList(); RestaurantTable restTable = new RestaurantTable(); MenuViewModel mvw = new MenuViewModel(); foreach (RestaurantTable rt in tableList) { if (rt.ID == tableid) { foreach (Product p in productList) { if (rt.RestaurantID == p.RestaurantID) { tempList.Add(p); restTable = rt; } } } } mvw.productList = tempList; mvw.restaurantTable = restTable; return(View(mvw)); } } catch (Exception e) { string s = string.Format("Fehler: {0}", e.Message); s = string.Format("Typ: {0}", e.GetType()); return(View()); } }
// Product/Delete Deletes the product in the database based on the given product id public ActionResult DeleteProduct(int productID) { try { using (websitedbEntities db = new websitedbEntities()) { Product p = db.Product.Find(productID); db.Product.Remove(p); db.SaveChanges(); } return(RedirectToAction("ShowProduct")); } catch (Exception e) { string s = string.Format("Fehler: {0}", e.Message); s = string.Format("Typ: {0}", e.GetType()); return(RedirectToAction("ShowProduct")); } }
public ActionResult AddProduct(Product product) { try { byte[] imgData; using (BinaryReader reader = new BinaryReader(product.ImageFile.InputStream)) { imgData = reader.ReadBytes((int)product.ImageFile.InputStream.Length); } using (websitedbEntities db = new websitedbEntities()) { Product prod = new Product(); prod.RestaurantID = product.RestaurantID; prod.ProductDescription = product.ProductDescription; prod.ProductName = product.ProductName; prod.ImagePath = Convert.ToBase64String(imgData); if ((decimal.Parse(product.ProductPrice) > 0 && !product.ProductPrice.Contains('.'))) { prod.ProductPrice = product.ProductPrice; db.Product.Add(prod); db.SaveChanges(); return(RedirectToAction("ShowProduct", new { restaurantid = prod.RestaurantID })); } else { ViewBag.PriceError = "Please enter a price in the format xxx,yy"; return(View()); } } } catch (Exception e) { string s = string.Format("Fehler: {0}", e.Message); s = string.Format("Typ: {0}", e.GetType()); return(View()); } }
// Sets order elements as finished and therefore it is removed from the activeorder list public ActionResult FinishOrder(int orderid) { ShoppingCart sc = new ShoppingCart(); try { using (websitedbEntities db = new websitedbEntities()) { sc = db.ShoppingCart.Find(orderid); sc.OrderStatus = 0; db.SaveChanges(); } return(RedirectToAction("ShowActiveOrder", new { restaurantid = sc.RestaurantID })); } catch (Exception e) { string s = string.Format("Fehler: {0}", e.Message); s = string.Format("Typ: {0}", e.GetType()); return(RedirectToAction("ShowActiveOrder", new { restaurantid = sc.RestaurantID })); } }
// GET: Gives out all the restaurant in the db public ActionResult ShowRestaurant() { try { var tempList = new List <Restaurant>(); using (websitedbEntities db = new websitedbEntities()) { foreach (Restaurant r in db.Restaurant) { tempList.Add(r); } } return(View(tempList)); } catch (Exception e) { string s = string.Format("Fehler: {0}", e.Message); s = string.Format("Typ: {0}", e.GetType()); return(View()); } }
// GET: Opens the editproduct view and gives the user the option to reset the attributes. The product id clearly identifies the product to change and // therefore the fields are auto completed public ActionResult EditProduct(int productID) { if (!productID.Equals(null)) { try { websitedbEntities db = new websitedbEntities(); var prod = db.Product.SingleOrDefault(x => x.ProductID == productID); return(View(prod)); } catch (Exception e) { string s = string.Format("Fehler: {0}", e.Message); s = string.Format("Typ: {0}", e.GetType()); return(View()); } } return(View()); }
// GET: Opens the EditRestaurantTable view and gives the user the option to reset the attributes. The restaurant id clearly identifies the restaurant to change and // therefore the fields are auto completed public ActionResult EditRestaurantTable(int restaurantid) { try { var tempList = new List <RestaurantTable>(); int tableamount = 0; using (websitedbEntities db = new websitedbEntities()) { tableamount = db.RestaurantTable.Where(x => x.RestaurantID == restaurantid).Count(); } RestaurantTableViewModel rv = new RestaurantTableViewModel(); rv.ResID = restaurantid; rv.capacity = tableamount; return(View(rv)); } catch (Exception e) { string s = string.Format("Fehler: {0}", e.Message); s = string.Format("Typ: {0}", e.GetType()); } return(View()); }
// This methods adds items to the shopping cart. It takes the productid and the tableid to know which table wants which product. public ActionResult AddShoppingCart(int?productid, int?tableid) { websitedbEntities db = new websitedbEntities(); if (productid == null || tableid == null) { return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest)); } if (Session["ShoppingCartViewModel"] == null) { List <ShoppingCartViewModel> lsCart = new List <ShoppingCartViewModel> { new ShoppingCartViewModel(db.Product.Find(productid), 1, db.RestaurantTable.Find(tableid).ID) }; Session["ShoppingCartViewModel"] = lsCart; Session["tableid"] = tableid; } else { List <ShoppingCartViewModel> lscart = (List <ShoppingCartViewModel>)Session["ShoppingCartViewModel"]; int check = isExistingCheck(productid); if (check == -1) { lscart.Add(new ShoppingCartViewModel(db.Product.Find(productid), 1, db.RestaurantTable.Find(tableid).ID)); } else { lscart[check].quantity++; } Session["ShoppingCartViewModel"] = lscart; Session["tableid"] = tableid; } return(RedirectToAction("ShowShoppingCart")); }
public ActionResult EditRestaurantTable(RestaurantTableViewModel restaurantTableViewModel) { try { var tempList = new List <RestaurantTable>(); int tableamount = 0; using (websitedbEntities db = new websitedbEntities()) { tableamount = db.RestaurantTable.Where(x => x.RestaurantID == restaurantTableViewModel.ResID).Count(); if (tableamount < restaurantTableViewModel.capacity) { while (tableamount < restaurantTableViewModel.capacity) { RestaurantTable rt = new RestaurantTable(); rt.RestaurantID = restaurantTableViewModel.ResID; rt.RestaurantSeat = tableamount + 1; tableamount = tableamount + 1; db.RestaurantTable.Add(rt); db.SaveChanges(); } ViewBag.message = "Successfully increased to " + restaurantTableViewModel.capacity + " Tables"; ViewBag.resid = restaurantTableViewModel.ResID; } else if (tableamount > restaurantTableViewModel.capacity) { List <RestaurantTable> tableList = db.RestaurantTable.ToList(); foreach (RestaurantTable rt in tableList) { if (rt.RestaurantID == restaurantTableViewModel.ResID) { db.RestaurantTable.Remove(rt); db.SaveChanges(); } } tableamount = 0; while (tableamount < restaurantTableViewModel.capacity) { RestaurantTable rt = new RestaurantTable(); rt.RestaurantID = restaurantTableViewModel.ResID; rt.RestaurantSeat = tableamount + 1; tableamount = tableamount + 1; db.RestaurantTable.Add(rt); db.SaveChanges(); } ViewBag.message = "Successfully decreased to " + restaurantTableViewModel.capacity + " Tables"; ViewBag.resid = restaurantTableViewModel.ResID; } else if (tableamount == restaurantTableViewModel.capacity) { ViewBag.message = "Please enter a different Table Capacity Number than the current one"; ViewBag.resid = restaurantTableViewModel.ResID; } } } catch (Exception e) { string s = string.Format("Fehler: {0}", e.Message); s = string.Format("Typ: {0}", e.GetType()); } return(View()); }