public static decimal SellingPointRevenue(string sellingPointName, DateTime start, DateTime end)
 {
     using (var ctx = new ShawarmaDBEntities())
     {
         decimal      result = 0;
         SellingPoint point  = ctx.SellingPoints.FirstOrDefault(p => p.ShawarmaTitle == sellingPointName);
         if (point == null)
         {
             throw new Exception("there is not specified selling point");
         }
         foreach (var seller in ctx.Sellers.Where(p => p.SellingPointId == point.SellingPointId))
         {
             foreach (
                 var order in
                 seller.OrderHeaders.Where(order => order.OrderDate >= start && order.OrderDate <= end))
             {
                 foreach (var orderDetail in order.OrderDetails)
                 {
                     PriceController price =
                         orderDetail.Shawarma.PriceControllers.LastOrDefault(
                             p => p.SellingPointId == point.SellingPointId);
                     if (price == null)
                     {
                         throw new Exception("Shawarma hasn't price");
                     }
                     result += price.Price * orderDetail.Quantity;
                 }
             }
         }
         return(result);
     }
 }
 public static bool AddPrice(string sellingPointTitle, string shawarmaName, decimal newPrice, string comment)
 {
     using (var ctx = new ShawarmaDBEntities())
     {
         SellingPoint point = ctx.SellingPoints.FirstOrDefault(p => p.ShawarmaTitle == sellingPointTitle);
         if (point == null)
         {
             AddSellingPoint(sellingPointTitle, "", "");
             point = ctx.SellingPoints.FirstOrDefault(p => p.ShawarmaTitle == sellingPointTitle);
         }
         Shawarma shawarma = ctx.Shawarmas.FirstOrDefault(sh => sh.ShawarmaName == shawarmaName);
         if (shawarma == null)
         {
             return(false);                  //there is not specified shawarma
         }
         ctx.PriceControllers.Add(new PriceController
         {
             ShwarmaId      = shawarma.ShawarmaId,
             Price          = newPrice,
             SellingPointId = point.SellingPointId,
             Comment        = comment
         });
         return(Commit(ctx));
     }
 }
 public static bool AddSeller(string sellerName, string sellingPointName)
 {
     using (var ctx = new ShawarmaDBEntities())
     {
         SellingPoint point = ctx.SellingPoints.FirstOrDefault(p => p.ShawarmaTitle == sellingPointName);
         if (point == null)
         {
             return(false);              //there is not specified selling point
         }
         ctx.Sellers.Add(new Seller
         {
             SellerName     = sellerName,
             SellingPointId = point.SellingPointId
         });
         return(Commit(ctx));
     }
 }