예제 #1
0
        public ActionResult Index(WordsCondition condition)
        {
            // Lấy danh sách từ vựng theo điều kiện tìm kiếm.
            condition.ListWordSuggest = _service.List(condition);

            // Lấy danh sách loại từ điển.
            List <SelectListItem> listDictType = _service.ListDictType();

            listDictType.Insert(0, new SelectListItem()
            {
                Text = "Chọn loại từ điển", Value = "0"
            });
            ViewBag.ListDictType = listDictType;

            int userId = 0;

            int.TryParse(CookieHelper.Get(Configs.COOKIES_ACCOUNT_ID), out userId);

            // Lấy thông tin chi tiết của từ vựng
            WordsModel model = new WordsModel();

            if (condition.Id > 0)
            {
                model = _service.GetById(condition.Id);

                // Cập nhật vào bảng lịch sử tìm kiếm.
                if (userId > 0)
                {
                    _service.UpdateWordHistory(condition.Id, userId);
                }
            }
            ViewBag.WordsModel = model;

            // Lấy danh sách lịch sử tìm kiếm.
            List <SelectListItem> listWordHistory = new List <SelectListItem>();

            if (userId > 0)
            {
                listWordHistory = _service.ListWordHistory(userId);
            }
            ViewBag.ListWordHistory = listWordHistory;

            TempData["TabId"] = condition.DictType;

            return(View(condition));
        }