// GET api/<controller> public List <dish> Get() { dish d = new dish(); List <dish> dishList = d.Read(); return(dishList); }
public IActionResult updateDish(int DishID, dish updatedDish) // public IActionResult updateDish(dish dish, int DishID) { if (ModelState.IsValid) { dish RetrievedDish = dbContext.Dishes.FirstOrDefault(selectedDish => selectedDish.DishID == DishID); RetrievedDish.Name = updatedDish.Name; RetrievedDish.Chef = updatedDish.Chef; RetrievedDish.Tastiness = updatedDish.Tastiness; RetrievedDish.Calories = updatedDish.Calories; RetrievedDish.Description = updatedDish.Description; // RetrievedDish.Name = dish.Name; // RetrievedDish.Chef = dish.Chef; // RetrievedDish.Tastiness = dish.Tastiness; // RetrievedDish.Calories = dish.Calories; // RetrievedDish.Description = dish.Description; dbContext.SaveChanges(); RetrievedDish.UpdatedAt = DateTime.Now; Console.WriteLine("************** Model is Valid **************"); return(Redirect($"/DishID/{DishID}")); } else { Console.WriteLine("************** Model is Invalid **************"); return(View("Edit", updatedDish)); } }
public IActionResult ChefsPage(int DishID) { dish RetrievedDish = dbContext.Dishes.FirstOrDefault(selectedDish => selectedDish.DishID == DishID); ViewBag.selectedDish = RetrievedDish; return(View("ChefsPage")); }
public IActionResult edit(int DishID) { dish RetrievedDish = dbContext.Dishes.FirstOrDefault(selectedDish => selectedDish.DishID == DishID); // ViewBag.selectedDish = RetrievedDish; return(View(RetrievedDish)); }
public IActionResult DeleteDish(int DishID) { dish RetrievedDish = dbContext.Dishes.SingleOrDefault(selectedDish => selectedDish.DishID == DishID); dbContext.Dishes.Remove(RetrievedDish); dbContext.SaveChanges(); return(RedirectToAction("Index")); }
//-------------------------------------------------------------------- // Build the Insert command String //-------------------------------------------------------------------- private String BuildInsertCommand(dish dish) { String command; StringBuilder sb = new StringBuilder(); // use a string builder to create the dynamic string sb.AppendFormat("Values('{0}', '{1}','{2}','{3}')", dish.Name, dish.Image, dish.CookingType, dish.Time); String prefix = "INSERT INTO dish_g_2021 " + "( [name], [image],[cookingType],[time]) "; command = prefix + sb.ToString(); return(command); }
public HttpResponseMessage getDailyDish(string id) { DataTable dt = new BLL.handleDish().GetDailyDish(id); Object data; if (dt.Rows.Count >= 0) { List <dish> list = new List <dish>(); for (int i = 0; i < dt.Rows.Count; i++) { dish dish = new dish(); dish.id = dt.Rows[i]["id"].ToString(); dish.dish_title = dt.Rows[i]["dish_title"].ToString(); dish.dish_content = dt.Rows[i]["dish_content"].ToString(); dish.dish_img = dt.Rows[i]["dish_img"].ToString(); dish.companyId = dt.Rows[i]["companyId"].ToString(); dish.dish_type = dt.Rows[i]["dish_type"].ToString(); dish.dish_week = dt.Rows[i]["dish_week"].ToString(); dish.is_online = Convert.ToInt32(dt.Rows[i]["is_online"]); dish.update_time = dt.Rows[i]["update_time"].ToString(); dish.create_time = dt.Rows[i]["create_time"].ToString(); list.Add(dish); } data = new { success = true, backData = list }; } else { data = new { success = false, backMsg = "数据异常" }; } JavaScriptSerializer serializer = new JavaScriptSerializer(); string json = serializer.Serialize(data); return(new HttpResponseMessage { Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json") }); }
public IActionResult Create(dish d) { if (ModelState.IsValid) { dbContext.Add(d); dbContext.SaveChanges(); // do somethng! maybe insert into db? then we will redirect Console.WriteLine("************** Model is Valid **************"); return(Redirect("/")); } else { // Oh no! We need to return a ViewResponse to preserve the ModelState, and the errors it now contains! Console.WriteLine("************** Model is Invalid **************"); return(View("NewDish")); } }
public List <dish> ReadDish() { SqlConnection con = null; List <dish> dishList = new List <dish>(); try { con = connect("DBConnectionString"); // create a connection to the database using the connection String defined in the web config file String selectSTR = "SELECT * FROM dish_g_2021"; SqlCommand cmd = new SqlCommand(selectSTR, con); // get a reader SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); // CommandBehavior.CloseConnection: the connection will be closed after reading has reached the end while (dr.Read()) { // Read till the end of the data into a row dish b = new dish(); b.Id = Convert.ToInt32(dr["id"]); b.Name = (string)dr["name"]; b.Image = (string)dr["image"]; b.CookingType = (string)dr["cookingType"]; b.Time = Convert.ToDouble(dr["time"]); dishList.Add(b); } return(dishList); } catch (Exception ex) { // write to log throw (ex); } finally { if (con != null) { con.Close(); } } }
public HttpResponseMessage getDishDetail(string id) { DataTable dt = new BLL.handleDish().GetDishDetail(id); Object data; if (dt.Rows.Count == 1) { dish dish = new dish(); dish.id = dt.Rows[0]["id"].ToString(); dish.dish_title = dt.Rows[0]["dish_title"].ToString(); dish.dish_content = dt.Rows[0]["dish_content"].ToString(); dish.dish_img = dt.Rows[0]["dish_img"].ToString(); dish.companyId = dt.Rows[0]["companyId"].ToString(); dish.dish_type = dt.Rows[0]["dish_type"].ToString(); dish.is_online = Convert.ToInt32(dt.Rows[0]["is_online"]); dish.update_time = dt.Rows[0]["update_time"].ToString(); dish.create_time = dt.Rows[0]["create_time"].ToString(); data = new { success = true, backData = dish }; } else { data = new { success = false, backMsg = "数据异常" }; } JavaScriptSerializer serializer = new JavaScriptSerializer(); string json = serializer.Serialize(data); return(new HttpResponseMessage { Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json") }); }
//========================================================dish public int InsertDish(dish dish) { SqlConnection con; SqlCommand cmd; try { con = connect("DBConnectionString"); // create the connection } catch (Exception ex) { // write to log throw (ex); } String cStr = BuildInsertCommand(dish); // helper method to build the insert string cmd = CreateCommand(cStr, con); // create the command try { int numEffected = cmd.ExecuteNonQuery(); // execute the command return(numEffected); } catch (Exception ex) { // write to log throw (ex); } finally { if (con != null) { // close the db connection con.Close(); } } }
public ActionResult <List <dish> > Get()// { List <dish> mylist = new List <dish>(); string ls_sql = "select id,name,image,category,label,price,description from dishes"; using (SqlConnection conn = new SqlConnection(connstr)) { List <dish> mydisharr = new List <dish>(); try { conn.Open(); SqlCommand scmd = new SqlCommand(ls_sql, conn); SqlDataReader rd = scmd.ExecuteReader(); dish ld; while (rd.Read()) { ld = new dish { id = (int)rd.GetValue(0), name = (string)rd.GetValue(1), image = (string)rd.GetValue(2), category = (string)rd.GetValue(3), label = (string)rd.GetValue(4), price = (string)rd.GetValue(5), description = (string)rd.GetValue(6) }; mydisharr.Add(ld); } rd.Close(); } catch (Exception e) { Console.WriteLine(e.Message); throw; } return(mydisharr); } //return new string[] { "v 1", "value2" }; }
// POST api/<controller> public void Post([FromBody] dish d) { d.Insert(); }
public WriteXmlFile(dish myDish) { dsh = myDish; }
// DONE: deserts, starters, main course, salats, pizzas, sandwiches, kids, //LEFT: private List <dish> getAllDishes() { List <dish> myDishes = new List <dish>(); // get deserts dish desert_soufle = new dish("Soufle", "with cream", "Deserts", "hot soufle with cream", 35, "https://cdn.kiwilimon.com/recetaimagen/1685/th5-640x426-12888.jpg"); dish desert_cheeseCake = new dish("Cheese Cake", "with chocolate", "Deserts", "cheese cake with chocolate", 35, "https://www.jocooks.com/wp-content/uploads/2018/11/new-york-style-cheesecake-1-2.jpg"); dish desert_troufles = new dish("troufles", "with pineapple", "Deserts", "brownies with pineapple and cream", 35, "https://www.averiecooks.com/wp-content/uploads/2019/04/boyfriendbrownies-6.jpg"); dish desert_applePie = new dish("Apple Pie", "with meipel", "Deserts", "hot apple-pie with meipel", 35, "https://food.fnr.sndimg.com/content/dam/images/food/fullset/2013/6/28/0/FNK_Apple-Pie_s4x3.jpg.rend.hgtvcom.826.620.suffix/1382545039107.jpeg"); // get starters dish firstDish_Fries = new dish("Fries", "like homefries", "Starters", "asd", 36, "https://thumbor.thedailymeal.com/r19Dr1epeqxTZm6O5CuFj0T0kME=//https://www.thedailymeal.com/sites/default/files/recipe/2018/iStock-687999118_1_.jpg"); dish firstDish_Nachos = new dish("Cheese Nachos", "with cheese", "Starters", "hot nachos with melted cheese", 35, "https://img1.mashed.com/img/gallery/mistakes-everyone-makes-when-making-nacho-cheese/intro-1544049574.jpg"); dish firstDish_NachosSupreme = new dish("Nachos Supreme", "with vegtebles", "Starters", "nachos with melted cheese and veg", 55, "http://www.pamperedchef.ca/iceberg/com/recipe/1050281-lg.jpg"); dish firstDish_NachosSupremeTexas = new dish("Nachos Supreme Texas", "with beef", "Starters", "nachos with cheese, veg and beef", 62, "https://www.farmison.com/community/wp-content/uploads/2018/06/BEEF-CHILI-TACO-NACHOS-AND-TORTILLA-NACHOS-1024x1024.jpg"); dish firstDish_Sausege = new dish("Sausege", "on cabage", "Starters", "2 sauseges on a hot skillet", 42, "https://www.wikihow.com/images/thumb/0/0a/Cook-Italian-Sausage-Step-4-Version-2.jpg/aid2339691-v4-728px-Cook-Italian-Sausage-Step-4-Version-2.jpg"); dish firstDish_MunchiesBusket = new dish("Munchies Busket", "mix fries", "Starters", "fries, onion rings and chicken fingers", 52, "https://image.shutterstock.com/image-photo/breaded-chicken-strips-french-fries-260nw-165016274.jpg"); dish firstDish_MacNCheese = new dish("Mac n Cheese", "macaroni and cheese", "Starters", "macaroni and cheese", 49, "https://www.dinneratthezoo.com/wp-content/uploads/2018/04/stove-top-mac-and-cheese-4.jpg"); dish firstDish_Adamame = new dish("Adamame", "with salt", "Starters", "big plate of adamame", 39, "https://www.garlicandzest.com/wp-content/uploads/2014/02/blistered-edamame-9.jpg"); dish firstDish_BBQwings8 = new dish("BBQ wings 8 pieces", "8 wings with BBQ sauce", "Starters", "8 wings with bbq", 39, "https://img.sndimg.com/food/image/upload/w_555,h_416,c_fit,fl_progressive,q_95/v1/img/recipes/18/58/92/apYqQ1tfTWaLP3tlxrxQ_bbq%20chic3.jpg"); dish firstDish_BBQwings16 = new dish("BBQ wings 16 pieces", "16 wings with BBQ sauce", "Starters", "16 wings with bbq", 52, "https://img.sndimg.com/food/image/upload/w_555,h_416,c_fit,fl_progressive,q_95/v1/img/recipes/18/58/92/apYqQ1tfTWaLP3tlxrxQ_bbq%20chic3.jpg"); dish firstDish_Hotwings8 = new dish("Hot wings 8 pieces", "8 wings with frank sauce", "Starters", "8 wings with frank hot sauce", 42, "https://img.sndimg.com/food/image/upload/w_555,h_416,c_fit,fl_progressive,q_95/v1/img/recipes/18/58/92/apYqQ1tfTWaLP3tlxrxQ_bbq%20chic3.jpg"); dish firstDish_HotWings16 = new dish("Hot wings 16 pieces", "16 wings with frank sauce", "Starters", "16 wings with franks hot sauce", 56, "https://www.thespruceeats.com/thmb/-xzu1qCwP2_eLYw4QbaJt2yW7F8=/450x0/filters:no_upscale():max_bytes(150000):strip_icc()/traditional-chicken-wings-912937-10-5b3f8c9ac9e77c00547241ab.jpg"); dish firstDish_CheeseFries = new dish("Cheese fries", "fries with melted cheese", "Starters", "fries with melted cheese", 42, "https://upload.wikimedia.org/wikipedia/commons/0/03/Shake_shack_cheese_fries.jpg"); dish firstDish_CheeseBaconFries = new dish("Cheese bacon fries", "fries with cheese and bacon", "Starters", "fries with cheese and bacon", 52, "http://i0.wp.com/chickandhercheese.com/wp-content/uploads/2016/03/Bacon-ranch-cheese-fries-08.jpg"); dish firstDish_OnionRings = new dish("Onion rings", "basket of onion rings", "Starters", "basket of onion rings", 39, "https://cdn.shortpixel.ai/client/q_glossy,ret_img,w_900/https://lifeloveandgoodfood.com/wp-content/uploads/2015/06/onion-rings1.jpg"); dish firstDish_ChickenFingers = new dish("Chicken fingers", "basket of Chicken fingers", "Starters", "basket of Chicken fingers", 48, "https://upload.wikimedia.org/wikipedia/commons/2/21/Crispy_Chicken_Strips_-_FotoosVanRobin.jpg"); // get main-course dish mainCourse_Burger = new dish("Burger", "tasty burger", "MainCourse", "asd", 3, "https://food.fnr.sndimg.com/content/dam/images/food/fullset/2017/5/10/0/FNM_060117-Smashburger-Style-Burgers-Recipe_s4x3.jpg.rend.hgtvcom.616.462.suffix/1494459418304.jpeg"); dish mainCourse_ChickenFillet = new dish("Chicken fillet", "2 pieces with side-dish", "MainCourse", "2 pices of chicken", 62, "https://i.ndtvimg.com/i/2017-01/chicken-fillet-620x350_620x350_61485536532.jpg"); dish mainCourse_FishNChips = new dish("Fish n chips", "fish strips on fries", "MainCourse", "fish strips on fries busket", 59, "https://media-cdn.tripadvisor.com/media/photo-p/13/7f/35/57/amy-s-fish-chips.jpg"); dish mainCourse_HalleluiaChicken = new dish("Halleluia chicken", "shwarma with torrtillas", "MainCourse", "shwarma with torrtillas", 68, "https://sifu.unileversolutions.com/image/en-EG/recipe-topvisual/2/1260-709/chicken-shawarma-50256669.jpg"); dish mainCourse_ChickenFahitas = new dish("Chicken fahitas", "chicken and veg inside tortillas", "MainCourse", "chicken and veg inside torttillas", 89, "https://carlsbadcravings.com/wp-content/uploads/2016/08/Chicken-Fajitas-2-650x975.jpg"); dish mainCourse_VeggieFahitas = new dish("Veggie fahitas", "veg burger inside tortillas", "MainCourse", "veg burger inside tortillas", 89, "https://www.onelovelylife.com/wp-content/uploads/2017/07/fajitas1-SM.jpg"); // get pizza dish pizza_Margarita = new dish("Pizza Margarita", "our homade pizza margarita", "Pizzas", "oven made fresh pizza", 39, "https://media-cdn.tripadvisor.com/media/photo-s/0e/9c/ab/14/pizza-margherita-con.jpg"); dish pizza_Pepperoni = new dish("Pizza Pepperoni", "our homade pizza margarita with pepperoni", "Pizzas", "oven made fresh pizza with pepperoni", 49, "https://images-gmi-pmc.edge-generalmills.com/f4c0a86f-b080-45cd-a8a7-06b63cdb4671.jpg"); dish pizza_MeatLovers = new dish("Pizza Meat Lovers", "amazing pizza for real meat lovers", "Pizzas", "cheese pizza with bacon, chicken, sausege and pepperoni", 69, "https://www.sodicgarden.com/wp-content/uploads/2018/07/MEt-Pizza.jpg"); dish pizza_Buffalo = new dish("Buffalo Pizza", "pizza with blue cheese and hot fried chicken", "Pizzas", "pizza with blue cheese, hot fried chicken and oregano", 65, "https://foxeslovelemons.com/wp-content/uploads/2017/06/Buffalo-Shrimp-Pizza-720x540.jpg"); dish pizza_Mexican = new dish("Mexican Pizza", "pizza with cooked veggies", "Pizzas", "our pizza with cooked onion and peppers ", 49, "https://keeprecipes.com/sites/keeprecipes/files/imagecache/recipe_large/16065_1357397078_0.jpg"); // get salad dish salad_Mexican = new dish("Mexican salad", "our hot mexican salad", "Salats", "fresh lettece with tomatos, cucumber, onions and fried veggies", 49, "http://i.recipes-plus.com/styles/fp_detail/public/recipe/2016/04/hot-sweet-sour-green-papaya-salad.jpg"); dish salad_MikesPlace = new dish("Mikes Place Salad", "salad 8 colors", "Salats", "salad with lots of veggies", 42, "https://i2.wp.com/aspicyperspective.com/wp-content/uploads/2018/07/Chopped-Israeli-Salad-with-Lemon-Vinaigrette-12.jpg"); dish salad_Buffalo = new dish("Buffalo Salad", "our hot american salad", "Salats", "leaves salad with hot fried chicken", 62, "https://www.anduzzis.com/wp-content/uploads/buffalo-chicken-salad-1.jpg"); dish salad_Ranch = new dish("Ranch Salad", "fati salad", "Salats", "leaves salad with chicken, bacon and cheese", 69, "https://www.gimmesomeoven.com/wp-content/uploads/2016/07/Kale-Salad-with-Bacon-and-Blue-Cheese-3.jpg"); // get sandwiches dish burger_burger = new dish("Mikes Place Burger", "classic 200g burger", "Sandwiches", "classic burger serve with veggies on the side", 58, "https://d9hyo6bif16lx.cloudfront.net/live/img/production/detail/menu/lunch-dinner_burgers_all-american-burger.jpg"); dish burger_cheeseAndBacon = new dish("cheese bacon burger", "chedder cheese and bacon on top of the burger", "Sandwiches", "amazing chedder cheese and bacon burger with veggies on the side", 68, "https://sifu.unileversolutions.com/image/en-AU/recipe-topvisual/2/1260-709/beef-burger-with-deep-fried-bacon-and-thousand-island-dressing-50247463.jpg"); dish burger_bigMike = new dish("The BIG MIKE", "double burger with cheese and bacon", "Sandwiches", "double 200g burger with double of cheese and bacon", 89, "https://image.shutterstock.com/image-photo/tasty-double-burger-bacon-on-260nw-1053696920.jpg"); dish burger_chickenSandwich = new dish("Chicken Sandwich", "classic 200g chicken burger", "Sandwiches", "chicken and veggies in a bun", 58, "http://life-in-the-lofthouse.com/wp-content/uploads/2014/07/Chic-Fil-A-copycat-sandwich.jpg"); dish burger_veganBurger = new dish("veggie burger", "veggie burger", "Sandwiches", "veggie burger from soy", 58, "https://sweetsimplevegan.com/wp-content/uploads/2018/06/Vegan_High_Protein_Mushroom_Burgers_Sweet_Simple_Vegan_1-copy.jpg"); dish burger_aliceTeaParty = new dish("Alice Tea Party", "burger with mushrooms, frie onions and cmehin", "Sandwiches", "200g burger served with fried mushrooms and onions and kmehin sause on top", 72, "http://woodysgrill.com/portal2/wp-content/uploads/2013/11/MushroomOnionBurger_web.jpg"); dish burger_blt = new dish("BLT", "bacon strips burger with mayo", "Sandwiches", "3 strips of bacon with lettece, tomato and mayo", 58, "https://www.meatpoultry.com/ext/resources/MPImages/04-2019/041519/Sonic_Slide.jpg?1555442121"); dish burger_muddies = new dish("Muddies sandwich", "fried chicken with hot sause in a bun", "Sandwiches", "fried chicken with hot sause in a bun", 72, "https://i.kinja-img.com/gawker-media/image/upload/s--rvazq1nQ--/c_scale,f_auto,fl_progressive,q_80,w_800/d01h32vyj51jhwjbaav1.jpg"); dish burger_sloppyJoe = new dish("sloppy joe", "ground beef with bbq sause in a bun", "Sandwiches", "ground beef with bbq sause in a bun", 58, "https://www.dinneratthezoo.com/wp-content/uploads/2018/06/slow-cooker-sloppy-joes-4.jpg"); // get kids dish kids_burger = new dish("Kiddy Burger", "200g burger and fries", "Kids", "special burger for kids", 46, "https://www.meatpoultry.com/ext/resources/MPImages/04-2019/041519/Sonic_Slide.jpg?1555442121"); dish kids_pizza = new dish("Kiddy Pizza", "Pizza with topping", "Kids", "special pizza for kids", 58, "https://www.meatpoultry.com/ext/resources/MPImages/04-2019/041519/Sonic_Slide.jpg?1555442121"); dish kids_chixFingers = new dish("Kiddy Chicken Fingers", "chicken fingers and fries", "Kids", "special fingers for kids", 58, "https://www.meatpoultry.com/ext/resources/MPImages/04-2019/041519/Sonic_Slide.jpg?1555442121"); // push deserts myDishes.Add(desert_soufle); myDishes.Add(desert_cheeseCake); myDishes.Add(desert_troufles); myDishes.Add(desert_applePie); // push starters myDishes.Add(firstDish_Fries); myDishes.Add(firstDish_Nachos); myDishes.Add(firstDish_NachosSupreme); myDishes.Add(firstDish_NachosSupremeTexas); myDishes.Add(firstDish_Sausege); myDishes.Add(firstDish_MunchiesBusket); myDishes.Add(firstDish_MacNCheese); myDishes.Add(firstDish_Adamame); myDishes.Add(firstDish_BBQwings8); myDishes.Add(firstDish_BBQwings16); myDishes.Add(firstDish_Hotwings8); myDishes.Add(firstDish_HotWings16); myDishes.Add(firstDish_CheeseFries); myDishes.Add(firstDish_CheeseBaconFries); myDishes.Add(firstDish_OnionRings); myDishes.Add(firstDish_ChickenFingers); // push main-course myDishes.Add(mainCourse_Burger); myDishes.Add(mainCourse_ChickenFillet); myDishes.Add(mainCourse_FishNChips); myDishes.Add(mainCourse_HalleluiaChicken); myDishes.Add(mainCourse_ChickenFahitas); myDishes.Add(mainCourse_VeggieFahitas); // push pizza myDishes.Add(pizza_Margarita); myDishes.Add(pizza_Pepperoni); myDishes.Add(pizza_MeatLovers); myDishes.Add(pizza_Buffalo); myDishes.Add(pizza_Mexican); // push salad myDishes.Add(salad_Mexican); myDishes.Add(salad_MikesPlace); myDishes.Add(salad_Buffalo); myDishes.Add(salad_Ranch); // push burgers myDishes.Add(burger_burger); myDishes.Add(burger_cheeseAndBacon); myDishes.Add(burger_bigMike); myDishes.Add(burger_chickenSandwich); myDishes.Add(burger_veganBurger); myDishes.Add(burger_aliceTeaParty); myDishes.Add(burger_blt); myDishes.Add(burger_muddies); myDishes.Add(burger_sloppyJoe); //push kids myDishes.Add(kids_burger); myDishes.Add(kids_pizza); myDishes.Add(kids_chixFingers); return(myDishes); }