Example #1
0
        public void AddMunicipalities(List <MunicipalityDto> municipalitiesDto)
        {
            foreach (var municipalityDto in municipalitiesDto)
            {
                try
                {
                    var municipality = _municipalitiesRepository.Query(o => o.Name == municipalityDto.Name).FirstOrDefault();
                    if (municipality != null)
                    {
                        foreach (var municipalityTaxDto in municipalityDto.Taxes)
                        {
                            municipality.AddMunicipalityTax(new MunicipalityTax(municipality.Id, municipalityTaxDto.StartDate, municipalityTaxDto.EndDate, municipalityTaxDto.Value));
                        }
                        _municipalitiesRepository.Update(municipality);
                    }
                    else
                    {
                        var newMunicipality = new Municipality(municipalityDto.Name);
                        foreach (var municipalityTaxDto in municipalityDto.Taxes)
                        {
                            newMunicipality.AddMunicipalityTax(new MunicipalityTax(municipality.Id, municipalityTaxDto.StartDate, municipalityTaxDto.EndDate, municipalityTaxDto.Value));
                        }

                        _municipalitiesRepository.Insert(newMunicipality);
                    }
                }
                catch (Exception)
                {
                    // TOOD: Record results which caused exceptions
                }
            }
        }