public ActionResult AlbumReport()
        {
            var query = from a in db.Albums
                        select a;

            List <Album> allAlbums = query.ToList();
            List <AlbumReportViewModel> AlbumReports = new List <AlbumReportViewModel>();

            foreach (Album a in allAlbums)
            {
                AlbumReportViewModel aivm = new AlbumReportViewModel();
                var query2 = from pi in db.PurchaseItems
                             where pi.Purchase.isPurchased == true && pi.PurchaseItemAlbum.AlbumID == a.AlbumID
                             select pi;
                List <PurchaseItem> AlbumPurchaseItem = query2.ToList();
                Int32   purchaseCount = 0;
                Decimal totalRevenue  = 0;
                foreach (PurchaseItem pi in AlbumPurchaseItem)
                {
                    purchaseCount += 1;
                    totalRevenue  += pi.PurchaseItemPrice;
                }
                aivm.purchaseCount = purchaseCount;
                aivm.AlbumRevenue  = totalRevenue;
                aivm.Album         = a;
                AlbumReports.Add(aivm);
            }
            AlbumReports = AlbumReports.OrderByDescending(x => x.AlbumRevenue).ToList();
            return(View(AlbumReports));
        }
        public ActionResult AlbumReport()
        {
            List <AlbumReportViewModel> AlbumReportViewModels = new List <AlbumReportViewModel>();
            List <Album> albumlist = db.Albums.ToList();

            foreach (Album album in db.Albums)
            {
                Int32 SaleCount;
                SaleCount = 0;

                Decimal TotalRevenue;
                TotalRevenue = 0.00m;
                List <OrderDetail> OrderDetails = db.OrderDetails.Where(x => x.Product.ContentID == album.ContentID).ToList();
                foreach (OrderDetail orderdetail in OrderDetails)
                {
                    SaleCount    += 1;
                    TotalRevenue += orderdetail.ExtendedPrice;
                }

                AlbumReportViewModel albumreport = new AlbumReportViewModel();
                albumreport.AlbumName  = album.AlbumName;
                albumreport.Revenue    = TotalRevenue;
                albumreport.SalesCount = SaleCount;

                AlbumReportViewModels.Add(albumreport);
            }
            ViewBag.AlbumReports = AlbumReportViewModels;

            return(View());
        }