Beispiel #1
0
        public ActionResult PatchAppointment(uint appointmentId, string email, JsonPatchDocument <AppointmentCreateUpdateDto> patchDocument)
        {
            ICollection <Appointment> appointments = _repository.GetAppointments(email);
            Appointment existingAppointment        = null;

            foreach (Appointment appointment in appointments)
            {
                if (appointment.Id == appointmentId)
                {
                    existingAppointment = appointment;
                    break;
                }
            }

            if (existingAppointment == null)
            {
                return(NotFound());
            }

            AppointmentCreateUpdateDto appointmentToPatch = _mapper.Map <AppointmentCreateUpdateDto>(existingAppointment);

            patchDocument.ApplyTo(appointmentToPatch, ModelState);

            if (!TryValidateModel(appointmentToPatch))
            {
                return(ValidationProblem(ModelState));
            }

            _mapper.Map(appointmentToPatch, existingAppointment);
            _repository.SaveChanges();
            return(NoContent());
        }
Beispiel #2
0
        public ActionResult <AppointmentReadDto> CreateAppointment(AppointmentCreateUpdateDto appointmentCreateDto)
        {
            Appointment model = _mapper.Map <Appointment>(appointmentCreateDto);

            _repository.CreateAppointment(model);
            _repository.SaveChanges();

            return(CreatedAtRoute(nameof(GetAppointments), new { email = model.User.Email }, _mapper.Map <AppointmentReadDto>(model)));
        }