Ejemplo n.º 1
0
        public void Cancel(AppointmentCancellationDto appointmentCancellation)
        {
            var existingAppointment = _databaseContext.Appointment.SingleOrDefault(s => s.Id == appointmentCancellation.Id);

            if (existingAppointment == null)
            {
                throw new ArgumentException($"No appointment exists with id '{appointmentCancellation.Id}'");
            }

            if (existingAppointment.IsCanceled)
            {
                throw new Exception("Appointment is already cancelled.");
            }

            if (existingAppointment.DateAndTime < DateTime.Now)
            {
                throw new ArgumentOutOfRangeException("Only future appointments can be cancelled.");
            }

            existingAppointment.IsCanceled         = true;
            existingAppointment.CancellationReason = appointmentCancellation.CancellationReason;
            _databaseContext.Appointment.Update(existingAppointment);

            _databaseContext.SaveChanges();
        }
Ejemplo n.º 2
0
        public IActionResult Cancel([FromBody] AppointmentCancellationDto appointmentCancellation)
        {
            _logger.LogInformation("Cancelling appointment.");
            _logger.LogInformation("Cancellation Reason: " + appointmentCancellation.CancellationReason);

            _appointmentService.Cancel(appointmentCancellation);

            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CancelAppointmentAsync(AppointmentCancellationDto appointmentCancellationDto)
        {
            var appointment = await appointmentRepository.GetAsync(appointmentCancellationDto.Id);

            appointment.Status     = AppointmentStatus.Cancelled;
            appointment.FinishDate = DateTime.Now;

            if (!string.IsNullOrEmpty(appointmentCancellationDto.Description))
            {
                appointment.Description = appointmentCancellationDto.Description;
            }

            return(new JsonResult(await appointmentRepository.UpdateAsync(appointment))
            {
                StatusCode = 200
            });
        }
Ejemplo n.º 4
0
 public async Task <IActionResult> CancelAppointmentAsync(
     [FromBody] AppointmentCancellationDto appointmentCancellationDto)
 {
     return(await appointmentService.CancelAppointmentAsync(appointmentCancellationDto));
 }