Esempio n. 1
0
        public Dashboard CaluclateDashboard(int UserID)
        {
            Dashboard d = new Dashboard(); //meaningful calc

            using (ContextBLL ctx = new ContextBLL())
            {
                List <MovieUserBLL> L = new List <MovieUserBLL>();
                L = ctx.GetMovieUsers(0, 100);
                d.TotalCountForAllDownloads = L.Count;
                var q1    = from u in L where u.UserID == UserID select u;
                var Users = q1.ToList();
                d.TotalCountForThisUser = Users.Count;
                var q2       = from u in L group u by u.UserID into g select new { UserID = g.Key, Count = g.Count(), AverageDuration = g.Average(x => x.Length) };
                var averages = q2.ToList();

                List <MovieBLL> M = new List <MovieBLL>();
                M = ctx.GetMovies(0, 100);
                var q3     = from u in M group u by u.MovieID into g select new { MovieIdD = g.Key, Duration = g.Sum(x => x.Length), AverageDuration = g.Average(x => x.Length) };
                var movies = q3.ToList();
                if (movies.Count > 0)
                {
                    d.TotalLengthOfAllMovies   = movies.Sum(x => x.Duration);
                    d.AverageLengthOfAllMovies = movies.Average(x => x.Duration);
                }
                else
                {
                }
                //if (averages.Count > 0)
                //{
                //    d.AverageCountOfAllDownloads = averages.Average(x => x.AverageDuration);
                //}
                //else
                //{
                //    d.AverageCountOfAllDownloads = 0;
                //}
                if (Users.Count > 0)
                {
                    d.TotalDurationForThisUser = Users.Sum(x => x.Length);

                    d.AverageDurationForThisUser = Users.Average(x => x.Length);
                }
                else
                {
                    d.TotalDurationForThisUser   = 0;
                    d.AverageDurationForThisUser = 0;
                }
                if (L.Count > 0)
                {
                    d.AverageDurationOfMoviesDownloaded = L.Average(x => x.Length);

                    d.TotalDurationMoviesDownloaded = L.Sum(x => x.Length);
                }
                else
                {
                    d.AverageDurationOfMoviesDownloaded = 0;
                    d.TotalDurationMoviesDownloaded     = 0;
                }
            }
            return(d);
        }