public async Task <IActionResult> GetAsync([FromQuery] string search = null) { List <Transfer_Insurance> InsuranceAll; if (search == null) { _logger.LogInformation($"Retrieving all insurances"); InsuranceAll = (await _insuranceRepository.GetInsuranceAsync()).Select(Mapper.MapInsurance).ToList(); } else { _logger.LogInformation($"Retrieving insurances with parameters {search}."); InsuranceAll = (await _insuranceRepository.GetInsuranceAsync(search)).Select(Mapper.MapInsurance).ToList(); } try { foreach (var val in InsuranceAll) { val.ProviderIds = await _provInsurRepository.GetProviderCoverage(val.InsuranceId); } _logger.LogInformation($"Sending {InsuranceAll.Count} Insurance."); return(Ok(InsuranceAll)); } catch (Exception e) { _logger.LogWarning($"Error! {e.Message}."); return(StatusCode(500, e)); } }
public async Task <ViewModel.Insurance> GetInsuranceAsync(int insuranceId) { var insurance = await _insuranceRepository.GetInsuranceAsync(insuranceId); var insuranceViewModel = _mapper.Map <ViewModel.Insurance>(insurance); return(insuranceViewModel); }
public async Task Handle(InsuranceAssigned notification) { var insurance = await _insuranceRepository.GetInsuranceAsync(notification.InsuranceId); insurance.UseByCustomers(); await _insuranceRepository.UnitOfWork.SaveEntitiesAsync(); }
public async Task Handle(InsuranceCancelled notification) { var activeInsurances = await _customerRepository.GetActiveInsurancesAsync(notification.InsuranceId); if (activeInsurances?.Count == 0) { var insurance = await _insuranceRepository.GetInsuranceAsync(notification.InsuranceId); insurance.Release(); await _insuranceRepository.UnitOfWork.SaveEntitiesAsync(); } }