public async Task <IActionResult> updateAppointment([FromBody] AppointmentForUpdateDto appointmentForUpdate) { try { var appointmentFromRepo = await _repo.getAppointmentById(appointmentForUpdate.Id); _mapper.Map(appointmentForUpdate, appointmentFromRepo); if (await _repo.SaveAll()) { return(StatusCode(200)); } } catch (Exception e) { return(BadRequest(e.Message)); } return(StatusCode(400)); }
public async Task <IActionResult> UpdateAppointment(int id, int userId, AppointmentForUpdateDto apptForUpdateDto) { var appointmentFromRepo = await _repo.GetAppointment(id); if (!userId.Equals(appointmentFromRepo.PatientId) && !userId.Equals(appointmentFromRepo.DoctorId)) { return(Unauthorized()); } // if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) // return Unauthorized(); // var userFromRepo = await _repo.getUser(id); _mapper.Map(apptForUpdateDto, appointmentFromRepo); if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception($"Update appointment {id} failed on save"); }
public async Task <IActionResult> UpdateAppointment(int patientId, int id, [FromBody] AppointmentForUpdateDto appointmentForUpdate) { if (appointmentForUpdate == null) { ModelState.AddModelError("Message", "Unable to locate payload for new request"); return(BadRequest(ModelState)); } var command = new ChangeAppointmentDetailsCommand(patientId, id, appointmentForUpdate.AppointmentDate, appointmentForUpdate.Reason, appointmentForUpdate.Cancelled == Models.ValueTypes.YesNoValueType.Yes, appointmentForUpdate.CancellationReason); _logger.LogInformation( $"----- Sending command: ChangeAppointmentDetailsCommand - {id}"); var commandResult = await _mediator.Send(command); if (!commandResult) { return(BadRequest("Command not created")); } return(Ok()); }