Example #1
0
        public ActionResult ListMealSet(string search, string filter)
        {
            ViewBag.successMessage = "";

            ViewBag.notExistMealSet = "";

            MealSetTableAdapter mealSetAdapter = new MealSetTableAdapter();
            try
            {
                mealSetDT = mealSetAdapter.GetData();
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
            }

            if (!(string.IsNullOrEmpty(search) && string.IsNullOrEmpty(filter)))
            {
                int type = -1;
                if (!string.IsNullOrEmpty(filter))
                {
                    int.TryParse(filter, out type);
                }

                string name = search;
                if (name == null)
                {
                    name = String.Empty;
                }

                bool type_ = false;
                if (type == 1)
                {
                    type_ = true;
                }
                var result = from row in mealSetDT.AsEnumerable()
                             where (name == String.Empty ? true : StringExtensions.ContainsInsensitive(row.Field<string>("Name"), name))
                             && (type < 0 ? true : row.Field<bool>("CanEatMore") == type_)
                             select row;

                try
                {
                    return View(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);
                }
            }

            return View(mealSetDT);
        }
Example #2
0
        public JsonResult GetMeatSetForDDL()
        {
            try
            {
                MealSetTableAdapter mealSetTA = new MealSetTableAdapter();
                DataTable mealSetDT = mealSetTA.GetData();

                IList<MeatSetForDDLJsonModel> mealSet = new List<MeatSetForDDLJsonModel>();

                foreach (DataRow row in mealSetDT.Rows)
                {
                    MeatSetForDDLJsonModel model = new MeatSetForDDLJsonModel();

                    model.MealSetID = row.Field<int>("MealSetID");
                    model.Name = row.Field<string>("Name");

                    mealSet.Add(model);
                }

                return Json(new { mealSet = mealSet }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                return Json("error", JsonRequestBehavior.AllowGet);
            }
        }