// This operation might take a long time // Better to just deactivate the products ? Think about it as a cache public async Task Handle(CategoryDeactivated message) { var prods = _productsRepository .SearchFor(p => p.Categories.Any(cId => cId == message.Id)); foreach (var prod in prods) { _productsRepository.Delete(prod); } }
// Bubble up visible products to parent categories public async Task Handle(CategoryDeactivated message) { var cat = _categoryRepository.GetById(message.Id); cat.IsActivated = false; _categoryRepository.Update(cat); Guid?parentId = cat.ParentId; while (parentId != null) { var parentCat = _categoryRepository.GetById(parentId.Value); parentCat.TotalVisibleProducts -= cat.TotalVisibleProducts; _categoryRepository.Update(parentCat); parentId = parentCat.ParentId; } }
private void Apply(CategoryDeactivated e) { Activated = false; }