Exemple #1
0
        public List <HallOfFameResponse> ListHallOfFame()
        {
            var cacheKey   = "HallOfFameCache";
            var hallOfFame = MemoryCache.Get <List <HallOfFameResponse> >(cacheKey);

            if (hallOfFame == null)
            {
                hallOfFame = new List <HallOfFameResponse>();
                var advisorsMonthlyRanking = Data.ListAdvisorsHallOfFame(3);
                if (advisorsMonthlyRanking.Any())
                {
                    var advisors          = AdvisorRankingBusiness.ListAdvisorsFullData();
                    var advisorsFollowers = FollowAdvisorBusiness.ListFollowers(advisorsMonthlyRanking.Select(c => c.UserId).Distinct(), false);
                    var user            = GetLoggedUser();
                    var groupedAdvisors = advisorsMonthlyRanking.GroupBy(c => new { c.Year, c.Month });
                    foreach (var data in groupedAdvisors)
                    {
                        var item = new HallOfFameResponse();
                        item.Year  = data.Key.Year;
                        item.Month = data.Key.Month;
                        foreach (var advisor in data)
                        {
                            var advisorRanking = advisors.FirstOrDefault(c => c.Id == advisor.UserId);
                            if (advisorRanking != null)
                            {
                                item.Advisors.Add(AdvisorRankingBusiness.GetAdvisorResponse(advisorRanking, advisors.Count, advisorsFollowers, user, null, null, null, advisor));
                            }
                        }
                        hallOfFame.Add(item);
                    }
                    MemoryCache.Set <List <HallOfFameResponse> >(cacheKey, hallOfFame, 1440);
                }
            }
            return(hallOfFame);
        }
Exemple #2
0
        public IEnumerable <AdvisorResponse> ListAdvisorsData()
        {
            var advisors          = AdvisorRankingBusiness.ListAdvisorsFullData();
            var advisorsFollowers = FollowAdvisorBusiness.ListFollowers(advisors.Select(c => c.Id).Distinct(), false);
            var user = GetLoggedUser();

            return(advisors.Select(c => AdvisorRankingBusiness.GetAdvisorResponse(c, advisors.Count, advisorsFollowers, user, null, null, null, null)).OrderBy(c => c.Ranking));
        }
Exemple #3
0
        public IEnumerable <AdvisorResponse> ListAdvisorsMonthlyRanking(int?year, int?month)
        {
            var advisors          = AdvisorRankingBusiness.ListAdvisorsFullData();
            var advisorsIds       = advisors.Select(c => c.Id).Distinct().ToHashSet();
            var advisorsFollowers = FollowAdvisorBusiness.ListFollowers(advisorsIds, false);
            var user = GetLoggedUser();

            List <AdvisorMonthlyRanking> ranking = null;
            List <AdvisorRankingHistory> monthBeginningHistory = null;

            if (year.HasValue && month.HasValue && !(year == Data.GetDateTimeNow().Year&& month == Data.GetDateTimeNow().Month))
            {
                ranking = AdvisorMonthlyRankingBusiness.ListAdvisorsMonthlyRanking(year.Value, month.Value);
            }
            if (ranking == null || ranking.Count == 0)
            {
                monthBeginningHistory = AdvisorRankingHistoryBusiness.ListAdvisorsRankingAndProfitForMonthBeginning(advisorsIds);
            }

            var result = new List <AdvisorResponse>();

            foreach (var advisor in advisors)
            {
                if (monthBeginningHistory != null)
                {
                    var data = monthBeginningHistory.FirstOrDefault(c => c.UserId == advisor.Id);
                    if (data != null)
                    {
                        result.Add(AdvisorRankingBusiness.GetAdvisorResponse(advisor, advisors.Count, advisorsFollowers, user, null, null, data, null));
                    }
                }
                else
                {
                    var data = ranking.FirstOrDefault(c => c.UserId == advisor.Id);
                    if (data != null)
                    {
                        result.Add(AdvisorRankingBusiness.GetAdvisorResponse(advisor, advisors.Count, advisorsFollowers, user, null, null, null, data));
                    }
                }
            }
            if (monthBeginningHistory != null)
            {
                result = result.OrderByDescending(c => c.MonthlyRankingHistory.ProfitPercentage).ThenByDescending(c => c.UserId).ToList();
                for (int i = 0; i < result.Count; ++i)
                {
                    result[i].MonthlyRankingHistory.Ranking = i + 1;
                }
            }
            else
            {
                result = result.OrderBy(c => c.MonthlyRankingHistory.Ranking).ToList();
            }

            return(result);
        }
Exemple #4
0
        public AdvisorResponse GetAdvisorData(int advisorId)
        {
            AdvisorRanking advisor = null;
            List <DomainObjects.Asset.Asset> assets            = null;
            List <FollowAdvisor>             advisorsFollowers = null;
            AdvisorRankingHistory            advisorHistory    = null;

            Parallel.Invoke(() => advisor           = AdvisorRankingBusiness.GetAdvisorFullData(advisorId),
                            () => assets            = AssetBusiness.ListAssets(false),
                            () => advisorsFollowers = FollowAdvisorBusiness.ListFollowers(new int[] { advisorId }, false),
                            () => advisorHistory    = AdvisorRankingHistoryBusiness.GetLastAdvisorRankingAndProfit(advisorId));

            return(AdvisorRankingBusiness.GetAdvisorResponse(advisor, advisor.TotalAdvisors, advisorsFollowers, GetLoggedUser(), assets, advisorHistory, null, null));
        }