コード例 #1
0
        public async Task <MunicipalityTaxScheduleDto> UpdateExistingMunicipalityTax(int id, MunicipalityTaxScheduleDto municipalityTaxScheduleDto)
        {
            bool isValid = MunicipalityTaxScheduleValidator.IsValid(municipalityTaxScheduleDto);

            if (!isValid)
            {
                throw new ValidationException();
            }

            MunicipalityTaxSchedules taxSchedule = await _municipalityTaxScheduleRepository.GetById(id);

            if (taxSchedule == null)
            {
                throw new NotFoundException("MunicipalityTaxSchedules", id);
            }

            taxSchedule.ModifiedOn       = DateTime.Now;
            taxSchedule.MunicipalityName = municipalityTaxScheduleDto.MunicipalityName;
            taxSchedule.FromDate         = municipalityTaxScheduleDto.FromDate;
            taxSchedule.Todate           = municipalityTaxScheduleDto.Todate;
            taxSchedule.TaxAmount        = municipalityTaxScheduleDto.TaxAmount;

            await _municipalityTaxScheduleRepository.UpdateTaxSchedule(taxSchedule);

            return(MunicipalityTaxScheduleMapper.ToDto(taxSchedule));
        }
コード例 #2
0
        public void IsValid_WhenFromDateIsGreaterThanToDate_ShouldReturnFalse()
        {
            municipalityTaxScheduleDto.FromDate = DateTime.Now;
            municipalityTaxScheduleDto.Todate   = DateTime.Now.AddDays(-1);
            bool result = MunicipalityTaxScheduleValidator.IsValid(municipalityTaxScheduleDto);

            Assert.IsFalse(result);
        }
コード例 #3
0
        public void IsValid_WhenForAnyTypeWithNegativeTaxAmount_ShouldReturnFalse()
        {
            municipalityTaxScheduleDto.TaxAmount = -0.0M;

            bool result = MunicipalityTaxScheduleValidator.IsValid(municipalityTaxScheduleDto);

            Assert.IsFalse(result);
        }
コード例 #4
0
        public void IsValid_WhenForAnyTypeWithPositiveTaxAmount_ShouldReturnTrue()
        {
            municipalityTaxScheduleDto.TaxAmount = 0.2M;

            bool result = MunicipalityTaxScheduleValidator.IsValid(municipalityTaxScheduleDto);

            Assert.IsTrue(result);
        }
コード例 #5
0
        public void IsValid_WhenTaxTypeIsMonthlyAndToDateIsNotSet_ShouldReturnFalse()
        {
            municipalityTaxScheduleDto.TaxSheduleTypeId = (int)eTaxScheduleTypes.Monthly;
            municipalityTaxScheduleDto.Todate           = null;

            bool result = MunicipalityTaxScheduleValidator.IsValid(municipalityTaxScheduleDto);

            Assert.IsFalse(result);
        }
コード例 #6
0
        public void IsValid_WhenTaxTypeIsDailyAndToDateIsSet_ShouldReturnFalse()
        {
            municipalityTaxScheduleDto.TaxSheduleTypeId = (int)eTaxScheduleTypes.Daily;
            municipalityTaxScheduleDto.Todate           = DateTime.Now.AddDays(1);

            bool result = MunicipalityTaxScheduleValidator.IsValid(municipalityTaxScheduleDto);

            Assert.IsFalse(result);
        }
コード例 #7
0
        public async Task <MunicipalityTaxScheduleDto> AddNewMunicipalityTax(MunicipalityTaxScheduleDto municipalityTaxScheduleDto)
        {
            bool isValid = MunicipalityTaxScheduleValidator.IsValid(municipalityTaxScheduleDto);

            if (!isValid)
            {
                throw new ValidationException();
            }

            MunicipalityTaxSchedules taxSchedule = MunicipalityTaxScheduleMapper.ToEntity(municipalityTaxScheduleDto);

            taxSchedule.CreatedOn = DateTime.Now;

            await _municipalityTaxScheduleRepository.AddTaxSchedule(taxSchedule);

            return(MunicipalityTaxScheduleMapper.ToDto(taxSchedule));
        }
コード例 #8
0
        public async Task <int> BulkAddMunicipalityTax(IEnumerable <MunicipalityTaxScheduleDto> municipalityTaxScheduleDtos)
        {
            bool isValid = municipalityTaxScheduleDtos.All(_ => MunicipalityTaxScheduleValidator.IsValid(_));

            if (!isValid)
            {
                throw new ValidationException();
            }

            IEnumerable <MunicipalityTaxSchedules> taxSchedules = municipalityTaxScheduleDtos.Select(_ =>
            {
                var entity       = MunicipalityTaxScheduleMapper.ToEntity(_);
                entity.CreatedOn = DateTime.Now;
                return(entity);
            });

            return(await _municipalityTaxScheduleRepository.BulkInsertTaxSchedule(taxSchedules));
        }
コード例 #9
0
        public void IsValid_WhenInputIsValid_ShouldReturnTrue()
        {
            bool result = MunicipalityTaxScheduleValidator.IsValid(municipalityTaxScheduleDto);

            Assert.IsTrue(result);
        }