/// <summary> /// Creates a <see cref="IOrder"/> and saves it to the database /// </summary> /// <param name="orderStatusKey">The <see cref="IOrderStatus"/> key</param> /// <param name="invoiceKey"></param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> /// <returns><see cref="IOrder"/></returns> public IOrder CreateOrderWithKey(Guid orderStatusKey, Guid invoiceKey, bool raiseEvents = true) { Mandate.ParameterCondition(!Guid.Empty.Equals(orderStatusKey), "orderStatusKey"); Mandate.ParameterCondition(!Guid.Empty.Equals(invoiceKey), "invoiceKey"); var status = GetOrderStatusByKey(orderStatusKey); var order = new Order(status, invoiceKey) { VersionKey = Guid.NewGuid(), OrderDate = DateTime.Now }; if (raiseEvents) if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs<IOrder>(order), this)) { order.WasCancelled = true; return order; } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateOrderRepository(uow)) { repository.AddOrUpdate(order); uow.Commit(); } } if (raiseEvents) Created.RaiseEvent(new Events.NewEventArgs<IOrder>(order), this); return order; }
/// <summary> /// Creates a <see cref="IOrder"/> without saving it to the database /// </summary> /// <param name="orderStatusKey">The <see cref="IOrderStatus"/> key</param> /// <param name="invoiceKey"></param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> /// <returns><see cref="IOrder"/></returns> public IOrder CreateOrder(Guid orderStatusKey, Guid invoiceKey, bool raiseEvents = true) { Mandate.ParameterCondition(!Guid.Empty.Equals(orderStatusKey), "orderStatusKey"); Mandate.ParameterCondition(!Guid.Empty.Equals(invoiceKey), "invoiceKey"); var status = GetOrderStatusByKey(orderStatusKey); var order = new Order(status, invoiceKey) { VersionKey = Guid.NewGuid(), OrderDate = DateTime.Now }; if (raiseEvents) if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs<IOrder>(order), this)) { order.WasCancelled = true; return order; } if (raiseEvents) Created.RaiseEvent(new Events.NewEventArgs<IOrder>(order), this); return order; }