public HttpResponseMessage TotalRentalHistory(HttpRequestMessage request) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; var totalMoviesRentalHistory = new List <TotalRentalHistoryViewModel>(); var movies = _moviesRepository.GetAll(); foreach (var movie in movies) { var totalRentalHistory = new TotalRentalHistoryViewModel { ID = movie.ID, Title = movie.Title, Image = movie.Image, Rentals = GetMovieRentalHistoryPerDates(movie.ID) }; if (totalRentalHistory.TotalRentals > 0) { totalMoviesRentalHistory.Add(totalRentalHistory); } } response = request.CreateResponse(HttpStatusCode.OK, totalMoviesRentalHistory); return response; })); }
public IHttpActionResult TotalRentalHistory(HttpRequestMessage request) { _requiredRepositories = new List <Type>() { typeof(Customer), typeof(Stock), typeof(Rental), typeof(Customer), typeof(Movie) }; return(CreateHttpResponse(request, _requiredRepositories, () => { HttpResponseMessage response = null; List <TotalRentalHistoryViewModel> _totalMoviesRentalHistory = new List <TotalRentalHistoryViewModel>(); var movies = _moviesRepository.GetAll().ToList(); foreach (var movie in movies) { TotalRentalHistoryViewModel _totalRentalHistory = new TotalRentalHistoryViewModel() { ID = movie.ID, Title = movie.Title, Image = movie.Image, Rentals = GetMovieRentalHistoryPerDates(movie.ID) }; if (_totalRentalHistory.TotalRentals > 0) { _totalMoviesRentalHistory.Add(_totalRentalHistory); } } response = request.CreateResponse(HttpStatusCode.OK, _totalMoviesRentalHistory); return response; })); }