コード例 #1
0
        public async Task <IActionResult> CreateUpdate([FromBody] AppointmentDTO appointmentDTO)
        {
            try
            {
                // The API will return Bad Request if
                // appointmentDTO is null or ModelState
                // is not valid without executing this method
                // I think I don't need the following code
                // start
                if (appointmentDTO == null)
                {
                    return(BadRequest(ModelState));
                }
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                // end   --- Iyad
                var isDateTimeAvailable = await _appointmentRepository.IsDateTimeAvailable(appointmentDTO.AppointmentDate);

                if (isDateTimeAvailable)
                {
                    return(BadRequest(ModelState));
                }
                var appointment = _mapper.Map <Appointment>(appointmentDTO);
                var response    = await _appointmentRepository.CreateUpdate(appointment);

                if (response == null)
                {
                    return(StatusCode(500, "Something went wrong. Please try again later!"));
                }
                return(Ok(response));
            }
            catch (Exception)
            {
                return(StatusCode(500, "Something went wrong. Please try again later!"));
            }
        }