Esempio n. 1
0
        public async Task <IActionResult> PostAsync(Transfer_Provider provider)
        {
            try
            {
                _logger.LogInformation($"Adding new provider.");
                var checkProvider = new CheckerClass(_facilityRepository, _specialtyRepository);
                checkProvider.CheckProvider(provider);
                Inner_Provider transformedProvider = new Inner_Provider
                {
                    ProviderId          = 0,
                    ProviderFirstName   = provider.ProviderFirstName,
                    ProviderLastName    = provider.ProviderLastName,
                    ProviderPhoneNumber = provider.ProviderPhoneNumber,
                    Facility            = await _facilityRepository.GetFacilityByIdAsync(provider.FacilityId),
                    Specialty           = await _specialtyRepository.GetSpecialtyByIdAsync(provider.FacilityId)
                };
                await _providerRepository.AddProviderAsync(transformedProvider);

                return(CreatedAtAction(nameof(GetByIdAsync), new { id = provider.ProviderId }, provider));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public void CheckProvider(Transfer_Provider provider)
        {
            if (!(_facilityRepo.FacilityExistAsync(provider.FacilityId).Result))
            {
                throw new HealthPairAppException("This Facility Does not Exist");
            }

            if (!(_specialtyRepo.SpecialtyExistAsync(provider.SpecialtyId).Result))
            {
                throw new HealthPairAppException("The Specialty does not exist, please choose the correct specialty");
            }
        }
Esempio n. 3
0
        public async Task <ActionResult <Transfer_Provider> > GetByIdAsync(int id)
        {
            _logger.LogInformation($"Retrieving providers with id {id}.");
            if (await _providerRepository.GetProviderByIdAsync(id) is Inner_Provider provider)
            {
                Transfer_Provider providerReal = Mapper.MapProvider(provider);
                providerReal.InsuranceIds = await _provInsurRepository.GetInsuranceCoverage(providerReal.ProviderId);

                return(Ok(providerReal));
            }
            _logger.LogInformation($"No providers found with id {id}.");
            return(NotFound());
        }
Esempio n. 4
0
        public async Task <IActionResult> PutAsync(int id, [FromBody] Transfer_Provider provider)
        {
            _logger.LogInformation($"Editing provider with id {id}.");
            var entity = await _providerRepository.GetProviderByIdAsync(id);

            if (entity is Inner_Provider)
            {
                entity.ProviderFirstName   = provider.ProviderFirstName;
                entity.ProviderLastName    = provider.ProviderLastName;
                entity.ProviderPhoneNumber = provider.ProviderPhoneNumber;

                return(NoContent());
            }
            _logger.LogInformation($"No providers found with id {id}.");
            return(NotFound());
        }