Ejemplo n.º 1
0
        public async Task <IActionResult> CancelAppointment(Guid id)
        {
            try
            {
                var appointmentEntity = await _repository.Appointment.GetAppointmentByIdAsync(id);

                if (appointmentEntity == null)
                {
                    return(NotFound());
                }

                if (!_businessLogic.CanCancel(appointmentEntity.Date))
                {
                    return(BadRequest($"Appointments must be canceled at least 24 hours in advance; appointment date: {appointmentEntity.Date}"));
                }

                appointmentEntity.Active = false;

                _repository.Appointment.UpdateAppointment(appointmentEntity);
                await _repository.SaveAsync();

                return(NoContent());
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"));
            }
        }