public StatisticsDownloaders GetStatisticDownloaders(string userId) { StatisticsDownloaders statisticsDownloaders = new Models.StatisticsDownloaders(); List <BestBuyers> bests = new List <BestBuyers>(); try { List <string> buyersEmail = new UserService().GetBuyerEmail(userId); List <string> buyersSum = new List <string>(); List <string> buyersCount = new List <string>(); foreach (var item in buyersEmail) { BestBuyers b = new BestBuyers(); b.Email = item; b.Sum = new UserService().GetOrderSum(item, "email").ToString().Replace(',', '.'); b.CountD = new UserService().GetOrdersCount(item, "email"); bests.Add(b); } statisticsDownloaders.bestBuyers = bests; } catch (Exception ex) { statisticsDownloaders.bestBuyers = null; } return(statisticsDownloaders); }
public ForStatistics GetStatistic(string userId) { List <BestBuyers> bests; ForStatisticsMy statisticsMy = new ForStatisticsMy(); try { statisticsMy.CountDownloads = new UserService().GetOrdersCount(userId); } catch (Exception ex) { statisticsMy.CountDownloads = 0; } try { statisticsMy.CountLikes = new ImageService().GetUserLikesCount(userId); } catch (Exception ex) { statisticsMy.CountLikes = 0; } try { statisticsMy.SumTotal = new UserService().GetOrderSum(userId).ToString(); } catch (Exception ex) { statisticsMy.SumTotal = "0"; } if (statisticsMy.SumTotal.ToString().IndexOf(',') >= 0) { statisticsMy.SumTotal = statisticsMy.SumTotal.ToString().Replace(',', '.'); } bests = new List <BestBuyers>(); try { List <string> buyersEmail = new UserService().GetBuyerEmail(userId); List <string> buyersSum = new List <string>(); int q = 0; double sum = 0; foreach (var item in buyersEmail) { q++; if (q < 4) { BestBuyers b = new BestBuyers(); b.Email = item; b.Sum = new UserService().GetOrderSum(item, "email").ToString().Replace(',', '.'); bests.Add(b); } else { sum += new UserService().GetOrderSum(item, "email"); } } if (sum > 0) { BestBuyers b = new BestBuyers(); b.Email = "Другие"; b.Sum = sum.ToString().Replace(',', '.'); bests.Add(b); } statisticsMy.bestBuyers = bests; } catch (Exception ex) { statisticsMy.bestBuyers = null; } ForStatisticsCommon statisticsCommon = new ForStatisticsCommon(); statisticsCommon.I = 3947; DateTime date = DateTime.Now.Subtract(new TimeSpan(7, 0, 0, 0)); try { var it = new UserService().GetOrderSum(type: "email", date: date); statisticsCommon.CommonSum = it.ToString().Replace(',', '.'); } catch (Exception) { statisticsCommon.CommonSum = "13.39"; } IEnumerable <QuerysPopular> querys1 = new UserService().GetQuerysPopularsAll(); statisticsCommon.SearchWords = querys1.GroupBy(j => j.QueryStr).Take(16).ToList(); return(new ForStatistics() { forStatisticsMy = statisticsMy, forStatisticsCommon = statisticsCommon }); }