Exemple #1
0
        public static string CreateOrder(OrderModel orderModel)
        {
            var order = new Order();
            order.Id = Guid.NewGuid();
            order.Total = orderModel.Total;

            foreach (var orderItemModel in orderModel.OrderItems)
            {
                order.OrderItems.Add(OrderItem.CreateOrderItem(
                    Guid.NewGuid(), orderItemModel.Item.Id, orderItemModel.Quantity, order.Id
                ));
            }

            using (Entities ctx = new Entities())
            {
                var orderType =
                    Convert.ToInt16(ConfigurationManager.AppSettings["ENTITY_ORDER_TYPE"]);
                var orderCounter =
                    ctx.EntityNumberCounters.SingleOrDefault(
                    p => p.EntityType == orderType);

                order.RefNumber = (orderCounter.Counter + 1).ToString();
                ctx.Orders.AddObject(order);

                orderCounter.Counter++;
                ctx.SaveChanges();
            }

            return order.RefNumber;
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Orders EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOrders(Order order)
 {
     base.AddObject("Orders", order);
 }
 /// <summary>
 /// Create a new Order object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="total">Initial value of the Total property.</param>
 /// <param name="refNumber">Initial value of the RefNumber property.</param>
 public static Order CreateOrder(global::System.Guid id, global::System.Decimal total, global::System.String refNumber)
 {
     Order order = new Order();
     order.Id = id;
     order.Total = total;
     order.RefNumber = refNumber;
     return order;
 }