コード例 #1
0
        public void Adicionar(ForecastET forecast)
        {
            var forecastExiste = _forecastRepository
                                 .Buscar(forecast.IdCelula, forecast.IdCliente, forecast.IdServico, forecast.NrAno);
            ForecastET forecastAnoSeguinteExiste = null;

            if (forecast.DataAniversario != null)
            {
                forecastAnoSeguinteExiste = forecast.DataAniversario.Value.Year > forecast.NrAno ?
                                            _forecastRepository.Buscar(forecast.IdCelula, forecast.IdCliente, forecast.IdServico,
                                                                       forecast.DataAniversario.Value.Year) :
                                            null;
            }

            if (forecastExiste != null || forecastAnoSeguinteExiste != null)
            {
                throw new ArgumentException($"Um Forecast para esta Célula, Cliente, Serviço e Ano já existe");
            }

            _forecastRepository.Adicionar(forecast);
            if (forecast.DataAniversario.HasValue && forecast.DataAniversario.Value.Year > forecast.NrAno)
            {
                var forecastDoAnoSeguinte        = CriarEntidadeForecastDoAnoSeguinte(forecast, AtribuirValoresDosMesesParaAnoSeguinteAdicao);
                var forecastDoSegundoAnoSeguinte = CriarEntidadeForecastDoAnoSeguinte(forecastDoAnoSeguinte, AtribuirValoresDosMesesParaAnoSeguinteAdicao);
                _forecastRepository.Adicionar(forecastDoAnoSeguinte);
                _forecastRepository.Adicionar(forecastDoSegundoAnoSeguinte);
            }

            _unitOfWork.Commit();
        }