/// <summary> /// Saves a collection of <see cref="IDetachedContentType"/>. /// </summary> /// <param name="detachedContentTypes"> /// The collection to be saved. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events. /// </param> public void Save(IEnumerable <IDetachedContentType> detachedContentTypes, bool raiseEvents = true) { var detachedContentArray = detachedContentTypes as IDetachedContentType[] ?? detachedContentTypes.ToArray(); if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <IDetachedContentType>(detachedContentArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateDetachedContentTypeRepository(uow)) { foreach (var detachedContent in detachedContentArray) { repository.AddOrUpdate(detachedContent); } uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IDetachedContentType>(detachedContentArray), this); } }
/// <summary> /// Saves the <see cref="IAnonymousCustomer"/> /// </summary> /// <param name="anonymous"> /// The anonymous customer /// </param> /// <param name="raiseEvents"> /// TOptional boolean indicating whether or not to raise events /// </param> public void Save(IAnonymousCustomer anonymous, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IAnonymousCustomer>(anonymous), this)) { return; } } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateAnonymousCustomerRepository(uow)) { repository.AddOrUpdate(anonymous); uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IAnonymousCustomer>(anonymous), this); } }
/// <summary> /// Saves a collection of <see cref="IProductVariant"/> /// </summary> /// <param name="productVariantList">The collection of <see cref="IProductVariant"/> to be saved</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IEnumerable <IProductVariant> productVariantList, bool raiseEvents = true) { var productVariants = productVariantList as IProductVariant[] ?? productVariantList.ToArray(); if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <IProductVariant>(productVariants), this); } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateProductVariantRepository(uow)) { foreach (var variant in productVariants) { repository.AddOrUpdate(variant); } uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IProductVariant>(productVariants), this); } }
/// <summary> /// Saves a collection of <see cref="IPayment"/> /// </summary> /// <param name="payments">A collection of <see cref="IPayment"/> to be saved</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IEnumerable <IPayment> payments, bool raiseEvents = true) { var paymentsArray = payments as IPayment[] ?? payments.ToArray(); if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <IPayment>(paymentsArray), this); } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreatePaymentRepository(uow)) { foreach (var paymentMethod in paymentsArray) { repository.AddOrUpdate(paymentMethod); } uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IPayment>(paymentsArray), this); } }
/// <summary> /// Saves a collection of entity collections. /// </summary> /// <param name="entityCollections"> /// The entity collections. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> public void Save(IEnumerable <IEntityCollection> entityCollections, bool raiseEvents = true) { var collectionsArray = entityCollections as IEntityCollection[] ?? entityCollections.ToArray(); if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <IEntityCollection>(collectionsArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateEntityCollectionRepository(uow)) { foreach (var collection in collectionsArray) { repository.AddOrUpdate(collection); } uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IEntityCollection>(collectionsArray), this); } }
/// <summary> /// Saves a collection of <see cref="ICustomer"/> objects. /// </summary> /// <param name="customers">Collection of <see cref="ICustomer"/> to save</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IEnumerable <ICustomer> customers, bool raiseEvents = true) { var customerArray = customers as ICustomer[] ?? customers.ToArray(); if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <ICustomer>(customerArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateCustomerRepository(uow)) { foreach (var customer in customerArray) { repository.AddOrUpdate(customer); } uow.Commit(); } } foreach (var customer in customerArray) { SaveAddresses(customer); } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <ICustomer>(customerArray), this); } }
/// <summary> /// Saves a collection of <see cref="IShipMethod"/> /// </summary> /// <param name="shipMethodList">Collection of <see cref="IShipMethod"/> to save</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IEnumerable <IShipMethod> shipMethodList, bool raiseEvents = true) { var shipMethodsArray = shipMethodList as IShipMethod[] ?? shipMethodList.ToArray(); if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <IShipMethod>(shipMethodsArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateShipMethodRepository(uow)) { foreach (var shipMethod in shipMethodsArray) { repository.AddOrUpdate(shipMethod); } uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IShipMethod>(shipMethodsArray), this); } }
/// <summary> /// Saves a single <see cref="shipCountry"/> /// </summary> /// <param name="shipCountry"></param> /// <param name="raiseEvents"></param> public void Save(IShipCountry shipCountry, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IShipCountry>(shipCountry), this)) { ((ShipCountry)shipCountry).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateShipCountryRepository(uow, _storeSettingService)) { repository.AddOrUpdate(shipCountry); uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IShipCountry>(shipCountry), this); } }
/// <summary> /// Saves a collection of <see cref="IAuditLog"/> /// </summary> /// <param name="auditLogs"> /// The collection of <see cref="IAuditLog"/>s to be saved /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> public void Save(IEnumerable <IAuditLog> auditLogs, bool raiseEvents = true) { var auditLogsArray = auditLogs as IAuditLog[] ?? auditLogs.ToArray(); if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <IAuditLog>(auditLogsArray), this); } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateAuditLogRepository(uow)) { foreach (var auditLog in auditLogsArray) { repository.AddOrUpdate(auditLog); } uow.Commit(); } } Saved.RaiseEvent(new SaveEventArgs <IAuditLog>(auditLogsArray), this); }
/// <summary> /// Saves a single <see cref="IWarehouseCatalog"/>. /// </summary> /// <param name="warehouseCatalog"> /// The warehouse catalog. /// </param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IWarehouseCatalog warehouseCatalog, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IWarehouseCatalog>(warehouseCatalog), this)) { ((WarehouseCatalog)warehouseCatalog).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateWarehouseCatalogRepository(uow)) { repository.AddOrUpdate(warehouseCatalog); uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IWarehouseCatalog>(warehouseCatalog), this); } }
/// <summary> /// Saves a collection of <see cref="IWarehouseCatalog"/>. /// </summary> /// <param name="warehouseCatalogs"> /// The warehouse catalogs. /// </param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IEnumerable <IWarehouseCatalog> warehouseCatalogs, bool raiseEvents = true) { var catalogsArray = warehouseCatalogs as IWarehouseCatalog[] ?? warehouseCatalogs.ToArray(); if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <IWarehouseCatalog>(catalogsArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateWarehouseCatalogRepository(uow)) { foreach (var catalog in catalogsArray) { repository.AddOrUpdate(catalog); } uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IWarehouseCatalog>(catalogsArray), this); } }
/// <summary> /// Saves a collection of <see cref="ITaxMethod"/> /// </summary> /// <param name="countryTaxRateList">A collection of <see cref="ITaxMethod"/> to be saved</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IEnumerable <ITaxMethod> countryTaxRateList, bool raiseEvents = true) { var taxMethodsArray = countryTaxRateList as ITaxMethod[] ?? countryTaxRateList.ToArray(); if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <ITaxMethod>(taxMethodsArray), this); } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateTaxMethodRepository(uow)) { foreach (var countryTaxRate in taxMethodsArray) { repository.AddOrUpdate(countryTaxRate); } uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <ITaxMethod>(taxMethodsArray), this); } }
/// <summary> /// Saves a single <see cref="ITaxMethod"/> /// </summary> /// <param name="taxMethod">The <see cref="ITaxMethod"/> to be saved</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(ITaxMethod taxMethod, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <ITaxMethod>(taxMethod), this)) { ((TaxMethod)taxMethod).WasCancelled = true; return; } } //TODO refactor this taxMethod.Name = string.IsNullOrEmpty(taxMethod.Name) ? GetTaxMethodName(taxMethod) : taxMethod.Name; using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateTaxMethodRepository(uow)) { repository.AddOrUpdate(taxMethod); uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <ITaxMethod>(taxMethod), this); } }
public void Save(IEnumerable <IMemberType> memberTypes, int userId = 0) { var asArray = memberTypes.ToArray(); if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IMemberType>(asArray), this)) { return; } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateMemberTypeRepository(uow)) { foreach (var memberType in asArray) { memberType.CreatorId = userId; repository.AddOrUpdate(memberType); } //save it all in one go uow.Commit(); } UpdateContentXmlStructure(asArray.Cast <IContentTypeBase>().ToArray()); } Saved.RaiseEvent(new SaveEventArgs <IMemberType>(asArray, false), this); }
/// <summary> /// Saves a single <see cref="IProduct"/> object /// </summary> /// <param name="product">The <see cref="IProductVariant"/> to save</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events.</param> public void Save(IProduct product, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IProduct>(product), this)) { ((Product)product).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateProductRepository(uow)) { repository.AddOrUpdate(product); uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IProduct>(product), this); } // verify that all variants of this product still have attributes - or delete them _productVariantService.EnsureProductVariantsHaveAttributes(product); // save any remaining variants changes in the variants collection if (product.ProductVariants.Any()) { _productVariantService.Save(product.ProductVariants); } }
/// <summary> /// Saves a collection of <see cref="IDigitalMedia"/>. /// </summary> /// <param name="digitalMedias"> /// The digital medias. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events. /// </param> public void Save(IEnumerable <IDigitalMedia> digitalMedias, bool raiseEvents = true) { var digitalMediaArray = digitalMedias as IDigitalMedia[] ?? digitalMedias.ToArray(); if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <IDigitalMedia>(digitalMediaArray), this); } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateDigitalMediaRepository(uow)) { foreach (var digitalMedia in digitalMediaArray) { repository.AddOrUpdate(digitalMedia); } uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IDigitalMedia>(digitalMediaArray), this); } }
/// <summary> /// Saves a collection of <see cref="INotificationMethod"/> /// </summary> /// <param name="notificationMethods">The collection of <see cref="INotificationMethod"/> to be saved</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IEnumerable <INotificationMethod> notificationMethods, bool raiseEvents = true) { var notificationMethodsArray = notificationMethods as INotificationMethod[] ?? notificationMethods.ToArray(); if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <INotificationMethod>(notificationMethodsArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateNotificationMethodRepository(uow)) { foreach (var notificationMethod in notificationMethodsArray) { repository.AddOrUpdate(notificationMethod); } uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <INotificationMethod>(notificationMethodsArray), this); } }
/// <summary> /// Saves a single <see cref="ICustomerAddress"/> /// </summary> /// <param name="address"> /// The address. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> public void Save(ICustomerAddress address, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <ICustomerAddress>(address), this)) { ((CustomerAddress)address).WasCancelled = true; return; } } var count = GetCustomerAddressCount(address.CustomerKey, address.AddressType); if (count == 0 || address.IsDefault) { ClearDefaultCustomerAddress(address.CustomerKey, address.AddressType); address.IsDefault = true; } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateCustomerAddressRepository(uow)) { repository.AddOrUpdate(address); uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <ICustomerAddress>(address), this); } }
/// <summary> /// Saves a single <see cref="IShipMethod"/> /// </summary> /// <param name="shipMethod">The <see cref="IShipMethod"/> to save</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events.</param> public void Save(IShipMethod shipMethod, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IShipMethod>(shipMethod), this)) { ((ShipMethod)shipMethod).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateShipMethodRepository(uow)) { repository.AddOrUpdate(shipMethod); uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IShipMethod>(shipMethod), this); } }
/// <summary> /// Saves a collection of <see cref="ICustomerAddress"/> /// </summary> /// <param name="addresses"> /// The addresses. /// </param> /// <param name="raiseEvents"> /// The raise events. /// </param> /// <remarks> /// TODO - come up with a validation strategy on batch saves that protects default address settings /// </remarks> public void Save(IEnumerable <ICustomerAddress> addresses, bool raiseEvents = true) { var addressArray = addresses as ICustomerAddress[] ?? addresses.ToArray(); if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <ICustomerAddress>(addressArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateCustomerAddressRepository(uow)) { foreach (var address in addressArray) { repository.AddOrUpdate(address); } uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <ICustomerAddress>(addressArray), this); } }
/// <summary> /// Saves a single <see cref="IPaymentMethod"/> /// </summary> /// <param name="payment">The <see cref="IPayment"/> to be saved</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IPayment payment, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IPayment>(payment), this)) { ((Payment)payment).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreatePaymentRepository(uow)) { repository.AddOrUpdate(payment); uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IPayment>(payment), this); } }
/// <summary> /// Saves a collection of <see cref="IMedia"/> objects /// </summary> /// <param name="medias">Collection of <see cref="IMedia"/> to save</param> /// <param name="userId">Id of the User saving the Content</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events.</param> public void Save(IEnumerable <IMedia> medias, int userId = 0, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IMedia>(medias), this)) { return; } } var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateMediaRepository(uow)) { foreach (var media in medias) { media.CreatorId = userId; repository.AddOrUpdate(media); } //commit the whole lot in one go uow.Commit(); } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IMedia>(medias, false), this); } Audit.Add(AuditTypes.Save, "Save Media items performed by user", userId, -1); }
/// <summary> /// Saves a single entity collection. /// </summary> /// <param name="entityCollection"> /// The entity collection. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> public void Save(IEntityCollection entityCollection, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IEntityCollection>(entityCollection), this)) { ((EntityCollection)entityCollection).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateEntityCollectionRepository(uow)) { repository.AddOrUpdate(entityCollection); uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IEntityCollection>(entityCollection), this); } }
/// <summary> /// Saves a collection of <see cref="IItemCache"/> objects. /// </summary> /// <param name="itemCaches">Collection of <see cref="ItemCache"/> to save</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IEnumerable <IItemCache> itemCaches, bool raiseEvents = true) { var basketArray = itemCaches as IItemCache[] ?? itemCaches.ToArray(); if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <IItemCache>(basketArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateItemCacheRepository(uow)) { foreach (var basket in basketArray) { repository.AddOrUpdate(basket); } uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IItemCache>(basketArray), this); } }
/// <summary> /// Saves a single instance of <see cref="IDetachedContentType"/>. /// </summary> /// <param name="detachedContentType"> /// The detached content type. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events. /// </param> public void Save(IDetachedContentType detachedContentType, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IDetachedContentType>(detachedContentType), this)) { ((DetachedContentType)detachedContentType).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateDetachedContentTypeRepository(uow)) { repository.AddOrUpdate(detachedContentType); uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IDetachedContentType>(detachedContentType), this); } }
/// <summary> /// Saves a single <see cref="IShipment"/> object /// </summary> /// <param name="shipment">The <see cref="IShipment"/> to save</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IShipment shipment, bool raiseEvents = true) { if (!((Shipment)shipment).HasIdentity && shipment.ShipmentNumber <= 0) { // We have to generate a new 'unique' invoice number off the configurable value ((Shipment)shipment).ShipmentNumber = _storeSettingService.GetNextShipmentNumber(); } var includesStatusChange = ((Shipment)shipment).IsPropertyDirty("ShipmentStatus") && shipment.HasIdentity; if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IShipment>(shipment), this)) { ((Shipment)shipment).WasCancelled = true; return; } if (includesStatusChange) { StatusChanging.RaiseEvent(new StatusChangeEventArgs <IShipment>(shipment), this); } } if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IShipment>(shipment), this)) { ((Shipment)shipment).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateShipmentRepository(uow)) { repository.AddOrUpdate(shipment); uow.Commit(); } } if (!raiseEvents) { return; } Saved.RaiseEvent(new SaveEventArgs <IShipment>(shipment), this); if (includesStatusChange) { StatusChanged.RaiseEvent(new StatusChangeEventArgs <IShipment>(shipment), this); } }
/// <summary> /// Sorts a collection of <see cref="IMedia"/> objects by updating the SortOrder according /// to the ordering of items in the passed in <see cref="IEnumerable{T}"/>. /// </summary> /// <param name="items"></param> /// <param name="userId"></param> /// <param name="raiseEvents"></param> /// <returns>True if sorting succeeded, otherwise False</returns> public bool Sort(IEnumerable <IMedia> items, int userId = 0, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IMedia>(items), this)) { return(false); } } var shouldBeCached = new List <IMedia>(); using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateMediaRepository(uow)) { int i = 0; foreach (var media in items) { //If the current sort order equals that of the media //we don't need to update it, so just increment the sort order //and continue. if (media.SortOrder == i) { i++; continue; } media.SortOrder = i; i++; repository.AddOrUpdate(media); shouldBeCached.Add(media); } uow.Commit(); foreach (var content in shouldBeCached) { //Create and Save ContentXml DTO var xml = content.ToXml(); CreateAndSaveMediaXml(xml, content.Id, uow.Database); } } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IMedia>(items, false), this); } Audit.Add(AuditTypes.Sort, "Sorting Media performed by user", userId, 0); return(true); }
/// <summary> /// Saves a collection of <see cref="IOrder"/> /// </summary> /// <param name="orders">The collection of <see cref="IOrder"/></param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IEnumerable <IOrder> orders, bool raiseEvents = true) { // Generate Order Number for new Orders in the collection var ordersArray = orders as IOrder[] ?? orders.ToArray(); var newOrderCount = ordersArray.Count(x => x.OrderNumber <= 0 && !((Order)x).HasIdentity); if (newOrderCount > 0) { var lastOrderNumber = _storeSettingService.GetNextOrderNumber(newOrderCount); foreach (var newOrder in ordersArray.Where(x => x.OrderNumber <= 0 && !((Order)x).HasIdentity)) { ((Order)newOrder).OrderNumber = lastOrderNumber; lastOrderNumber = lastOrderNumber - 1; } } var existingOrdersWithStatusChanges = ordersArray.Where( x => ((Order)x).HasIdentity == false && ((Order)x).IsPropertyDirty("OrderStatus")) .ToArray(); if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <IOrder>(ordersArray), this); if (existingOrdersWithStatusChanges.Any()) { StatusChanging.RaiseEvent(new StatusChangeEventArgs <IOrder>(existingOrdersWithStatusChanges), this); } } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateOrderRepository(uow)) { foreach (var order in ordersArray) { repository.AddOrUpdate(order); } uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IOrder>(ordersArray), this); if (existingOrdersWithStatusChanges.Any()) { StatusChanged.RaiseEvent(new StatusChangeEventArgs <IOrder>(existingOrdersWithStatusChanges), this); } } }
/// <summary> /// Saves a collection of <see cref="IInvoice"/> /// </summary> /// <param name="invoices">The collection of <see cref="IInvoice"/></param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IEnumerable <IInvoice> invoices, bool raiseEvents = true) { // Generate Invoice Number for new Invoices in the collection var invoicesArray = invoices as IInvoice[] ?? invoices.ToArray(); var newInvoiceCount = invoicesArray.Count(x => x.InvoiceNumber <= 0 && !((Invoice)x).HasIdentity); if (newInvoiceCount > 0) { var lastInvoiceNumber = _storeSettingService.GetNextInvoiceNumber(newInvoiceCount); foreach (var newInvoice in invoicesArray.Where(x => x.InvoiceNumber <= 0 && !((Invoice)x).HasIdentity)) { ((Invoice)newInvoice).InvoiceNumber = lastInvoiceNumber; lastInvoiceNumber = lastInvoiceNumber - 1; } } var existingInvoicesWithStatusChanges = invoicesArray.Where( x => ((Invoice)x).HasIdentity == false && ((Invoice)x).IsPropertyDirty("InvoiceStatusKey")) .ToArray(); if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <IInvoice>(invoicesArray), this); if (existingInvoicesWithStatusChanges.Any()) { StatusChanging.RaiseEvent( new StatusChangeEventArgs <IInvoice>(existingInvoicesWithStatusChanges), this); } } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateInvoiceRepository(uow)) { foreach (var invoice in invoicesArray) { repository.AddOrUpdate(invoice); } uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IInvoice>(invoicesArray), this); if (existingInvoicesWithStatusChanges.Any()) { StatusChanged.RaiseEvent(new StatusChangeEventArgs <IInvoice>(existingInvoicesWithStatusChanges), this); } } }
/// <summary> /// Saves a single <see cref="IOrder"/> /// </summary> /// <param name="order">The <see cref="IOrder"/> to save</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IOrder order, bool raiseEvents = true) { if (!((Order)order).HasIdentity && order.OrderNumber <= 0) { // We have to generate a new 'unique' order number off the configurable value ((Order)order).OrderNumber = _storeSettingService.GetNextOrderNumber(); } var includesStatusChange = ((Order)order).IsPropertyDirty("OrderStatus") && ((Order)order).HasIdentity; if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IOrder>(order), this)) { ((Order)order).WasCancelled = true; return; } if (includesStatusChange) { StatusChanging.RaiseEvent(new StatusChangeEventArgs <IOrder>(order), this); } } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateOrderRepository(uow)) { repository.AddOrUpdate(order); uow.Commit(); } } if (!raiseEvents) { return; } Saved.RaiseEvent(new SaveEventArgs <IOrder>(order), this); if (includesStatusChange) { StatusChanged.RaiseEvent(new StatusChangeEventArgs <IOrder>(order), this); } }