Example #1
0
        public List <ProductSaleSummary> GetProductSaleSummaries()
        {
            // NOTE: See Footnote 1
            // NOTE: See Footnote 2
            var dbContext = new NorthwindSystem.DataModels.Sales.NorthwindSales();
            var data      =
                (from item in dbContext.Products
                 where !item.Discontinued
                 select new ProductSaleSummary()
            {
                TotalSales = item.Order_Details.Sum(x => (decimal?)(x.UnitPrice * x.Quantity)) ?? 0,       // NOTE: See Footnote 1
                TotalDiscount = item.Order_Details
                                .Sum(x => (decimal?)
                                     (x.UnitPrice * x.Quantity *
                                      (((decimal)((int)(x.Discount * 100))) / 100)                          // NOTE: See Footnote 2
                                     )) ?? 0,
                SaleCount = item.Order_Details.Count(),
                SaleQuantity = item.Order_Details.Sum(x => (short?)x.Quantity) ?? 0,
                AverageUnitPrice = item.Order_Details.Average(x => (decimal?)x.UnitPrice) ?? 0,
                ProductName = item.ProductName,
                QuantityPerUnit = item.QuantityPerUnit,
                UnitsInStock = item.UnitsInStock.HasValue ?
                               item.UnitsInStock.Value : (short)0,
                UnitsOnOrder = item.UnitsOnOrder.HasValue ?
                               item.UnitsOnOrder.Value : (short)0,
                ReorderLevel = item.ReorderLevel.HasValue ?
                               item.ReorderLevel.Value : (short)0,
                Discontinued = item.Discontinued,
                CurrentUnitPrice = item.UnitPrice.HasValue ?
                                   item.UnitPrice.Value : 0,
                CategoryId = item.CategoryID.HasValue ?
                             item.CategoryID.Value : 0,
                ProductId = item.ProductID
            }).ToList();

            var dbInventoryContext = new NorthwindSystem.DataModels.Purchasing.NorthwindPurchasing();

            foreach (var item in data)
            {
                if (item.CategoryId > 0)
                {
                    item.CategoryName = dbInventoryContext.Categories.Find(item.CategoryId).CategoryName;
                }
            }
            return(data);
        }
Example #2
0
        public List<ProductSaleSummary> GetProductSaleSummaries()
        {
            // NOTE: See Footnote 1
            // NOTE: See Footnote 2
            var dbContext = new NorthwindSystem.DataModels.Sales.NorthwindSales();
            var data =
                (from item in dbContext.Products
                 where !item.Discontinued
                 select new ProductSaleSummary()
                 {
                     TotalSales = item.Order_Details.Sum(x => (decimal?)(x.UnitPrice * x.Quantity)) ?? 0,  // NOTE: See Footnote 1
                     TotalDiscount = item.Order_Details
                                     .Sum(x => (decimal?)
                                                 (x.UnitPrice * x.Quantity *
                                                 (((decimal)((int)(x.Discount * 100))) / 100)               // NOTE: See Footnote 2
                                                 )) ?? 0,
                     SaleCount = item.Order_Details.Count(),
                     SaleQuantity = item.Order_Details.Sum(x => (short?)x.Quantity) ?? 0,
                     AverageUnitPrice = item.Order_Details.Average(x => (decimal?)x.UnitPrice) ?? 0,
                     ProductName = item.ProductName,
                     QuantityPerUnit = item.QuantityPerUnit,
                     UnitsInStock = item.UnitsInStock.HasValue ?
                                     item.UnitsInStock.Value : (short)0,
                     UnitsOnOrder = item.UnitsOnOrder.HasValue ?
                                     item.UnitsOnOrder.Value : (short)0,
                     ReorderLevel = item.ReorderLevel.HasValue ?
                                     item.ReorderLevel.Value : (short)0,
                     Discontinued = item.Discontinued,
                     CurrentUnitPrice = item.UnitPrice.HasValue ?
                                     item.UnitPrice.Value : 0,
                     CategoryId = item.CategoryID.HasValue ?
                                     item.CategoryID.Value : 0,
                     ProductId = item.ProductID
                 }).ToList();

            var dbInventoryContext = new NorthwindSystem.DataModels.Purchasing.NorthwindPurchasing();
            foreach (var item in data)
                if (item.CategoryId > 0)
                    item.CategoryName = dbInventoryContext.Categories.Find(item.CategoryId).CategoryName;
            return data;
        }