Пример #1
0
        public ActionResult Shipments()
        {
            List<Confirmation> model;
            using (var context = new OrderContext())
            {
                var shipments =
                    from s in context.Shipments
                    orderby s.ShipmentId descending
                    select new { s.Order.Item, s.Order.OrderId };

                model = shipments
                    .AsEnumerable()
                    .Select(s => new Confirmation
                    {
                        Item = s.Item,
                        ConfirmationNumber = "CN" + s.OrderId
                    })
                    .ToList();
            }
            return View(model);
        }
Пример #2
0
        private static Order SaveAsOrder(ShoppingCart shoppingCart)
        {
            Order order;
            using (var context = new OrderContext())
            {
                // TODO 8.3: Look for existing order by uniquifier.
                var matchingOrders =
                    from o in context.Orders
                    where o.Uniquifier == shoppingCart.Uniquifier
                    select o;

                order = matchingOrders.FirstOrDefault();
                if (order != null)
                    return order;

                order = new Order
                {
                    Item = shoppingCart.Item,
                    // TODO 8.4: Copy uniquifier.
                    Uniquifier = shoppingCart.Uniquifier
                };
                context.Orders.Add(order);

                context.SaveChanges();
            }
            return order;
        }