Esempio n. 1
0
        public async Task <UserStatsSummary> GetSummary(SummaryRequest request)
        {
            // get all movie requests
            var movies         = _movieRequest.GetWithUser();
            var filteredMovies = movies.Where(x => x.RequestedDate >= request.From && x.RequestedDate <= request.To);
            var tv             = _tvRequest.GetLite();
            var children       = tv.SelectMany(x =>
                                               x.ChildRequests.Where(c => c.RequestedDate >= request.From && c.RequestedDate <= request.To));

            var userMovie = filteredMovies.GroupBy(x => x.RequestedUserId).OrderBy(x => x.Key).FirstOrDefaultAsync();
            var userTv    = children.GroupBy(x => x.RequestedUserId).OrderBy(x => x.Key).FirstOrDefaultAsync();

            var moviesCount     = filteredMovies.CountAsync();
            var childrenCount   = children.CountAsync();
            var availableMovies =
                filteredMovies.Select(x => x.MarkedAsAvailable >= request.From && x.MarkedAsAvailable <= request.To).CountAsync();
            var availableChildren = children.Where(c => c.MarkedAsAvailable >= request.From && c.MarkedAsAvailable <= request.To).CountAsync();

            return(new UserStatsSummary
            {
                TotalMovieRequests = await moviesCount,
                TotalTvRequests = await childrenCount,
                CompletedRequestsTv = await availableChildren,
                CompletedRequestsMovies = await availableMovies,
                MostRequestedUserMovie = (await userMovie).FirstOrDefault()?.RequestedUser ?? new OmbiUser(),
                MostRequestedUserTv = (await userTv).FirstOrDefault()?.RequestedUser ?? new OmbiUser(),
            });
        }