Пример #1
0
        public IHttpActionResult DeleteAppointment(int id)
        {
            // Get the maximum cancellation hours
            int maxHoursCancellation = Convert.ToInt16(ConfigurationManager.AppSettings["MaxHoursCancellation"]);

            // Get the appointment detail
            Domain.Appointment appointment = _appointmentHelper.GetAppointments().Where(a => a.Id == id).FirstOrDefault();

            // Check status for the result
            if (appointment == null)
            {
                return(Ok(string.Format("The appointment does not exist.")));
            }
            else if ((appointment.AppointmentDateTime - DateTime.Now).TotalHours < maxHoursCancellation)
            {
                return(Ok(string.Format("Appointments cannot be canceled less than {0} hours in advance.", maxHoursCancellation)));
            }
            else
            {
                _appointmentHelper.DeleteAppointment(id);
                return(Ok("Success"));
            }
        }