Example #1
0
        public List <CustomerOrderSummary> GetCustomerOrderSummaries()
        {
            var dbContext = new NorthwindSystem.DataModels.Sales.NorthwindSales();
            var data      = (from purchase in dbContext.Orders
                             where purchase.OrderDate.HasValue
                             select new CustomerOrderSummary()
            {
                OrderDate = purchase.OrderDate.Value,
                Freight = purchase.Freight.GetValueOrDefault(),
                Subtotal = purchase.Order_Details
                           .Sum(x =>
                                (decimal?)(x.UnitPrice * x.Quantity)
                                ) ?? 0,                                                           // NOTE: See Footnote 1
                Discount = purchase.Order_Details
                           .Sum(x =>
                                x.UnitPrice * x.Quantity *
                                (((decimal)((int)(x.Discount * 100))) / 100)                     // NOTE: See Footnote 2
                                ),
                Total = purchase.Order_Details.Sum(x => (x.UnitPrice * x.Quantity) -
                                                   (x.UnitPrice * x.Quantity *
                                                    (((decimal)((int)(x.Discount * 100))) / 100)                  // NOTE: See Footnote 2
                                                   )
                                                   ),
                ItemCount = purchase.Order_Details.Count(),
                ItemQuantity = purchase.Order_Details.Sum(x => (short?)x.Quantity) ?? 0,
                AverageItemUnitPrice = purchase.Order_Details.Average(x => (decimal?)x.UnitPrice) ?? 0,
                CompanyName = purchase.Customer.CompanyName,
                ContactName = purchase.Customer.ContactName,
                ContactTitle = purchase.Customer.ContactTitle,
                CustomerId = purchase.CustomerID
            }).ToList();

            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);
        }
Example #3
0
        public List <NorthwindSystem.DataModels.Sales.Order> GetOrders()
        {
            var dbContext = new NorthwindSystem.DataModels.Sales.NorthwindSales();

            return(dbContext.Orders.ToList());
        }
Example #4
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 #5
0
 public List<NorthwindSystem.DataModels.Sales.Order> GetOrders()
 {
     var dbContext = new NorthwindSystem.DataModels.Sales.NorthwindSales();
     return dbContext.Orders.ToList();
 }
Example #6
0
 public List<CustomerOrderSummary> GetCustomerOrderSummaries()
 {
     var dbContext = new NorthwindSystem.DataModels.Sales.NorthwindSales();
     var data = (from purchase in dbContext.Orders
                 where purchase.OrderDate.HasValue
                 select new CustomerOrderSummary()
                 {
                     OrderDate = purchase.OrderDate.Value,
                     Freight = purchase.Freight.GetValueOrDefault(),
                     Subtotal = purchase.Order_Details
                                        .Sum(x =>
                                             (decimal?)(x.UnitPrice * x.Quantity)
                                             ) ?? 0,                                       // NOTE: See Footnote 1
                     Discount = purchase.Order_Details
                                        .Sum(x =>
                                             x.UnitPrice * x.Quantity *
                                             (((decimal)((int)(x.Discount * 100))) / 100) // NOTE: See Footnote 2
                                             ),
                     Total = purchase.Order_Details.Sum(x => (x.UnitPrice * x.Quantity) -
                                                             (x.UnitPrice * x.Quantity *
                                                              (((decimal)((int)(x.Discount * 100))) / 100) // NOTE: See Footnote 2
                                                             )
                                                        ),
                     ItemCount = purchase.Order_Details.Count(),
                     ItemQuantity = purchase.Order_Details.Sum(x => (short?)x.Quantity) ?? 0,
                     AverageItemUnitPrice = purchase.Order_Details.Average(x => (decimal?)x.UnitPrice) ?? 0,
                     CompanyName = purchase.Customer.CompanyName,
                     ContactName = purchase.Customer.ContactName,
                     ContactTitle = purchase.Customer.ContactTitle,
                     CustomerId = purchase.CustomerID
                 }).ToList();
     return data;
 }