Пример #1
0
        public IQueryable <DuAn> GetDuAn(eDuAnSearch duansearch)
        {
            var result = db.DuAns.Where(x => x.ID != 1).ToList();

            if (duansearch != null)
            {
                //search theo loại dự án
                if (duansearch.IDLoaiDuAn.HasValue && duansearch.IDLoaiDuAn != 0)
                {
                    result = result.Where(x => x.IDLoaiDuAn == duansearch.IDLoaiDuAn).ToList();
                }
                //search theo điều kiện tỉnh thành phố
                if (duansearch.IDTinhThanhPho.HasValue && duansearch.IDTinhThanhPho != 0)
                {
                    result = result.Where(x => x.QuanHuyen.IDTinhThanhPho == duansearch.IDTinhThanhPho).ToList();
                }
                //search theo điều kiện quận huyện
                if (duansearch.IDQuanHuyen.HasValue && duansearch.IDQuanHuyen != 0)
                {
                    result = result.Where(x => x.IDQuanHuyen == duansearch.IDQuanHuyen).ToList();
                }
                //search theo chuỗi
                if (!string.IsNullOrEmpty(duansearch.searchstring))
                {
                    List <DuAn> listduan = new List <DuAn>();
                    foreach (var item_result in result)
                    {
                        foreach (var item_search in TimKiemDuAnTheoChuoi(duansearch.searchstring))
                        {
                            if (item_result.ID == item_search.ID)
                            {
                                listduan.Add(item_result);
                            }
                        }
                    }
                    return(listduan.AsQueryable());
                }
            }
            return(result.AsQueryable());
        }
Пример #2
0
        public ActionResult DSDuAn(eDuAnSearch duansearch)
        {
            int idnhanvien = Convert.ToInt32(Session["nhanvien"]);

            if (idnhanvien != 0)
            {
                ViewBag.tennhanvien = db.NhanViens.Where(x => x.ID == idnhanvien).FirstOrDefault().HoTen;
            }
            else
            {
                return(RedirectToAction("../Home/Login"));
            }
            var danhsachduan = GetDuAn(duansearch);
            var model        = from o in danhsachduan
                               select new EDuAn
            {
                ID             = o.ID,
                TenDuAn        = o.TenDuAn,
                IDQuanHuyen    = o.IDQuanHuyen,
                TenQuanHuyen   = o.QuanHuyen.TenQuanHuyen,
                DonViPhanPhoi  = o.DonViPhanPhoi,
                TongDienTich   = o.TongDienTich,
                IDLoaiDuAn     = o.IDLoaiDuAn,
                TenLoaiDuAn    = o.LoaiDuAn.TenLoaiDuAn,
                MoTa           = o.MoTa,
                Urlimage       = o.Urlimage,
                TrangThai      = o.TrangThai,
                NgayDang       = o.NgayDang,
                NgayCapNhat    = o.NgayCapNhat,
                DiaChi         = o.DiaChi,
                DienTich_DonVi = o.TongDienTich + " m2",
                GiaBan_DonVi   = o.GiaBan + " Triệu/m2"
            };

            ViewBag.listloaiduan = db.LoaiDuAns.ToList();
            List <TinhThanhPho> ttp = new List <TinhThanhPho>();

            ttp.Add(new TinhThanhPho()
            {
                ID = 0, TenTinhThanhPho = "Tất cả tỉnh thành"
            });
            ttp.AddRange(db.TinhThanhPhoes.ToList());
            ViewBag.listtinhthanh = ttp.OrderBy(o => o.TenTinhThanhPho);
            if (duansearch.IDTinhThanhPho.HasValue)
            {
                List <QuanHuyen> qh = new List <QuanHuyen>();
                qh.Add(new QuanHuyen()
                {
                    ID = 0, TenQuanHuyen = "Tất cả quận huyện"
                });
                qh.AddRange(db.QuanHuyens.Where(x => x.IDTinhThanhPho == duansearch.IDTinhThanhPho).ToList());
                ViewBag.listquanhuyen = qh;
            }
            else
            {
                List <QuanHuyen> qh = new List <QuanHuyen>();
                qh.Add(new QuanHuyen()
                {
                    ID = 0, TenQuanHuyen = "Tất cả quận huyện"
                });
                ViewBag.listquanhuyen = qh;
            }
            if (Session["nhanvien"] != null)
            {
                return(View(model));
            }
            else
            {
                return(RedirectToAction("../Home/Login"));
            }
        }
Пример #3
0
        public ActionResult TimKiemDuAn(eDuAnSearch duansearch, int?page)
        {
            var danhsachduan = GetDuAn(duansearch);
            var model        = from o in danhsachduan
                               select new DuAn
            {
                ID            = o.ID,
                TenDuAn       = o.TenDuAn,
                QuanHuyen     = o.QuanHuyen,
                PhuongXa      = o.PhuongXa,
                TinhThanhPho  = o.TinhThanhPho,
                GiaBan        = o.GiaBan,
                DiaChi        = o.DiaChi,
                DonViPhanPhoi = o.DonViPhanPhoi,
                TongDienTich  = o.TongDienTich,
                IDLoaiDuAn    = o.IDLoaiDuAn,
                LoaiDuAn      = o.LoaiDuAn,
                MoTa          = o.MoTa,
                Urlimage      = o.Urlimage,
                TrangThai     = o.TrangThai,
                NgayCapNhat   = o.NgayCapNhat,
                NgayDang      = o.NgayDang,
            };

            ViewBag.duansearch = duansearch;
            ViewBag.textsearch = duansearch.searchstring;
            List <TinhThanhPho> ttp = new List <TinhThanhPho>();

            ttp.Add(new TinhThanhPho()
            {
                ID = 0, TenTinhThanhPho = " Tất cả tỉnh thành"
            });
            ttp.AddRange(db.TinhThanhPhoes.ToList());
            ViewBag.listtinhthanh = ttp.OrderBy(o => o.TenTinhThanhPho);
            ViewBag.listloaiduan  = db.LoaiDuAns.ToList();
            if (duansearch.IDTinhThanhPho.HasValue)
            {
                List <QuanHuyen> qh = new List <QuanHuyen>();
                qh.Add(new QuanHuyen()
                {
                    ID = 0, TenQuanHuyen = "Tất cả quận huyện"
                });
                qh.AddRange(db.QuanHuyens.Where(x => x.IDTinhThanhPho == duansearch.IDTinhThanhPho).ToList());
                ViewBag.listquanhuyen = qh.OrderBy(o => o.TenQuanHuyen);
            }
            else
            {
                List <QuanHuyen> qh = new List <QuanHuyen>();
                qh.Add(new QuanHuyen()
                {
                    ID = 0, TenQuanHuyen = "Tất cả quận huyện"
                });
                ViewBag.listquanhuyen = qh;
            }

            if (page > 0)
            {
                page = page;
            }
            else
            {
                page = 1;
            }
            int start = (int)(page - 1) * pageSize_duan;

            ViewBag.pageCurrent = page;
            int   totalPage    = model.Count();
            float totalNumsize = (totalPage / (float)pageSize_duan);
            int   numSize      = (int)Math.Ceiling(totalNumsize);

            ViewBag.numSize = numSize;
            model           = model.OrderByDescending(x => x.ID).Skip(start).Take(pageSize_duan);

            return(View(model));
        }