public void Can_log_Brand_Products_Assigned() { var @event = new BrandProductsAssigned(); _serviceBus.PublishMessage(@event); AssertAdminActivityLog(@event, AdminActivityLogCategory.Brand); }
public void Consume(BrandProductsAssigned @event) { var brand = _repository.Brands .Where(x => @event.BrandId == x.Id) .Include(x => x.BrandGameProviderConfigurations) .Single(); var existingAssignees = new List <Guid>(); if (brand.BrandGameProviderConfigurations != null) { existingAssignees = brand.BrandGameProviderConfigurations .Select(x => x.GameProviderId) .ToList(); } brand.BrandGameProviderConfigurations = new Collection <BrandGameProviderConfiguration>(); var products = @event.ProductsIds.Except(existingAssignees); var gameProviders = from gp in _repository.GameProviders where products.Contains(gp.Id) select gp; if (gameProviders.Any() == false) { return; } var fullGps = gameProviders .Include(x => x.GameProviderConfigurations); foreach (var gameProvider in fullGps) { if (gameProvider.GameProviderConfigurations == null || !gameProvider.GameProviderConfigurations.Any()) { throw new RegoException("Unable to assign product. One of more products do not have configurations available."); } var gameProviderConfiguration = gameProvider.GameProviderConfigurations.First(); brand.BrandGameProviderConfigurations.Add(new BrandGameProviderConfiguration { Id = Guid.NewGuid(), BrandId = brand.Id, GameProviderConfigurationId = gameProviderConfiguration.Id, GameProviderId = gameProvider.Id }); } _repository.SaveChanges(); }
public void Consume(BrandProductsAssigned message) { _eventHandlers.Handle(message); }
public void Handle(BrandProductsAssigned @event) { AddActivityLog(AdminActivityLogCategory.Brand, @event); }