Esempio n. 1
0
        public ActionResult ViewDish(string search, string filter)
        {
            ViewBag.notExistDish = "";

            DishTypeTableAdapter dishTypeAdapter = new DishTypeTableAdapter();
            DataTable dishTypeDT = dishTypeAdapter.GetData();

            ViewData["DishType"] = dishTypeDT;

            DishTableAdapter adapter = new DishTableAdapter();

            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);
        }