Ejemplo n.º 1
0
        private void AdjustTopSellers(TopSellersToken token)
        {
            if (token.Top_EUR.Count < 5)
            {
                var currency = ActiveCurrencies.FirstOrDefault(x => x.CurrencyId == EUR_CURRENCY_ID);

                var toAdd = 5 - token.Top_EUR.Count;

                for (var i = 0; i < toAdd; i++)
                {
                    token.Top_EUR.Add(new AuthorPayoutToken {
                        Currency = currency
                    });
                }
            }

            if (token.Top_USD.Count < 5)
            {
                var currency = ActiveCurrencies.FirstOrDefault(x => x.CurrencyId == USD_CURRENCY_ID);

                var toAdd = 5 - token.Top_USD.Count;

                for (var i = 0; i < toAdd; i++)
                {
                    token.Top_USD.Add(new AuthorPayoutToken {
                        Currency = currency
                    });
                }
            }
        }
Ejemplo n.º 2
0
        public AdminDashboardToken GetAdminDashboardToken()
        {
            try
            {
                var now = DateTime.Now;

                var prev = now.AddMonths(-1);

                var rows = _payoutServices.GetPayoutCurrencySummaryRows(now.Year, now.Month, null, null, -1);

                var previous = _payoutServices.GetPayoutCurrencySummaryRows(prev.Year, prev.Month, null, null, -1);

                var p = new List <AdminPayoutToken>();

                var sellerTop = new TopSellersToken();

                foreach (var token in rows)
                {
                    var pt = token.PayoutCurrencySummaryDto2AdminPayoutToken();

                    var row = previous.FirstOrDefault(x => x.Currency.CurrencyId == token.Currency.CurrencyId);

                    var tendency = new TendencyToken();

                    if (row == null)
                    {
                        tendency.Direction = ReportEnums.eTendencyDirections.Up;
                        tendency.Percent   = 100;
                    }
                    else
                    {
                        if (token.Currency.CurrencyId == USD_CURRENCY_ID || token.Currency.CurrencyId == EUR_CURRENCY_ID)
                        {
                            var top = row.Rows.OrderByDescending(x => x.TotalSales).Take(Math.Min(row.Rows.Count, 5)).Select(x => new AuthorPayoutToken
                            {
                                Seller     = x.Seller
                                , Currency = x.Currency
                                , Sales    = x.TotalSales
                            }).ToList();
                            if (top.Count < 5)
                            {
                                var toAdd = 5 - top.Count;

                                for (var i = 0; i < toAdd; i++)
                                {
                                    top.Add(new AuthorPayoutToken {
                                        Currency = token.Currency
                                    });
                                }
                            }

                            switch (token.Currency.CurrencyId)
                            {
                            case USD_CURRENCY_ID:
                                sellerTop.Top_USD = top;
                                break;

                            case EUR_CURRENCY_ID:
                                sellerTop.Top_EUR = top;
                                break;
                            }
                        }

                        var ptr = row.PayoutCurrencySummaryDto2AdminPayoutToken();

                        var revenueChange = pt.TotalRevenue - ptr.TotalRevenue;

                        if (revenueChange == 0)
                        {
                            tendency.Direction = ReportEnums.eTendencyDirections.Equal;
                            tendency.Percent   = 0;
                        }
                        else
                        {
                            tendency.Direction = revenueChange > 0 ? ReportEnums.eTendencyDirections.Up : ReportEnums.eTendencyDirections.Down;

                            tendency.Percent = (ptr.TotalRevenue > 0 ? Math.Abs(100 - Math.Round((pt.TotalRevenue * 100 / ptr.TotalRevenue), 0)) : 0) * (revenueChange > 0 ? 1 : -1);
                        }
                    }

                    pt.Tendency = tendency;

                    p.Add(pt);
                }

                AdjustTopSellers(sellerTop);

                return(new AdminDashboardToken
                {
                    NextPayoutList = p
                    , TopSellers = sellerTop
                    , VideoStats = GetVideoStats()
                    , AuthorTotalStats = GetAuthorTotalStats()
                });
            }
            catch (Exception ex)
            {
                Logger.Error("Get Admin Dashboard token", ex, CommonEnums.LoggerObjectTypes.Reports);

                return(new AdminDashboardToken {
                    IsValid = false, Message = FormatError(ex)
                });
            }
        }