public IActionResult UpdateAppointment([FromBody] UpdateAppointmentRequestDto request) { int recordId = 0; try { var identity = HttpContext.User.Identity as ClaimsIdentity; IEnumerable <Claim> claims = identity?.Claims; var profileClaim = claims?.FirstOrDefault(x => x.Type == ClaimTypes.Name); if (profileClaim != null && int.TryParse(profileClaim.Value, out var profileId)) { var profile = profileService.GetProfileById(profileId); request.ProfileId = profile?.Id; } recordId = appointmentService.UpdateAppointment(request); } catch (Exception e) { Console.WriteLine(e); throw; } return(Ok(recordId)); }
private void ValidateRequest(UpdateAppointmentRequestDto request) { if (request.Id == 0 || request.Id < 0) { throw new DomainModelException("Appointment Id is a required field"); } ValidateRequest(request as InsertAppointmentRequestDto); }
public async Task <IActionResult> UpdateAppointmentByIdAsync( [FromRoute] int appointmentId, [FromBody] UpdateAppointmentRequestDto updateAppointmentRequestDto, CancellationToken token = default) { try { var appointmentServiceObject = Mapper.Map <AppointmentServiceObject>(updateAppointmentRequestDto); appointmentServiceObject.Id = appointmentId; var serviceResult = await _appointmentService.UpdateAppointmentByIdAsync(appointmentServiceObject, token); return(new OkObjectResult(Mapper.Map <UpdateAppointmentResponseDto>(serviceResult))); } catch (Exception) { return(new BadRequestResult()); } }
public int UpdateAppointment(UpdateAppointmentRequestDto request) { Appointment appointment; ValidateRequest(request); ConvertDtoToDbModel(request as InsertAppointmentRequestDto, out var newAppointment); appointment = GetAppointment(request.Id); if (appointment.ProfileId != newAppointment.ProfileId) { throw new DomainModelException("Provided ProfileId is not corresponding Appointment record"); } appointment = AdjustAppointment(appointment, newAppointment); appointmentRepository.Update(appointment); unitOfWork.Save(); return(appointment.Id); }