/// <summary>
        /// 
        /// </summary>
        /// <param name="search"></param>
        /// <param name="status"></param>
        /// <param name="lstInclude"></param>
        /// <returns></returns>
        private IQueryable<ThongTinBaoModel> BuildQuery(ThongTinBaoSearchModel search, int status = 1, List<string> lstInclude = null)
        {
            string include = string.Empty;
            IQueryable<BThongTinBao> qThongTinBao = db.BThongTinBaos;
            //Neu co include thi them include vao
            if (lstInclude != null && lstInclude.Count > 0)
                foreach (string item in lstInclude)
                    qThongTinBao = qThongTinBao.Include(item);

            IQueryable<ThongTinBaoModel> query = (from u in qThongTinBao.Include(a => a.DMLoaiAnPham).Include(a=>a.DMToaSoan)//.Include(a=>a.)
                                                  where u.Status == status
                                                  select new ThongTinBaoModel()
                                                   {
                                                       Id = u.Id,
                                                       MaBao = u.MaBao,
                                                       MaToaSoan = u.MaToaSoan,
                                                       TenBao = u.TenBao,
                                                       CoThue = u.CoThue,
                                                       MucThue = u.MucThue.ToString(),
                                                       BaoTrungUongDiaPhuong = u.BaoTrungUongDiaPhuong,
                                                       BaoCongIchNgoaiCongIch = u.BaoCongIch,
                                                       LoaiAnPham = u.LoaiAnPham,
                                                       ParentId = u.ParentId,
                                                       BaoTrongMucLuc = u.BaoTrongMucLuc,
                                                       BaoNgoaiVan = u.BaoNgoaiVan,
                                                       SoTrang = u.SoTrang.ToString(),
                                                       KichThuoc = u.KichThuoc,
                                                       TrongLuong = u.TrongLuong.ToString(),
                                                       GiayPhep = u.GiayPhep,
                                                       GiaVon = u.GiaVon,
                                                       GiaBia = u.GiaBia.ToString(),
                                                       GiaBan = u.GiaBan,
                                                       Status = u.Status,
                                                       GhiChu = u.GhiChu,
                                                       TenLoaiAnPham = u.DMLoaiAnPham != null ? u.DMLoaiAnPham.TenLoaiAnPham : "",
                                                       TenToaSoan = u.DMToaSoan != null ? u.DMToaSoan.TenToaSoan : ""
                                                   }).OrderBy(a => a.TenBao);
            if (search != null)
            {
                if (!string.IsNullOrWhiteSpace(search.Search))
                {
                    query = query.Where(a => a.MaBao.Contains(search.Search) || a.TenBao.Contains(search.Search));
                }
                if (!string.IsNullOrWhiteSpace(search.Id))
                    query = query.Where(a => a.Id.CompareTo(search.Id) == 0);
                if (!string.IsNullOrWhiteSpace(search.MaBao))
                    query = query.Where(a => a.MaBao.Contains(search.MaBao));
                if (!string.IsNullOrWhiteSpace(search.MaToaSoan))
                    query = query.Where(a => a.MaBao.Contains(search.MaToaSoan));
                if (!string.IsNullOrWhiteSpace(search.TenBao))
                    query = query.Where(a => a.TenBao.Contains(search.TenBao));
                if (!string.IsNullOrWhiteSpace(search.GiaBia))
                    query = query.Where(a => a.GiaBia.Contains(search.GiaBia));
                if (!string.IsNullOrWhiteSpace(search.TrongLuong))
                    query = query.Where(a => a.TrongLuong.Contains(search.TrongLuong));
                if (!string.IsNullOrWhiteSpace(search.KichThuoc))
                    query = query.Where(a => a.KichThuoc.Contains(search.KichThuoc));
                if (!string.IsNullOrWhiteSpace(search.GiayPhep))
                    query = query.Where(a => a.KichThuoc.Contains(search.GiayPhep));
            }
            return query;
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="Id"></param>
 /// <returns></returns>
 public ThongTinBaoModel getThongTinBaoById(string Id)
 {
     ThongTinBaoSearchModel search = new ThongTinBaoSearchModel() { Id = Id };
     int active = (int)Enums.RecordStatusCode.active;
     ThongTinBaoModel item = BuildQuery(search, active, null).FirstOrDefault();
     buildThongTinBao(item);
     return item;
 }
 public List<ThongTinBaoModel> searchThongTinBao(ThongTinBaoSearchModel thongTinBaoSearchModel)
 {
     int active = (int)Enums.RecordStatusCode.active;
     return BuildQuery(thongTinBaoSearchModel, active, null).ToList();
 }
 public ActionResult GetMaBaoCha(string search, string pageIndex)
 {
     List<ThongTinBaoModel> value = new List<ThongTinBaoModel>();
     int pageCount = 0;
     int totalitem = 0;
     if(string.IsNullOrWhiteSpace(search))
         value = db.getAllModel(1, pageSizePopup, out pageCount, out totalitem);
     else
     {
         ThongTinBaoSearchModel searchModel = new ThongTinBaoSearchModel() { Search = search };
         value = db.searchThongTinBao(searchModel);
     }
     ViewBag.Search = search;
     if (HttpContext.Request.IsAjaxRequest())
         return PartialView("_TimKiemMaBaoCha", new PagedList<ThongTinBaoModel>(value, 1, pageSizePopup, totalitem));
     return PartialView("_TimKiemMaBaoCha", new PagedList<ThongTinBaoModel>(value, 1, pageSizePopup, totalitem));
 }