Пример #1
0
        private async void DashboardForm_Load(object sender, EventArgs e)
        {
            var notifications = await _notificationsApi.Get <List <Model.Notification> >(null);

            notifications = notifications.OrderByDescending(n => n.Created).ToList();
            dgvNotifications.AutoGenerateColumns = false;
            dgvNotifications.DataSource          = notifications;
            var orders = await _ordersApi.Get <List <Model.Order> >(null);

            decimal orderRavenue = 0;

            foreach (var order in orders)
            {
                orderRavenue += order.Total;
            }
            Orders.Text = orderRavenue.ToString();

            decimal moviesRavenue   = 0;
            var     analyticsMovies = await _analyticsApi.Analytics <List <Model.UsersMovies> >("Movies");

            foreach (var item in analyticsMovies)
            {
                moviesRavenue += item.PurchaseAmount;
            }
            MoviesRavenue.Text = moviesRavenue.ToString();

            decimal showsRavenue   = 0;
            var     analyticsShows = await _analyticsApi.Analytics <List <Model.UsersShows> >("Shows");

            foreach (var item in analyticsShows)
            {
                showsRavenue += item.PurchaseAmount;
            }
            ShowsRavenue.Text = showsRavenue.ToString();

            decimal subscriptionRavenue    = 0;
            var     analyticsSubscriptions = await _analyticsApi.Analytics <List <Model.UsersSubscriptions> >("Subscriptions");

            foreach (var item in analyticsSubscriptions)
            {
                var sub = await _subscriptionsApi.GetById <Model.Subscription>(item.SubscriptionId);

                subscriptionRavenue += sub.Price;
            }
            SubRavenue.Text = subscriptionRavenue.ToString();

            var allMovies = await _moviesApi.Get <List <Model.Movie> >(null);

            List <Model.dgvLists.ScoreItem <Model.Movie> > movies = new List <Model.dgvLists.ScoreItem <Model.Movie> >();

            foreach (var movie in allMovies)
            {
                Model.dgvLists.ScoreItem <Model.Movie> newItem = new Model.dgvLists.ScoreItem <Model.Movie>()
                {
                    Title = movie.Title
                };
                foreach (var anMovie in analyticsMovies)
                {
                    if (anMovie.MovieId == movie.MovieId)
                    {
                        newItem.Ravenue += anMovie.PurchaseAmount;
                    }
                }
                movies.Add(newItem);
            }
            movies = movies.OrderByDescending(i => i.Ravenue).ToList();
            dgvTopMovies.AutoGenerateColumns = false;
            dgvTopMovies.DataSource          = movies;

            var allShows = await _showsApi.Get <List <Model.Show> >(null);

            List <Model.dgvLists.ScoreItem <Model.Show> > shows = new List <Model.dgvLists.ScoreItem <Model.Show> >();

            foreach (var show in allShows)
            {
                Model.dgvLists.ScoreItem <Model.Show> newItem = new Model.dgvLists.ScoreItem <Model.Show>()
                {
                    Title = show.Title
                };
                foreach (var anShow in analyticsShows)
                {
                    if (anShow.ShowId == show.ShowId)
                    {
                        newItem.Ravenue += anShow.PurchaseAmount;
                    }
                }
                shows.Add(newItem);
            }
            shows = shows.OrderByDescending(i => i.Ravenue).ToList();
            dgvTopShows.AutoGenerateColumns = false;
            dgvTopShows.DataSource          = shows;
        }