public SellerSalesTotal SalesTotal() { SellerSalesTotal result = null; using (var db = eCommerce.Accessors.EntityFramework.eCommerceDbContext.Create()) { result = (from o in db.Orders join s in db.Sellers on o.SellerId equals s.Id where o.SellerId == Context.SellerId group o by new { o.SellerId, s.Name } into g select new SellerSalesTotal { SellerId = g.Key.SellerId, SellerName = g.Key.Name, OrderCount = g.Count(), OrderTotal = g.Sum(x => x.Total) }).FirstOrDefault(); } return(result); }
public void OrderAccessor_SellerSalesTotal() { var order = new Order() { BillingAddress = BillingAddress, ShippingAddress = ShippingAddress, OrderLines = new OrderLine[] { new OrderLine() { ProductId = 1, UnitPrice = 10.0M, ExtendedPrice = 10.0M, Quantity = 1, } }, Total = 10.0M }; var accessor = CreateOrderAccessor(); var before = accessor.SalesTotal(); if (before == null) { before = new SellerSalesTotal(); } var saved = accessor.SaveOrder(2, order); Assert.IsNotNull(saved); var after = accessor.SalesTotal(); Assert.IsNotNull(after); Assert.AreEqual(before.OrderCount + 1, after.OrderCount); Assert.AreEqual(before.OrderTotal + 10.0M, after.OrderTotal); }