Example #1
0
        public void Execute()
        {
            using (var db = new Entities()) {
                // Welche Bestellungen müssen den geändert werden?
                var ordersToUpdate = db.Orders
                                     .Include(o => o.OrderLines)
                                     .Include("OrderLines.Product")
                                     .Include("OrderLines.Product.ShippingCategory")
                                     .Where(o => o.SubTotalPrice == 0 || o.ShippingCosts == 0)
                                     .ToList();

                var shopService = new ShopService();

                // Für die gewählten Bestellungen die Preise berechnen...
                foreach (var order in ordersToUpdate)
                {
                    order.SubTotalPrice = shopService.CalculateSubTotalPrice(order);
                    order.ShippingCosts = shopService.CalculateShippingCosts(order);
                }

                // ...und speichern.
                db.SaveChanges();
            }
        }