public OrderShippingConfirmation SendRequestForDelivery(Order order) { var randomDelay = new Random().Next(10); var trackId = new Random().Next(10000000); return new OrderShippingConfirmation() { ExpectedShipDate = DateTime.Today.AddDays(randomDelay), TrackingId = trackId.ToString() }; }
public static Order CreateFromShoppingCart(int temporaryId, ShoppingCart cart) { var order = new Order(temporaryId, cart.Buyer); foreach (var cartItem in cart.Items) { var orderItem = OrderItem.CreateNewForOrder(order, cartItem.Quantity, cartItem.Product); order.Items.Add(orderItem); order.Total = cart.GetTotal(); } return order; }
public int AddAndReturnKey(Order aggregate) { using (var db = new CommandModelDatabase()) { db.Entry(aggregate.Buyer).State = EntityState.Unchanged; db.Orders.Add(aggregate); if (db.SaveChanges() > 0) { return aggregate.OrderId; } return 0; } }
public static OrderFoundViewModel CreateFromOrder(Order order) { if (order == null) return new OrderFoundViewModel(); var model = new OrderFoundViewModel() { Id = order.OrderId, State = order.State, OrderDate = order.Date, Total = order.Total.ToString() }; foreach (var item in order.Items) { model.Details.Add(item); } return model; }
// The class has no public constructor because instances of it will only be // created materializing from storage. An O/RM will do it and it can use // the protected ctor. public static Order CreateNew(int id, Customer customer) { var order = new Order(id, customer); return order; }
public static OrderItem CreateNewForOrder(Order order, int quantity, Product product) { var item = new OrderItem { Quantity = quantity, Product = product, Order = order }; return item; }
public bool Delete(Order aggregate) { throw new NotImplementedException(); }