Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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());
            }
        }
Exemplo n.º 4
0
        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);
        }