public ActionResult GetMenuDetailsForUpdate(string menuID, string FCName, string CName, string DName, string SDate, string NoP) { FoodCourtAdminDAL agent = new FoodCourtAdminDAL(); UpdateMenuDetails obj = new UpdateMenuDetails(); obj.MenuItem = new MenuDetails(); obj.MenuID = Convert.ToInt32(menuID); obj.MenuItem.FoodCourtName = FCName; obj.MenuItem.CatererName = CName; obj.MenuItem.DishName = DName; obj.MenuItem.ServingDate = Convert.ToDateTime(SDate); obj.MenuItem.NumberOfPlates =Convert.ToInt32(NoP); List<string> tempList = new List<string>(); tempList = agent.FoodCourts(); tempList.Remove(FCName); ViewBag.list1 = tempList; tempList = agent.Caterers(); tempList.Remove(CName); ViewBag.list2 = tempList; tempList = agent.Dishes(); tempList.Remove(CName); ViewBag.list3 = tempList; return PartialView("_AddMenuPartial", obj); }
public bool UpdateMenuItem(UpdateMenuDetails obj) { bool UpdateSuccess = false; try { ConnectionStr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; conn = new SqlConnection(ConnectionStr); conn.Open(); } catch (Exception e) { Debug.WriteLine("SQL Server connection failed:" + e.Message); UpdateSuccess = false; } try { cmd = new SqlCommand("SELECT FoodCourtID FROM FoodCourtDB WHERE FoodCourtName = @foodcourtname;", conn); cmd.Parameters.AddWithValue("foodcourtname", obj.MenuItem.FoodCourtName); int FoodCourtID = Convert.ToInt32(cmd.ExecuteScalar()); cmd = new SqlCommand("SELECT CatererID FROM CatererDB WHERE CatererName = @caterername;", conn); cmd.Parameters.AddWithValue("caterername", obj.MenuItem.CatererName); int CatererID = Convert.ToInt32(cmd.ExecuteScalar()); cmd = new SqlCommand("SELECT DishID FROM DishDB WHERE DishName = @dishname;", conn); cmd.Parameters.AddWithValue("dishname", obj.MenuItem.DishName); int DishID = Convert.ToInt32(cmd.ExecuteScalar()); cmd = new SqlCommand("UPDATE MenuDB SET FoodCourtID = @foodcourtid, CatererID = @catererid, ServingDate = @servingdate, NoOfPlates = @noofplates, DishID = @dishid WHERE MenuID = @menuid", conn); cmd.Parameters.AddWithValue("foodcourtid", FoodCourtID); cmd.Parameters.AddWithValue("catererid", CatererID); cmd.Parameters.AddWithValue("servingdate", obj.MenuItem.ServingDate); cmd.Parameters.AddWithValue("noofplates", obj.MenuItem.NumberOfPlates); cmd.Parameters.AddWithValue("dishid", DishID); cmd.Parameters.AddWithValue("menuid", obj.MenuID); int count = cmd.ExecuteNonQuery(); if (count.Equals(1)) { UpdateSuccess = true; } else { UpdateSuccess = false; } } catch (Exception err) { Debug.WriteLine("SQL operation failed:" + err.Message); UpdateSuccess = false; } conn.Close(); return UpdateSuccess; }
public string UpdateMenuDetails(string menuID, string FCName, string CName, string DName, string SDate, string NoP) { FoodCourtAdminDAL agent = new FoodCourtAdminDAL(); UpdateMenuDetails obj = new UpdateMenuDetails(); obj.MenuItem = new MenuDetails(); obj.MenuID = Convert.ToInt32(menuID); obj.MenuItem.FoodCourtName = FCName; obj.MenuItem.CatererName = CName; obj.MenuItem.DishName = DName; obj.MenuItem.ServingDate = Convert.ToDateTime(SDate); obj.MenuItem.NumberOfPlates = Convert.ToInt32(NoP); bool res = agent.UpdateMenuItem(obj); if (res) { return ("DONE"); } else { return ("ERROR"); } }