public async Task <IActionResult> CancelAsync(Guid id, string reason) { ActionResult result; try { var appointment = await _appointmentService.GetAppointmentAsync(id); //does it exist? if (appointment == null) { return(NotFound()); } if (string.IsNullOrWhiteSpace(reason)) { throw new ArgumentNullException(nameof(reason)); } bool canceled = await _appointmentService.CancelAsync(id, reason); if (!canceled) { throw new InvalidOperationException($"The Appointment could not be canceled (Id: {appointment.Id:D})."); } result = Ok(); } catch (Exception ex) { _logger.LogError(ex, ex.Message); throw; } return(result); }