public async Task <MedicationResponse> UpdateAsync(int id, Medication medication) { var existingMedication = await _medicationRepository.FindByIdAsync(id); if (existingMedication == null) { return(new MedicationResponse("Medication not found.")); } existingMedication.Name = medication.Name; try { _medicationRepository.Update(existingMedication); await _unitOfWork.CompleteAsync(); return(new MedicationResponse(existingMedication)); } catch (Exception ex) { // Do some logging stuff return(new MedicationResponse($"An error occurred when updating medication: {ex.Message}")); } }