private List <RentalHistoryPerDate> GetMovieRentalHistoryPerDates(int movieId)
        {
            var listHistory   = new List <RentalHistoryPerDate>();
            var rentalHistory = GetMovieRentalHistory(movieId);

            if (rentalHistory.Count > 0)
            {
                var distinctDates = new List <DateTime>();
                distinctDates = rentalHistory.Select(h => h.RentalDate.Date).Distinct().ToList();

                foreach (var distinctDate in distinctDates)
                {
                    var totalDateRentals          = rentalHistory.Count(r => r.RentalDate.Date == distinctDate);
                    var movieRentalHistoryPerDate = new RentalHistoryPerDate
                    {
                        Date         = distinctDate,
                        TotalRentals = totalDateRentals
                    };

                    listHistory.Add(movieRentalHistoryPerDate);
                }

                listHistory.Sort((r1, r2) => r1.Date.CompareTo(r2.Date));
            }

            return(listHistory);
        }
Exemple #2
0
        private List <RentalHistoryPerDate> GetMovieRentalHistoryPerDates(int movieId)
        {
            List <RentalHistoryPerDate>   listHistory    = new List <RentalHistoryPerDate>();
            List <RentalHistoryViewModel> _rentalHistory = GetMovieRentalHistory(movieId);

            if (_rentalHistory.Count > 0)
            {
                List <DateTime> _distinctDates = new List <DateTime>();
                _distinctDates = _rentalHistory.Select(h => h.RentalDate.Date).Distinct().ToList();

                foreach (var distinctDate in _distinctDates)
                {
                    var totalDateRentals = _rentalHistory.Count(r => r.RentalDate.Date == distinctDate);
                    RentalHistoryPerDate _movieRentalHistoryPerDate = new RentalHistoryPerDate()
                    {
                        Date         = distinctDate,
                        TotalRentals = totalDateRentals
                    };

                    listHistory.Add(_movieRentalHistoryPerDate);
                }

                listHistory.Sort((r1, r2) => r1.Date.CompareTo(r2.Date));
            }

            return(listHistory);
        }