public Task <CreatePortfolioCommandResult> Handle(CreatePortfolioCommand command, CancellationToken cancellationToken) { var commandResult = command.Result(); if (!command.Validate()) { commandResult.AddNotifications(command.Notifications); return(Incomplete(commandResult)); } if (_portfolioRepository.CheckNameExists(command.Name)) { commandResult.AddNotification(nameof(Portfolio), $"Já existe Portfolio com esse nome ({command.Name})"); return(Incomplete(commandResult)); } var portfolio = new Portfolio(command.Name, _tenantProvider.GetTenantId()); commandResult.AddNotifications(portfolio.Notifications); if (commandResult.Invalid) { return(Incomplete(commandResult)); } _portfolioRepository.Add(portfolio); commandResult.Id = portfolio.Id; return(Complete(commandResult, _portfolioRepository.GetPortfolio(portfolio.Id))); }
public static void ProcessCreation(this ChangeTracker changeTracker, TenantProvider tenantProvider) { changeTracker .Entries <ITenant>() .Where(e => e.State == EntityState.Added) .ToList() .ForEach(e => e.Entity.SetTenantId(tenantProvider.GetTenantId())); }