Exemple #1
0
        /// <summary>
        ///     view list KhachHang with filter
        /// </summary>
        public ActionResult Index(KhachHangFilterModel filter, Pager pager, ViewMode viewMode = ViewMode.Default)
        {
            title = "Quản lý Khách hàng";

            // default values
            if (filter.Mode == KhachHangFilterModel.FilterByManagementInfo) // not in filter
            {
                // set selected to, quan huyen = nhanVien's to, quan huyen
                if (nhanVien != null && filter.QuanHuyenID == null)
                {
                    filter.NhanVienID = nhanVien.NhanvienID;
                    filter.ToID       = nhanVien.ToQuanHuyenID;
                    IToRepository toRepository = uow.Repository <ToRepository>();
                    var           to           = toRepository.GetByID(nhanVien.ToQuanHuyenID ?? 0);
                    if (to != null)
                    {
                        filter.QuanHuyenID = to.QuanHuyenID;
                    }
                }
            }

            var items = khachHangRepository.GetAllKhachHangModel();

            items = filter.ApplyFilter(items);

            if (viewMode == ViewMode.Excel)
            {
                return(ExcelResult("IndexExport", items.ToList()));
            }

            items = pager.ApplyPager(items);

            #region view data
            ViewBag.NhanVien = nhanVien;
            ViewBag.Filter   = filter;
            ViewBag.Pager    = pager;
            #endregion
            return(View(items.ToList()));
        }