public async Task <PagedList <Booking> > GetAllBookings(BookingParams bookingParams)
        {
            var bookings = _context.Bookings
                           .Include(b => b.ShowTime)
                           .Include(b => b.User).AsQueryable();

            if (!string.IsNullOrEmpty(bookingParams.ShowName))
            {
                bookings = bookings.Where(b =>
                                          b.ShowTime.Show.Name.ToLower().Contains(bookingParams.ShowName.ToLower()));
            }
            if (!string.IsNullOrEmpty(bookingParams.StartDate.ToString()))
            {
                bookings = bookings.Where(b => b.ShowTime.StartDate >= bookingParams.StartDate);
            }
            if (!string.IsNullOrEmpty(bookingParams.EndDate.ToString()))
            {
                bookings = bookings.Where(b => b.ShowTime.StartDate <= bookingParams.EndDate);
            }

            // check if the user is client
            if (_httpContextService.IsClient())
            {
                // show only the client's bookings
                var userId = _httpContextService.GetUserId();
                bookings = bookings.Where(b => b.UserId == userId).AsQueryable();
            }
            return(await PagedList <Booking> .CreateAsync(bookings.OrderBy(b => b.ShowTime.StartDate),
                                                          bookingParams.PageNumber, bookingParams.PageSize));
        }
示例#2
0
        public PagedList <Booking> GetBookingsForBooker(BookingParams bookingParams)
        {
            var bookings = _context.Bookings.Include(b => b.User).Include(b => b.Feedback).Include(b => b.Lab).ThenInclude(l => l.Owner)
                           .Where(b => b.UserId == bookingParams.BookerId)
                           .OrderByDescending(b => b.Id)
                           .AsQueryable();

            return(PagedList <Booking> .Create(bookings, bookingParams.PageNumber, bookingParams.PageSize));
        }
        public async Task <IActionResult> GetBookings([FromQuery] BookingParams bookingParams)
        {
            var bookings = await _service.GetAllBookings(bookingParams);

            Response.AddPagination(bookings.CurrentPage,
                                   bookings.PageSize, bookings.TotalCount,
                                   bookings.TotalPages);
            return(Ok(bookings));
        }
        public IEnumerable <BookingForDetailed> GetBookingForBooker([FromQuery] BookingParams bookingParams)
        {
            bookingParams.BookerId = Convert.ToInt32(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            var bookings = _service.GetBookingsForBooker(bookingParams);

            Response.AddPagination(bookings.CurrentPage, bookings.PageSize, bookings.TotalCount, bookings.TotalPages);

            return(_mapper.Map <IEnumerable <BookingForDetailed> >(bookings));
        }
示例#5
0
        public async Task <IActionResult> GetBookings([FromQuery] BookingParams bookingParams)
        {
            var bookings = await _repo.GetBookings(bookingParams);

            var bookingsToReturn = _mapper.Map <IEnumerable <BookingForListDto> >(bookings);

            Response.AddPagination(bookings.CurrentPage, bookings.PageSize, bookings.TotalCount, bookings.TotalPages);

            return(Ok(bookingsToReturn));
        }
        public object GetTotalPages([FromQuery] BookingParams bookingParams)
        {
            bookingParams.BookerId = Convert.ToInt32(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            var bookings = _service.GetBookingsForBooker(bookingParams);

            return(new
            {
                TotalPages = bookings.TotalPages
            });
        }
示例#7
0
        public async Task <PagedList <Booking> > GetBookings(BookingParams bookingParams)
        {
            var bookings = _context.Bookings.OrderByDescending(b => b.DateAdded).AsQueryable();

            //Get the current Month, Year and Day
            var month      = DateTime.Now.Month;
            var year       = DateTime.Now.Year;
            var day        = DateTime.Now.Day;
            var dayPlusOne = DateTime.Now.AddDays(1);

            if (bookingParams.EventsThisMonth)
            {
                bookings = bookings.Where(b => b.When.Year == year && b.When.Month == month);
            }

            if (bookingParams.EventsToday)
            {
                bookings = bookings.Where(b => (b.When.Year == year && b.When.Month == month) && b.When.Day == day);
            }

            if (bookingParams.EventsTomorrow)
            {
                bookings = bookings.Where(b => (b.When.Year == year && b.When.Month == month) && b.When.Day == dayPlusOne.Day);
            }

            if (bookingParams.Status != null)
            {
                bookings = bookings.Where(b => b.Status == bookingParams.Status);
            }

            if (!string.IsNullOrEmpty(bookingParams.OrderBy))
            {
                switch (bookingParams.OrderBy)
                {
                case "dateadded":
                    bookings = bookings.OrderByDescending(b => b.DateAdded);
                    break;

                default:
                    bookings = bookings.OrderByDescending(b => b.When);
                    break;
                }
            }

            return(await PagedList <Booking> .CreateAsync(bookings, bookingParams.PageNumber, bookingParams.PageSize));
        }
示例#8
0
        public PagedList <Booking> GetBookingsForManager(BookingParams bookingParams)
        {
            IQueryable <Booking> bookings;

            if (bookingParams.OwnerId == 8)
            {
                bookings = _context.Bookings.Include(b => b.Lab).Include(b => b.User).Include(b => b.Feedback)
                           .OrderByDescending(b => b.Id);
            }
            else
            {
                bookings = _context.Bookings.Include(b => b.Lab).Include(b => b.User).Include(b => b.Feedback)
                           .Where(b => b.Lab.OwnerId == bookingParams.OwnerId)
                           .OrderByDescending(b => b.Id)
                           .AsQueryable();
            }

            return(PagedList <Booking> .Create(bookings, bookingParams.PageNumber, bookingParams.PageSize));
        }
示例#9
0
        public async Task <IActionResult> GetBookingsForUser(int userId, [FromQuery] BookingParams bookingParams)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var bookings = await _repo.GetBookingsForUser(userId, bookingParams);

            if (bookings == null)
            {
                return(BadRequest());
            }

            var bookingsToReturn = _mapper.Map <IEnumerable <BookingForDetailedDto> >(bookings);

            Response.AddPagination(bookings.CurrentPage, bookings.PageSize, bookings.TotalCount, bookings.TotalPages);

            return(Ok(bookingsToReturn));
        }
示例#10
0
 public Request()
 {
     Details = new BookingParams();
 }
示例#11
0
		public Request() 
		{
			Details = new BookingParams ();
		}