Esempio n. 1
0
        public List <UserViewingByDate> GetLast30Days(List <UserWatchedFilmItemOn> filmItems)
        {
            List <DateTime> thirtyDaysDateList = new List <DateTime>();

            for (DateTime d = DateTime.Now.AddDays(-29); d <= DateTime.Now; d = d.AddDays(1))
            {
                thirtyDaysDateList.Add(d.Date);
            }

            List <UserViewingByDate> userViewingsList = new List <UserViewingByDate>();

            foreach (var date in thirtyDaysDateList)
            {
                UserViewingByDate userViewingByDate = new UserViewingByDate();
                userViewingByDate.Date = date;

                var userViewing = GetUserWatchedLast30Days(filmItems, userViewingByDate);
                userViewingsList.Add(userViewing);
            }

            return(userViewingsList);
        }
Esempio n. 2
0
        public UserViewingByDate GetUserWatchedLast30Days(List <UserWatchedFilmItemOn> filmItems, UserViewingByDate userViewingByDate)
        {
            int?timeWatched      = 0;
            var orderedFilmItems = filmItems.Where(f => f.FilmItem.Discriminator == "Movie" || f.FilmItem.Discriminator == "Episode").OrderByDescending(f => f.WatchedOn);

            foreach (var filmItemWatched in orderedFilmItems)
            {
                if (userViewingByDate.Date == filmItemWatched.WatchedOn.Date)
                {
                    timeWatched += filmItemWatched.FilmItem.Runtime;
                    if (filmItemWatched.FilmItem.Discriminator == "Episode")
                    {
                        userViewingByDate.AmountOfEpisodes++;
                    }
                    else if (filmItemWatched.FilmItem.Discriminator == "Movie")
                    {
                        userViewingByDate.AmountOfMovies++;
                    }
                }
            }
            userViewingByDate.TimeWatched = timeWatched;

            return(userViewingByDate);
        }