Пример #1
0
        public IHttpActionResult CreateAppointment(AppointmentModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Check if the patient already have one appointment for the given date
            Domain.Appointment appointment = _appointmentHelper.GetAppointmentsByPatient(model.PatientId).Where(a => a.AppointmentDateTime.Date == model.AppointmentDateTime.Date).FirstOrDefault();

            // No appointments for the given date
            if (appointment == null)
            {
                _appointmentHelper.CreateAppointment(model);
                return(Ok("Success"));
            }
            else
            {
                return(Ok(string.Format("You already have an appointment for {0}", model.AppointmentDateTime.ToString("yyyy-MM-dd"))));
            }
        }