Example #1
0
        public async Task <TaxReadModel> GetTaxForDate(Guid municipalityId, DateTime date, CancellationToken cancellationToken)
        {
            var taxes = (await _taxRepository.GetByMunicipalityId(municipalityId, cancellationToken))
                        .Where(t => t.PeriodStartDate <= date && date <= t.PeriodEndDate)
                        .ToList();

            if (!taxes.Any())
            {
                throw new DomainException(DomainExceptionType.NotFound, $"No taxes exist for municipality {municipalityId} for date {date}");
            }

            return(taxes
                   .OrderBy(t => t.PeriodLength())
                   .First());
        }