예제 #1
0
        public ActionResult ViewLeaderboard()
        {
            FungeyeDAL DAL = new FungeyeDAL();

            List <UserMushroom> emails = DAL.GetAllUserMushrooms();
            //select Email, count(distinct MushroomID) [UniqueIds], count(mushroomId) [Total] from UserMushroom group by email
            var groups = emails.GroupBy(x => x.Email).Select(x => new { EmailName = x.Key, EmailCount = x.Count() }).OrderBy(x => x.EmailCount).Reverse().ToList();

            var uniqueC = DAL.GetUniqueMushroomCount();

            var lst =
                (from res in groups
                 join res2 in uniqueC
                 on res.EmailName equals res2.Email
                 select new Leaderboard
            {
                Email = res.EmailName,
                TotalCount = res.EmailCount,
                UniqueCount = res2.Count
            }).ToList();

            ViewBag.Leaderboard = lst.OrderByDescending(x => x.TotalCount).ToList();

            return(View());
        }
예제 #2
0
        public ContentResult SortLeaderboard(string sortOption)
        {
            FungeyeDAL DAL = new FungeyeDAL();

            List <UserMushroom> userMushrooms = DAL.GetAllUserMushrooms();

            var groups = userMushrooms.GroupBy(x => x.Email).Select(x => new { EmailName = x.Key, EmailCount = x.Count() }).OrderBy(x => x.EmailCount).Reverse().ToList();

            var uniqueC = DAL.GetUniqueMushroomCount();

            var lst =
                (from res in groups
                 join res2 in uniqueC
                 on res.EmailName equals res2.Email
                 select new Leaderboard
            {
                Email = res.EmailName,
                TotalCount = res.EmailCount,
                UniqueCount = res2.Count
            }).ToList();

            if (sortOption == "totalCount")
            {
                lst = lst.OrderByDescending(x => x.TotalCount).ToList();
            }
            else if (sortOption == "uniqueCount")
            {
                lst = lst.OrderByDescending(x => x.UniqueCount).ToList();
            }
            else
            {
                lst = lst.OrderBy(x => x.Email).ToList();
            }

            var list = JsonConvert.SerializeObject(lst,
                                                   Formatting.None,
                                                   new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            return(Content(list, "application/json"));
        }