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));
        }
        public async Task <MunicipalityTaxScheduleDto> GetMunicipalityTaxById(int id)
        {
            var taxSchedule = await _municipalityTaxScheduleRepository.GetById(id);

            if (taxSchedule == null)
            {
                return(null);
            }
            return(MunicipalityTaxScheduleMapper.ToDto(taxSchedule));
        }
        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));
        }
        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));
        }
        public async Task <MunicipalityTaxScheduleDto> SearchMunicipalityTax(string municipalityName, DateTime date)
        {
            MunicipalityTaxSchedules taxSchedule = await _municipalityTaxScheduleRepository.GetByDay(municipalityName, date);

            if (taxSchedule == null)
            {
                taxSchedule = await _municipalityTaxScheduleRepository.GetByWeek(municipalityName, date);
            }
            if (taxSchedule == null)
            {
                taxSchedule = await _municipalityTaxScheduleRepository.GetByMonth(municipalityName, date);
            }
            if (taxSchedule == null)
            {
                taxSchedule = await _municipalityTaxScheduleRepository.GetByYear(municipalityName, date);
            }
            if (taxSchedule == null)
            {
                return(null);
            }

            return(MunicipalityTaxScheduleMapper.ToDto(taxSchedule));
        }
 public async Task <IEnumerable <MunicipalityTaxScheduleDto> > GetAllMunicipalityTax()
 {
     return((await _municipalityTaxScheduleRepository.GetAll()).Select(_ => MunicipalityTaxScheduleMapper.ToDto(_)));
 }