예제 #1
0
        public ActionResult ListDish(string search, string filter)
        {
            ViewBag.notExistDish = "";

            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;

            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
                {
                    return View(result.CopyToDataTable());
                }
                catch (Exception ex)
                {
                    if (string.IsNullOrEmpty(search))
                    {
                        ViewBag.notExistDish = "Không tìm thấy kết quả nào";
                    }
                    else
                    {
                        ViewBag.notExistDish = "Không tìm thấy kết quả nào với từ khóa: " + search;
                    }
                    Log.ErrorLog(ex.Message);
                }
            }

            return View(dishDT);
        }
예제 #2
0
        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");
            }
        }
예제 #3
0
        public ActionResult DetailDish(string dishID)
        {
            try
            {
                int id = int.Parse(dishID);

                DetailDishModel model = new DetailDishModel();
                DishInfoDetailTableAdapter dishAdapter = new DishInfoDetailTableAdapter();
                DataTable dishDT = dishAdapter.GetDataByDishID(id);
                model.DishID = id;
                model.Dishname = dishDT.Rows[0]["Name"].ToString();
                model.DishTypeName = dishDT.Rows[0]["TypeName"].ToString();
                model.Description = dishDT.Rows[0]["Description"].ToString();
                model.Image = dishDT.Rows[0]["Image"].ToString();

                return View(model);
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                return RedirectToAction("Error", "Error");
            }
        }