public ActionResult <IEnumerable <BookingAdapterOut> > Get([FromQuery] long start, long end, int productId)
        {
            try
            {
                List <BookingOrder> bookings;
                if (start == 0 && end == 0)
                {
                    bookings = _bookingService.ReadAll();
                }
                else
                {
                    bookings = _bookingService.ReadByWeek(DateConverter.FromUTCEpochToDatetime(start), DateConverter.FromUTCEpochToDatetime(end), productId);
                }

                List <BookingAdapterOut> bookingsOut = new List <BookingAdapterOut>();
                foreach (BookingOrder item in bookings)
                {
                    bookingsOut.Add(new BookingAdapterOut
                    {
                        Id                 = item.Id,
                        Product            = item.Product,
                        User               = item.User,
                        StartTimeOfBooking = DateConverter.FromDatetimeToUTCEpoch(item.StartTimeOfBooking),
                        EndTimeOfBooking   = DateConverter.FromDatetimeToUTCEpoch(item.EndTimeOfBooking)
                    });
                }
                return(Ok(bookings));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Пример #2
0
        public void TestBookingOrderServiceReadAll(long id, int addStart, int addEnd)
        {
            DateTime start   = DateTime.Now.AddHours(addStart);
            DateTime end     = DateTime.Now.AddHours(addEnd);
            UserInfo user    = new UserInfo();
            Product  product = new Product();

            IEnumerable <BookingOrder> users = new List <BookingOrder>
            {
                new BookingOrder()
                {
                    Id                 = id,
                    User               = user,
                    Product            = product,
                    StartTimeOfBooking = start,
                    EndTimeOfBooking   = end
                }
            };

            _mockRepo.Setup(repo => repo.ReadAll()).Returns(users);
            _service.ReadAll();
            _mockRepo.Verify(x => x.ReadAll(), Times.Once);
        }