Esempio n. 1
0
        public void ShouldAddMunicipalityTax()
        {
            // Arrange
            bool isMunicipalityTaxAdded;
            var  municipalityTaxDto = new MunicipalityTaxDto()
            {
                EndDate   = DateTime.Now.AddDays(2),
                StartDate = DateTime.Now,
                Value     = 0.5M
            };
            var municipalityId = _municipalitiesRepository.Query().First().Id;

            // Act
            try
            {
                _municipalityTaxesService.AddOrUpdateTax(municipalityId, municipalityTaxDto);
                isMunicipalityTaxAdded = true;
            }
            catch (Exception)
            {
                isMunicipalityTaxAdded = false;
            }

            // Assert
            Assert.IsTrue(isMunicipalityTaxAdded);
        }
        public void AddOrUpdateTax(int municipalityId, MunicipalityTaxDto municipalityTaxDto)
        {
            var municipality = _municipalitiesRepository.Query(o => o.Id == municipalityId, includeProperties: "MunicipalityTaxes").FirstOrDefault();

            if (municipality == null)
            {
                throw new Exception(Errors.MunicipalityByIdNotFound);
            }

            if (municipalityTaxDto.Id > 0)
            {
                var municipalityTax = municipality.GetMunicipalityTax(municipalityTaxDto.Id);
                municipalityTax.StartDate = municipalityTaxDto.StartDate;
                municipalityTax.EndDate   = municipalityTaxDto.EndDate;
                municipalityTax.Value     = municipalityTaxDto.Value;
                _municipalityTaxesRepository.Update(municipalityTax);
            }
            else
            {
                municipality.AddMunicipalityTax(new MunicipalityTax(municipality.Id, municipalityTaxDto.StartDate, municipalityTaxDto.EndDate, municipalityTaxDto.Value));
                _municipalitiesRepository.Update(municipality);
            }
        }
        public IActionResult AddOrUpdateTax(int municipalityId, MunicipalityTaxDto municipalityTaxDto)
        {
            _municipalityTaxesService.AddOrUpdateTax(municipalityId, municipalityTaxDto);

            return(Ok(municipalityTaxDto));
        }