/// <summary> /// Creates a Product without saving it to the database /// </summary> public IProduct CreateProduct(string name, string sku, decimal price) { var templateVariant = new ProductVariant(name, sku, price); var product = new Product(templateVariant); if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs<IProduct>(product), this)) { product.WasCancelled = true; return product; } Created.RaiseEvent(new Events.NewEventArgs<IProduct>(product), this); return product; }
/// <summary> /// Creates and saves a <see cref="IProduct"/> to the database /// </summary> /// <param name="name"></param> /// <param name="sku"></param> /// <param name="price"></param> /// <returns></returns> public IProduct CreateProductWithKey(string name, string sku, decimal price) { var templateVariant = new ProductVariant(name, sku, price); var product = new Product(templateVariant); if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs<IProduct>(product), this)) { product.WasCancelled = true; return product; } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateProductRepository(uow)) { repository.AddOrUpdate(product); uow.Commit(); } } Created.RaiseEvent(new Events.NewEventArgs<IProduct>(product), this); return product; }