public ActionResult DetailMealSet(string mealSetID) { try { int id = int.Parse(mealSetID); MealSetDishInfoTableAdapter mealSetDishInfoAdapter = new MealSetDishInfoTableAdapter(); ViewData["listMealSetDish"] = mealSetDishInfoAdapter.GetDataByMealSetID(id); MealSetTableAdapter mealSetAdapter = new MealSetTableAdapter(); EditMealSetModel model = new EditMealSetModel(); DataTable mealSetDT = mealSetAdapter.GetDataByMealSetID(id); model.MealSetID = id; model.MealSetName = mealSetDT.Rows[0]["Name"].ToString(); model.Description = mealSetDT.Rows[0]["Description"].ToString(); model.Image = mealSetDT.Rows[0]["Image"].ToString(); model.CanEatMore = (bool)mealSetDT.Rows[0]["CanEatMore"]; return View(model); } catch (Exception ex) { Log.ErrorLog(ex.Message); return RedirectToAction("Error", "Error"); } }
public ActionResult AddMealSetDish(string mealSetID, string search, string filter) { ViewBag.notExistMealSet = ""; DishTypeTableAdapter dishTypeAdapter = new DishTypeTableAdapter(); DataTable dishTypeDT = dishTypeAdapter.GetData(); List<SelectListItem> items = new List<SelectListItem>(); items.Add(new SelectListItem { Text = "Tất Cả", Value = "" }); foreach (DataRow row in dishTypeDT.Rows) { items.Add(new SelectListItem { Text = row["TypeName"].ToString(), Value = row["DishTypeID"].ToString() }); } ViewData["DishType"] = items; DataTable dishDT = new DataTable(); DishInfoDetailTableAdapter adapter = new DishInfoDetailTableAdapter(); try { dishDT = adapter.GetData(); } catch (Exception ex) { Log.ErrorLog(ex.Message); } if (!(string.IsNullOrEmpty(search) && string.IsNullOrEmpty(filter))) { int type = -1; int.TryParse(filter, out type); string name = search; if (name == null) { name = String.Empty; } var result = from row in dishDT.AsEnumerable() where (name == String.Empty ? true : StringExtensions.ContainsInsensitive(row.Field<string>("Name"), name)) && (type < 1 ? true : row.Field<int>("DishTypeID") == type) select row; try { dishDT = result.CopyToDataTable(); } catch (Exception ex) { if (string.IsNullOrEmpty(search)) { ViewBag.notExistMealSet = "Không tìm thấy kết quả nào"; } else { ViewBag.notExistMealSet = "Không tìm thấy kết quả nào với từ khóa: " + search; } Log.ErrorLog(ex.Message); } } ViewData["listDish"] = dishDT; try { int id = int.Parse(mealSetID); MealSetDishInfoTableAdapter mealSetDishInfoAdapter = new MealSetDishInfoTableAdapter(); ViewData["listMealSetDish"] = mealSetDishInfoAdapter.GetDataByMealSetID(id); MealSetTableAdapter mealSetAdapter = new MealSetTableAdapter(); EditMealSetModel model = new EditMealSetModel(); DataTable mealSetDT = mealSetAdapter.GetDataByMealSetID(id); model.MealSetID = id; model.MealSetName = mealSetDT.Rows[0]["Name"].ToString(); model.Description = mealSetDT.Rows[0]["Description"].ToString(); model.Image = mealSetDT.Rows[0]["Image"].ToString(); model.CanEatMore = (bool)mealSetDT.Rows[0]["CanEatMore"]; return View(model); } catch (Exception ex) { Log.ErrorLog(ex.Message); return RedirectToAction("Error", "Error"); } }