private bool IsWithinBound(ReportModelIn reportModelIn, Reservation reservation) { bool match = false; if ((reportModelIn.StartDate <= reservation.CheckOut) && (reportModelIn.EndDate >= reservation.CheckIn)) { match = true; } return(match); }
private bool DatesMatch(ReportModelIn reportModelIn, Reservation reservation) { bool matches = false; if (IsWithinBound(reportModelIn, reservation)) { matches = true; } return(matches); }
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>()); }
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")); } } }
private bool MatchesRequirementsForReservation(Accommodation accommodation, Reservation reservation, ReportModelIn reportModelIn) { return(MatchesName(reservation, accommodation) && reservation.ReservationSatusQualifiesForReport() && DatesMatch(reportModelIn, reservation)); }
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); }