コード例 #1
0
ファイル: BookingService.cs プロジェクト: domejuanan/club
        public async Task <BookingListResponse> ListAsync(int pageNum = 1, int pageSize = 50, string dateTimeString = null)
        {
            DateTime dateTime = default;

            if (!String.IsNullOrWhiteSpace(dateTimeString) && !DateTime.TryParse(dateTimeString, out dateTime))
            {
                return(new BookingListResponse(400, "Wrong date format", "dateTimeString", "dateTimeString format has to be: yyyy-MM-ddTHH:mm:ss"));
            }

            if (pageNum < 1 || pageSize < 1)
            {
                return(new BookingListResponse(400, "Wrong pagination", "Pagination", "pageNum and pageSize params must be greater than zero."));
            }

            int totalRecords;

            if (dateTime != default)
            {
                totalRecords = await _bookingRepository.CountDayBookingsAsync(dateTime);
            }
            else
            {
                totalRecords = await _bookingRepository.CountAsync();
            }

            var bookings = await _bookingRepository.ListBookings(dateTime, pageNum, pageSize);

            var resources    = _mapper.Map <IEnumerable <Booking>, IEnumerable <BookingResource> >(bookings);
            var resourceList = new BookingListResource(resources, pageNum, pageSize, totalRecords);

            return(new BookingListResponse(resourceList));
        }