/// <summary> /// Deletes a collection <see cref="IInvoice"/> /// </summary> /// <param name="invoices">The collection of <see cref="IInvoice"/> to be deleted</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Delete(IEnumerable <IInvoice> invoices, bool raiseEvents = true) { var invoicesArray = invoices as IInvoice[] ?? invoices.ToArray(); if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <IInvoice>(invoicesArray), this); } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateInvoiceRepository(uow)) { foreach (var invoice in invoicesArray) { DeleteAppliedPayments(invoice); DeleteOrders(invoice); repository.Delete(invoice); } uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IInvoice>(invoicesArray), this); } }
/// <summary> /// Deletes a <see cref="IStoreSetting"/> /// </summary> /// <param name="storeSetting"> /// The store Setting. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> public void Delete(IStoreSetting storeSetting, bool raiseEvents = true) { if (raiseEvents) { if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IStoreSetting>(storeSetting), this)) { ((StoreSetting)storeSetting).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateStoreSettingRepository(uow)) { repository.Delete(storeSetting); uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IStoreSetting>(storeSetting), this); } }
/// <summary> /// Deletes a collection of <see cref="IPayment"/> /// </summary> /// <param name="payments"> /// The payments. /// </param> /// <param name="raiseEvents"> /// The raise events. /// </param> public void Delete(IEnumerable <IPayment> payments, bool raiseEvents = true) { var paymentsArray = payments as IPayment[] ?? payments.ToArray(); if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <IPayment>(paymentsArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreatePaymentRepository(uow)) { foreach (var payment in paymentsArray) { repository.Delete(payment); } uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IPayment>(paymentsArray), this); } }
/// <summary> /// Deletes a collection of <see cref="IPaymentMethod"/> /// </summary> /// <param name="paymentMethods">The collection of <see cref="IPaymentMethod"/> to be deleted</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Delete(IEnumerable <IPaymentMethod> paymentMethods, bool raiseEvents = true) { var methods = paymentMethods as IPaymentMethod[] ?? paymentMethods.ToArray(); if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <IPaymentMethod>(methods), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreatePaymentMethodRepository(uow)) { foreach (var method in methods) { repository.Delete(method); } uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IPaymentMethod>(methods), this); } }
/// <summary> /// Deletes 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> internal void Delete(IEnumerable <ICustomerAddress> addresses, bool raiseEvents = true) { var addressArray = addresses as ICustomerAddress[] ?? addresses.ToArray(); if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <ICustomerAddress>(addressArray), this); } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateCustomerAddressRepository(uow)) { foreach (var address in addressArray) { repository.Delete(address); } uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <ICustomerAddress>(addressArray), this); } }
/// <summary> /// Deletes a single instance of <see cref="INotificationMessage"/> /// </summary> /// <param name="notificationMessage">The <see cref="INotificationMessage"/> to be deleted</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Delete(INotificationMessage notificationMessage, bool raiseEvents = true) { if (raiseEvents) { if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <INotificationMessage>(notificationMessage), this)) { ((NotificationMessage)notificationMessage).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateNotificationMessageRepository(uow)) { repository.Delete(notificationMessage); uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <INotificationMessage>(notificationMessage), this); } }
/// <summary> /// Deletes a collection of <see cref="IShipment"/> objects /// </summary> /// <param name="shipmentList">Collection of <see cref="IShipment"/> to delete</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Delete(IEnumerable <IShipment> shipmentList, bool raiseEvents = true) { var shipmentsArray = shipmentList as IShipment[] ?? shipmentList.ToArray(); if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <IShipment>(shipmentsArray), this); } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateShipmentRepository(uow)) { foreach (var shipment in shipmentsArray) { UpdateOrderLineItemShipmentKeys(shipment); repository.Delete(shipment); } } uow.Commit(); } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IShipment>(shipmentsArray), this); } }
/// <summary> /// Deletes a product option /// </summary> /// <param name="option"> /// The option to be deleted /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events. /// </param> /// <remarks> /// This performs a check to ensure the option is valid to be deleted /// </remarks> public void Delete(IProductOption option, bool raiseEvents = true) { if (!EnsureSafeOptionDelete(option)) { MultiLogHelper.Warn <ProductOptionService>("A ProductOption delete attempt was aborted. The option cannot be deleted due to it being shared with one or more products."); return; } if (raiseEvents) { if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IProductOption>(option), this)) { ((ProductOption)option).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateProductOptionRepository(uow)) { repository.Delete(option); uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IProductOption>(option), this); } }
/// <summary> /// Deletes a collection of product options /// </summary> /// <param name="options"> /// The collection of product options to be deleted /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events. /// </param> /// <remarks> /// This performs a check to ensure the option is valid to be deleted /// /// THIS is INTERNAL due to sharing policies /// /// </remarks> internal void Delete(IEnumerable <IProductOption> options, bool raiseEvents = true) { var optionsArray = options as IProductOption[] ?? options.ToArray(); if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <IProductOption>(optionsArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateProductOptionRepository(uow)) { foreach (var option in optionsArray) { repository.Delete(option); } uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IProductOption>(optionsArray), this); } }
/// <summary> /// Deletes a single <see cref="ITaxMethod"/> /// </summary> /// <param name="taxMethod">The <see cref="ITaxMethod"/> to be deleted</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Delete(ITaxMethod taxMethod, bool raiseEvents = true) { if (raiseEvents) { if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <ITaxMethod>(taxMethod), this)) { ((TaxMethod)taxMethod).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateTaxMethodRepository(uow)) { repository.Delete(taxMethod); uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <ITaxMethod>(taxMethod), this); } }
/// <summary> /// Deletes a collection <see cref="ICustomer"/> objects /// </summary> /// <param name="customers">Collection of <see cref="ICustomer"/> to delete</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Delete(IEnumerable <ICustomer> customers, bool raiseEvents = true) { var customerArray = customers as ICustomer[] ?? customers.ToArray(); if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <ICustomer>(customerArray), this); } customerArray.ForEach(DeleteInvoicesAndPayments); using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateCustomerRepository(uow)) { foreach (var customer in customerArray) { repository.Delete(customer); } uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <ICustomer>(customerArray), this); } }
public void Delete(IEnumerable <IMemberType> memberTypes, int userId = 0) { var asArray = memberTypes.ToArray(); if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IMemberType>(asArray), this)) { return; } using (new WriteLock(Locker)) { foreach (var contentType in asArray) { _memberService.DeleteMembersOfType(contentType.Id); } var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateMemberTypeRepository(uow)) { foreach (var memberType in asArray) { repository.Delete(memberType); } uow.Commit(); Deleted.RaiseEvent(new DeleteEventArgs <IMemberType>(asArray, false), this); } } }
/// <summary> /// Deletes a single of <see cref="IOfferSettings"/>. /// </summary> /// <param name="offerSettings"> /// The offer settings. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> public void Delete(IOfferSettings offerSettings, bool raiseEvents = true) { if (raiseEvents) { if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IOfferSettings>(offerSettings), this)) { return; } } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateOfferSettingsRepository(uow)) { repository.Delete(offerSettings); uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IOfferSettings>(offerSettings), this); } }
/// <summary> /// Deletes a <see cref="IShipRateTier"/> /// </summary> /// <param name="shipRateTier">The <see cref="IShipRateTier"/> to be deleted</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events.</param> public void Delete(IShipRateTier shipRateTier, bool raiseEvents = true) { if (raiseEvents) { if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IShipRateTier>(shipRateTier), this)) { ((ShipRateTier)shipRateTier).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateShipRateTierRepository(uow)) { repository.Delete(shipRateTier); uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IShipRateTier>(shipRateTier), this); } }
/// <summary> /// Deletes an <see cref="IOfferRedeemed"/> /// </summary> /// <param name="offerRedeemed"> /// The offer redeemed. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> public void Delete(IOfferRedeemed offerRedeemed, bool raiseEvents = true) { if (raiseEvents) { if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IOfferRedeemed>(offerRedeemed), this)) { ((OfferRedeemed)offerRedeemed).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateOfferRedeemedRepository(uow)) { repository.Delete(offerRedeemed); uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IOfferRedeemed>(offerRedeemed), this); } }
/// <summary> /// Deletes a collection of <see cref="IOfferSettings"/>. /// </summary> /// <param name="offersSettings"> /// The offers settings. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> public void Delete(IEnumerable <IOfferSettings> offersSettings, bool raiseEvents = true) { var settingsArray = offersSettings as IOfferSettings[] ?? offersSettings.ToArray(); if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <IOfferSettings>(settingsArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateOfferSettingsRepository(uow)) { foreach (var setting in settingsArray) { repository.Delete(setting); } uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IOfferSettings>(settingsArray), this); } }
/// <summary> /// The delete. /// </summary> /// <param name="redemptions"> /// The redemptions. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> public void Delete(IEnumerable <IOfferRedeemed> redemptions, bool raiseEvents = true) { var redemptionsArray = redemptions as IOfferRedeemed[] ?? redemptions.ToArray(); if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <IOfferRedeemed>(redemptionsArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateOfferRedeemedRepository(uow)) { foreach (var redemption in redemptionsArray) { repository.Delete(redemption); } uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IOfferRedeemed>(redemptionsArray), this); } }
/// <summary> /// Deletes a collection of <see cref="IGatewayProviderSettings"/> /// </summary> /// <param name="gatewayProviderList"></param> /// <param name="raiseEvents"></param> /// <remarks> /// Used for testing /// </remarks> internal void Delete(IEnumerable <IGatewayProviderSettings> gatewayProviderList, bool raiseEvents = true) { var gatewayProviderArray = gatewayProviderList as IGatewayProviderSettings[] ?? gatewayProviderList.ToArray(); if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <IGatewayProviderSettings>(gatewayProviderArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateGatewayProviderRepository(uow)) { foreach (var gatewayProvider in gatewayProviderArray) { repository.Delete(gatewayProvider); } uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IGatewayProviderSettings>(gatewayProviderArray), this); } }
/// <summary> /// Deletes a single <see cref="IShipment"/> object /// </summary> /// <param name="shipment"><see cref="IShipment"/> to delete</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Delete(IShipment shipment, bool raiseEvents = true) { if (raiseEvents) { if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IShipment>(shipment), this)) { ((Shipment)shipment).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateShipmentRepository(uow)) { UpdateOrderLineItemShipmentKeys(shipment); repository.Delete(shipment); uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IShipment>(shipment), this); } }
/// <summary> /// Deletes a single <see cref="IOrder"/> /// </summary> /// <param name="order">The <see cref="IOrder"/> to be deleted</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Delete(IOrder order, bool raiseEvents = true) { if (raiseEvents) { if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IOrder>(order), this)) { ((Order)order).WasCancelled = true; return; } } // Delete any shipment records associated with this order DeleteShipments(order); using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateOrderRepository(uow)) { repository.Delete(order); uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IOrder>(order), this); } }
/// <summary> /// Deletes a collection <see cref="IWarehouse"/> objects /// </summary> /// <param name="warehouseList">Collection of <see cref="IWarehouse"/> to delete</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> internal void Delete(IEnumerable <IWarehouse> warehouseList, bool raiseEvents = true) { var warehouseArray = warehouseList as IWarehouse[] ?? warehouseList.ToArray(); if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <IWarehouse>(warehouseArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateWarehouseRepository(uow)) { foreach (var warehouse in warehouseArray) { repository.Delete(warehouse); } uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IWarehouse>(warehouseArray), this); } }
/// <summary> /// Deletes a collection <see cref="IOrder"/> /// </summary> /// <param name="orders">The collection of <see cref="IOrder"/> to be deleted</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Delete(IEnumerable <IOrder> orders, bool raiseEvents = true) { var ordersArray = orders as IOrder[] ?? orders.ToArray(); if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <IOrder>(ordersArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateOrderRepository(uow)) { foreach (var order in ordersArray) { // delete the shipments DeleteShipments(order); repository.Delete(order); } uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IOrder>(ordersArray), this); } }
/// <summary> /// Deletes a single instance of a <see cref="IWarehouseCatalog"/>. /// </summary> /// <param name="warehouseCatalog"> /// The warehouse catalog. /// </param> /// <param name="raiseEvents"> /// The raise events. /// </param> public void Delete(IWarehouseCatalog warehouseCatalog, bool raiseEvents = true) { if (warehouseCatalog.Key == Core.Constants.Warehouse.DefaultWarehouseCatalogKey) { return; } if (raiseEvents) { if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IWarehouseCatalog>(warehouseCatalog), this)) { ((WarehouseCatalog)warehouseCatalog).WasCancelled = true; return; } } RemoveVariantsFromCatalogInventoryBeforeDeleting(warehouseCatalog); using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateWarehouseCatalogRepository(uow)) { repository.Delete(warehouseCatalog); uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IWarehouseCatalog>(warehouseCatalog), this); } }
/// <summary> /// Deletes 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 Delete(IEntityCollection entityCollection, bool raiseEvents = true) { if (raiseEvents) { if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IEntityCollection>(entityCollection), this)) { ((EntityCollection)entityCollection).WasCancelled = true; return; } } DeleteAllChildCollections(entityCollection); UpdateSiblingSortOrders(entityCollection); using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateEntityCollectionRepository(uow)) { repository.Delete(entityCollection); uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IEntityCollection>(entityCollection), this); } }
/// <summary> /// Deletes a collection of <see cref="IProductVariant"/> /// </summary> /// <param name="productVariantList">The collction of <see cref="IProductVariant"/> to be deleted</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Delete(IEnumerable <IProductVariant> productVariantList, bool raiseEvents = true) { var productVariants = productVariantList as IProductVariant[] ?? productVariantList.ToArray(); if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <IProductVariant>(productVariants), this); } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateProductVariantRepository(uow)) { foreach (var product in productVariants) { repository.Delete(product); } uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IProductVariant>(productVariants), this); } }
/// <summary> /// Empties the Recycle Bin by deleting all <see cref="IMedia"/> that resides in the bin /// </summary> public void EmptyRecycleBin() { //TODO: Why don't we have a base class to share between MediaService/ContentService as some of this is exacty the same? var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateMediaRepository(uow)) { var query = Query <IMedia> .Builder.Where(x => x.Trashed == true); var contents = repository.GetByQuery(query).OrderByDescending(x => x.Level); foreach (var content in contents) { if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IMedia>(content), this)) { continue; } repository.Delete(content); Deleted.RaiseEvent(new DeleteEventArgs <IMedia>(content, false), this); } uow.Commit(); } Audit.Add(AuditTypes.Delete, "Empty Recycle Bin performed by user", 0, -20); }
/// <summary> /// Deletes a single <see cref="IPayment"/> /// </summary> /// <param name="payment">The <see cref="IPayment"/> to be deleted</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Delete(IPayment payment, bool raiseEvents = true) { if (raiseEvents) { if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IPayment>(payment), this)) { ((Payment)payment).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreatePaymentRepository(uow)) { repository.Delete(payment); uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IPayment>(payment), this); } }
/// <summary> /// Permanently deletes an <see cref="IMedia"/> object as well as all of its Children. /// </summary> /// <remarks> /// Please note that this method will completely remove the Media from the database, /// as well as associated media files from the file system. /// </remarks> /// <param name="media">The <see cref="IMedia"/> to delete</param> /// <param name="userId">Id of the User deleting the Media</param> public void Delete(IMedia media, int userId = 0) { if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IMedia>(media), this)) { return; } //Delete children before deleting the 'possible parent' var children = GetChildren(media.Id); foreach (var child in children) { Delete(child, userId); } var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateMediaRepository(uow)) { repository.Delete(media); uow.Commit(); } Deleted.RaiseEvent(new DeleteEventArgs <IMedia>(media, false), this); Audit.Add(AuditTypes.Delete, "Delete Media performed by user", userId, media.Id); }
/// <summary> /// Deletes a collection <see cref="IItemCache"/> objects /// </summary> /// <param name="itemCaches">Collection of <see cref="IItemCache"/> to delete</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Delete(IEnumerable <IItemCache> itemCaches, bool raiseEvents = true) { var caches = itemCaches as IItemCache[] ?? itemCaches.ToArray(); if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <IItemCache>(caches), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateItemCacheRepository(uow)) { foreach (var basket in caches) { repository.Delete(basket); } uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IItemCache>(caches), this); } }
/// <summary> /// Deletes a single <see cref="IInvoice"/> /// </summary> /// <param name="invoice">The <see cref="IInvoice"/> to be deleted</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Delete(IInvoice invoice, bool raiseEvents = true) { if (raiseEvents) { if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IInvoice>(invoice), this)) { ((Invoice)invoice).WasCancelled = true; return; } } DeleteAppliedPayments(invoice); DeleteOrders(invoice); using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateInvoiceRepository(uow)) { repository.Delete(invoice); uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IInvoice>(invoice), this); } }