예제 #1
0
 public async Task <Medication> AddAsync(Medication medication)
 {
     if (medication.Quantity > 0)
     {
         return(await _medicationRepository.AddAsync(medication));
     }
     else
     {
         throw new InvalidInputException("The amount of a medication cannot be lower than zero.");
     }
 }
예제 #2
0
        public async Task <MedicationResponse> SaveAsync(Medication medication)
        {
            try
            {
                await _medicationRepository.AddAsync(medication);

                await _unitOfWork.CompleteAsync();

                return(new MedicationResponse(medication));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new MedicationResponse($"An error occurred when saving the medication: {ex.Message}"));
            }
        }