public async Task <ActionResult <IReadOnlyList <MunicipalityDto> > > GetAllMunicipalities(
            [FromQuery] MunicipalitySpecParams parameters)
        {
            var spec = new MunicipalitiesWithTaxSchedulesSpecification(parameters);

            var municipalities = await _uow.Repository <Municipality>().ListAsync(spec);

            return(Ok(_mapper.Map <IReadOnlyList <MunicipalityDto> >(municipalities)));
        }
Beispiel #2
0
        public async Task <ActionResult <double> > GetTaxRateByDate(int municipalityId, DateTime date)
        {
            var municipalitySpec = new MunicipalitiesWithTaxSchedulesSpecification(municipalityId);

            var municipality = await _uow.Repository <Municipality>().GetEntityWithSpecification(municipalitySpec);

            if (municipality == null)
            {
                return(NotFound(new ApiResponse(404)));
            }

            return(Ok(municipality.GetTaxRateForDate(municipality.TaxSchedules, date)));
        }
Beispiel #3
0
        public async Task <ActionResult <IReadOnlyList <TaxScheduleDto> > > GetTaxSchedulesForMunicipality(int municipalityId)
        {
            var municipalitySpec = new MunicipalitiesWithTaxSchedulesSpecification(municipalityId);

            var municipality = await _uow.Repository <Municipality>().GetEntityWithSpecification(municipalitySpec);

            if (municipality == null)
            {
                return(NotFound(new ApiResponse(404)));
            }

            return(Ok(_mapper.Map <IReadOnlyList <TaxScheduleDto> >(municipality.TaxSchedules)));
        }
        public async Task <ActionResult <MunicipalityDto> > GetMunicipalityById(int id)
        {
            var spec = new MunicipalitiesWithTaxSchedulesSpecification(id);

            var municipality = await _uow.Repository <Municipality>().GetEntityWithSpecification(spec);

            if (municipality == null)
            {
                return(NotFound(new ApiResponse(404)));
            }

            return(Ok(_mapper.Map <MunicipalityDto>(municipality)));
        }
Beispiel #5
0
        public async Task <ActionResult <TaxScheduleDto> > GetTaxScheduleForMunicipality(int municipalityId, int taxScheduleId)
        {
            var spec = new MunicipalitiesWithTaxSchedulesSpecification(municipalityId);

            var municipality = await _uow.Repository <Municipality>().GetEntityWithSpecification(spec);

            if (municipality == null)
            {
                return(NotFound(new ApiResponse(404)));
            }

            var taxScheduleSpec = new TaxSchedulesForMunicipalitySpecification(taxScheduleId);

            var taxSchedule = await _uow.Repository <TaxSchedule>().GetEntityWithSpecification(taxScheduleSpec);

            if (taxSchedule == null)
            {
                return(NotFound(new ApiResponse(404)));
            }

            return(Ok(_mapper.Map <TaxScheduleDto>(taxSchedule)));
        }
Beispiel #6
0
        public async Task <ActionResult <TaxScheduleDto> > CreateTaxScheduleForMunicipality(int municipalityId, TaxScheduleForCreationDto taxScheduleForCreation)
        {
            var spec = new MunicipalitiesWithTaxSchedulesSpecification(municipalityId);

            var municipality = await _uow.Repository <Municipality>().GetEntityWithSpecification(spec);

            if (municipality == null)
            {
                return(NotFound(new ApiResponse(404)));
            }

            var taxScheduleEntity = _mapper.Map <TaxSchedule>(taxScheduleForCreation);

            taxScheduleEntity.MunicipalityId = municipalityId;

            _uow.Repository <TaxSchedule>().Add(taxScheduleEntity);
            await _uow.Complete();

            var taxScheduleToReturn = _mapper.Map <TaxScheduleDto>(taxScheduleEntity);

            return(CreatedAtRoute("GetTaxScheduleById",
                                  new { municipalityId = municipality.Id, taxScheduleId = taxScheduleToReturn.Id }, taxScheduleToReturn));
        }