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(); }
public IActionResult Cancel([FromBody] AppointmentCancellationDto appointmentCancellation) { _logger.LogInformation("Cancelling appointment."); _logger.LogInformation("Cancellation Reason: " + appointmentCancellation.CancellationReason); _appointmentService.Cancel(appointmentCancellation); return(Ok()); }
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 }); }
public async Task <IActionResult> CancelAppointmentAsync( [FromBody] AppointmentCancellationDto appointmentCancellationDto) { return(await appointmentService.CancelAppointmentAsync(appointmentCancellationDto)); }