public async Task <Investiment> Handle(InvestimentCommand command) { var investiment = new Investiment(command.Description, Guid.Parse(_httpContextAccessor.HttpContext.User.Identity.Name)); command.InvestimentItems.ToList().ForEach(x => investiment.AddItem(new InvestimentItem(x.Ticker, x.Quotation, x.Amount))); #region Business var superiores = investiment.InvestimentItems.Where(x => x.Total > 50000).ToList(); if (superiores.Count > 0) { throw new BusinessRuleValidationException(string.Join(Environment.NewLine, superiores.Select(x => $"{x.Ticker} é superior a $50.000,00."))); } if (investiment.Total > 50000) { throw new BusinessRuleValidationException("Investimento total não pode ser superior a $50.000,00"); } #endregion return(await _investimentRepository.Create(investiment)); }
public async Task <IActionResult> Create(InvestimentCommand command) { return(DataResult(await _createInvestimentHandler.Handle(command))); }