コード例 #1
0
        // GET: Admin/GetListDatPhongs
        public IActionResult Index(GetListDatPhongIndexVM getListDatPhongIndexVm, string sortOrder)
        { // getlist phong trong theo ngay den ngay di.
          // có 2 ô ngày đến ngày đi nhập vô.
          // tìm phòng ngày đó.
          // chọn phòng
            var  lsPhongsDb  = from m in _context.Phongs select m;
            bool isFillterDb = false;

            if (getListDatPhongIndexVm.NgayNhanPhongDuKien != default)
            {
                // tìm tất cả các phòng trong chi tiết đặt phòng theo ngày đến, ngày đi
                var thoiGianNhanSqlParameter = new SqlParameter
                {
                    ParameterName = "@ThoiGianNhan",
                    SqlDbType     = SqlDbType.Date,
                    SqlValue      = getListDatPhongIndexVm.NgayNhanPhongDuKien
                };
                var thoiGianTraSqlParameter = new SqlParameter
                {
                    ParameterName = "@ThoiGianTra",
                    SqlDbType     = SqlDbType.Date,
                    SqlValue      = getListDatPhongIndexVm.NgayTraPhongDuKien
                };
                lsPhongsDb  = _context.Phongs.FromSqlRaw($"EXECUTE dbo.TimPhongLienTuc @ThoiGianNhan,@ThoiGianTra ", thoiGianNhanSqlParameter, thoiGianTraSqlParameter);
                isFillterDb = true;
            }
            var getListDatPhongIndexVm2 = new GetListDatPhongIndexVM
            {
                LsPhongDatPhongs = lsPhongsDb.ToList(),
                isFillter        = isFillterDb
            };

            return(View(getListDatPhongIndexVm2));
        }
コード例 #2
0
        // GET: Admin/GetListDatPhongs
        public IActionResult Index(GetListDatPhongIndexVM getListDatPhongIndexVm, string sortOrder)
        { // getlist phong trong theo ngay den ngay di.
          // có 2 ô ngày đến ngày đi nhập vô.
          // tìm phòng ngày đó.
          // chọn phòng
          //var applicationDbContext = _context.Phongs.Include(p => p.ChuongTrinh).Include(p => p.LoaiPhong);
            var  lsPhongsDb  = from m in _context.Phongs select m;
            bool isFillterDb = false;

            if (getListDatPhongIndexVm.NgayNhanPhongDuKien != default)
            {
                // tìm tất cả các phòng trong chi tiết đặt phòng theo ngày đến, ngày đi
                var ListId = from m in _context.ChiTietDatPhongs
                             where m.ThoiGian.Date >= getListDatPhongIndexVm.NgayNhanPhongDuKien.Date &&
                             m.ThoiGian.Date <= getListDatPhongIndexVm.NgayTraPhongDuKien.Date
                             select m.PhongId;

                lsPhongsDb  = _context.Phongs.Where(r => !ListId.Contains(r.Id));
                isFillterDb = true;
            }
            var getListDatPhongIndexVm2 = new GetListDatPhongIndexVM
            {
                LsPhongDatPhongs = lsPhongsDb.Include(c => c.LoaiPhong).Include(c => c.ChuongTrinh).ToList(),
                isFillter        = isFillterDb
            };

            return(View(getListDatPhongIndexVm2));
        }