コード例 #1
0
        private bool IsWithinBound(ReportModelIn reportModelIn, Reservation reservation)
        {
            bool match = false;

            if ((reportModelIn.StartDate <= reservation.CheckOut) && (reportModelIn.EndDate >= reservation.CheckIn))
            {
                match = true;
            }
            return(match);
        }
コード例 #2
0
        private bool DatesMatch(ReportModelIn reportModelIn, Reservation reservation)
        {
            bool matches = false;

            if (IsWithinBound(reportModelIn, reservation))
            {
                matches = true;
            }

            return(matches);
        }
コード例 #3
0
        public List <ReportLineModelOut> GetReports(ReportModelIn reportModelIn)
        {
            List <Accommodation>      accommodations  = this.accommodationLogic.GetAllByTouristSpotName(reportModelIn.TouristSpotName);
            List <Reservation>        reservations    = this.reservationLogic.GetAll();
            List <ReportLineModelOut> reportsToReturn = new List <ReportLineModelOut>();

            foreach (Accommodation accommodation in accommodations)
            {
                ReportLineModelOut reporte = this.GetReportLineForAccommodation(accommodation, reservations, reportModelIn);
                if (reporte != null)
                {
                    reportsToReturn.Add(reporte);
                }
            }
            var reportsOrderByDescendingResult = from r in reportsToReturn
                                                 orderby r.Reservations, r.Id descending
            select r;

            return(reportsOrderByDescendingResult.ToList <ReportLineModelOut>());
        }
コード例 #4
0
        public IActionResult Get()
        {
            var queryString = HttpUtility.ParseQueryString(this.HttpContext.Request.QueryString.Value);

            if (queryString.Count == 0)
            {
                return(BadRequest("Information needed."));
            }
            else
            {
                try
                {
                    ReportModelIn reportModelIn = new ReportModelIn
                    {
                        TouristSpotName = queryString.Get("touristSpotName"),
                        EndDate         = new DateTime(
                            Int32.Parse(queryString.Get("endDateYear")),
                            Int32.Parse(queryString.Get("endDateMonth")),
                            Int32.Parse(queryString.Get("endDateDay"))
                            ),
                        StartDate = new DateTime(
                            Int32.Parse(queryString.Get("startDateYear")),
                            Int32.Parse(queryString.Get("startDateMonth")),
                            Int32.Parse(queryString.Get("startDateDay"))
                            )
                    };
                    List <ReportLineModelOut> reports = new List <ReportLineModelOut>();
                    reports = reportLogic.GetReports(reportModelIn);
                    return(Ok(reports));
                }
                catch (Exception e)
                {
                    return(BadRequest("Wrong input: incorrect query string"));
                }
            }
        }
コード例 #5
0
 private bool MatchesRequirementsForReservation(Accommodation accommodation, Reservation reservation, ReportModelIn reportModelIn)
 {
     return(MatchesName(reservation, accommodation) && reservation.ReservationSatusQualifiesForReport() && DatesMatch(reportModelIn, reservation));
 }
コード例 #6
0
        private ReportLineModelOut GetReportLineForAccommodation(Accommodation accommodation, List <Reservation> reservations, ReportModelIn reportModelIn)
        {
            ReportLineModelOut reportToReturn = new ReportLineModelOut(accommodation.Name, accommodation.Id);

            foreach (var reservation in reservations)
            {
                if (MatchesRequirementsForReservation(accommodation, reservation, reportModelIn))
                {
                    reportToReturn.Reservations++;
                }
            }
            if (reportToReturn.Reservations == 0)
            {
                return(null);
            }
            return(reportToReturn);
        }