public string CadastrarPlantao(Plantao plantao) { try { _plantaoRepository.CadastrarPlantao(plantao); return("Plantão cadastrado com sucesse!"); } catch (Exception ex) { throw new Exception(ex.Message); } }
//Converte Plantão em PlantãoDTO public async Task <PlantaoDTO> ToPlantaoDTO(Plantao plantao) { var farmacia = await _farmaciaRepository.GetAllAsync(); PlantaoDTO plantaoDTO = new PlantaoDTO(); try { Farmacia farmaciaPrincipal = await _farmaciaRepository.GetByIdAsync(plantao.FarmaciaPrincipal); Farmacia farmaciaSecundaria = await _farmaciaRepository.GetByIdAsync(plantao.FarmaciaSecundaria); FarmaciaDTO farmaciaDTOPrincipal = new FarmaciaDTO() { Nome = farmaciaPrincipal.Nome, Endereco = farmaciaPrincipal.Endereco, Telefone = farmaciaPrincipal.Telefone }; FarmaciaDTO farmaciaDTOSecundaria = new FarmaciaDTO() { Nome = farmaciaSecundaria.Nome, Endereco = farmaciaSecundaria.Endereco, Telefone = farmaciaSecundaria.Telefone }; plantaoDTO.Grupo = plantao.Nome; plantaoDTO.Principal = farmaciaDTOPrincipal; plantaoDTO.Secundaria = farmaciaDTOSecundaria; } catch (DbConcurrencyException e) { throw new DbConcurrencyException(e.Message); } return(plantaoDTO); }