public Cocktail GetCocktailByID(int cocktailID) { Cocktail cocktail = null; using (SqlConnection con = new SqlConnection(this.ConnectionString)) { con.Open(); using (SqlCommand command = new SqlCommand()) { string sSQL = "SELECT * FROM Cocktails "; sSQL += " WHERE ID = @cocktailID"; command.CommandText = sSQL; command.Parameters.AddWithValue("@cocktailID", cocktailID); command.Connection = con; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { cocktail = new Cocktail(); cocktail.ID = int.Parse(reader["ID"].ToString()); cocktail.Name = (reader["Name"] != DBNull.Value ? reader["Name"].ToString() : string.Empty); } return cocktail; } } }
public ActionResult Order(int? GinId) { if (GinId == null || !ModelState.IsValid) return RedirectToAction("Index", "Gin"); List <VMCocktail> CocktailList = new List<VMCocktail>(); List<Ingredient> IngredientList = new List<Ingredient>(); Cocktail c = new Cocktail(); Ingredient i = new Ingredient(); VMCocktail vm = new VMCocktail(); c.ID = 0; c.Name = "Cocktail name"; i.ID = 0; i.Name = "Ingredient name"; i.Quantity = 250; IngredientList.Add(i); vm.CurrentCocktail = c; vm.Ingredients = IngredientList; CocktailList.Add(vm); ViewBag.Gin = GinData.GetGinById(Convert.ToInt32(GinId)); return View(CocktailList); }