Example #1
0
        public async Task <IActionResult> CreateAsync([FromBody] AppointmentDto appointment)
        {
            ActionResult result = StatusCode((int)HttpStatusCode.InternalServerError, "The content could not be displayed because an internal server error has occured.");

            try
            {
                var newAppointment = await _appointmentService.AddAppointmentAsync(appointment);

                //by design, returns null if validation fails and doesn't throw,
                //or context fails to create without error.
                if (newAppointment == null)
                {
                    throw new InvalidOperationException($"Could not be created.");
                }

                result = StatusCode((int)HttpStatusCode.Created, newAppointment);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                throw;
            }

            return(result);
        }