コード例 #1
0
ファイル: RoomsController.cs プロジェクト: nivhojberg/Lowtel
        // GET: Rooms
        public async Task <IActionResult> Index(string searchString)
        {
            IQueryable <Room> rooms = _context.Set <Room>();

            rooms = rooms.Include(r => r.Hotel).Include(r => r.RoomType);

            if (!String.IsNullOrEmpty(searchString))
            {
                int numberSearch;

                rooms = rooms.Where(r =>
                                    r.Hotel.Name.Contains(searchString) ||
                                    r.Hotel.State.Contains(searchString) ||
                                    r.RoomType.Name.Contains(searchString) ||
                                    (Int32.TryParse(searchString, out numberSearch) &&
                                     (r.Id == numberSearch || r.RoomType.PriceForNight == numberSearch)));
            }


            rooms = rooms.OrderBy(r => r.HotelId).ThenBy(r => r.Id);

            return(View(await rooms.ToListAsync()));
        }
コード例 #2
0
        // GET: Reservations
        public async Task <IActionResult> Index(string searchString)
        {
            if (HttpContext.Session.GetString(UsersController.SessionName) != null)
            {
                if (CountOfRoomTypeOnReservations() > 1)
                {
                    TrainReservationsData();
                }

                IQueryable <Reservation> reservations = _context.Set <Reservation>();

                reservations = reservations.Include(r => r.Client).
                               Include(r => r.Hotel).
                               Include(r => r.Room).
                               Include(r => r.Room.RoomType);

                if (!String.IsNullOrEmpty(searchString))
                {
                    int numberSearch;

                    reservations = reservations.Where(r =>
                                                      r.Hotel.Name.Contains(searchString) ||
                                                      r.Hotel.State.Contains(searchString) ||
                                                      r.Client.Id.Contains(searchString) ||
                                                      (Int32.TryParse(searchString, out numberSearch) && r.RoomId == numberSearch));
                }

                reservations = reservations.OrderByDescending(r => r.CheckInDate);

                return(View(await reservations.ToListAsync()));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }