/// <summary>
        /// Adds the appointment
        /// </summary>
        /// <param name="appointment">appointment</param>
        /// <returns></returns>
        public Response <AppointmentModel> AddAppointment(AppointmentModel appointment)
        {
            var response = new Response <AppointmentModel>();

            response.DataItems = new List <AppointmentModel>();

            if (appointment.Recurrence != null && appointment.Recurrence.IsRecurring)
            {
                appointment.RecurrenceID = _recurrenceDataProvider.AddRecurrence(appointment.Recurrence);

                var recurrenceCalculator = new RecurrenceCalculator(appointment);
                var appts = recurrenceCalculator.GetAppts();

                if (appts.Count > 0)
                {
                    using (var transactionScope = unitOfWork.BeginTransactionScope())
                    {
                        try
                        {
                            appts.ForEach(appt =>
                            {
                                var appointmentParameters = BuildAppointmentSpParams(appt, false);
                                var appointmentRepository =
                                    unitOfWork.GetRepository <AppointmentModel>(SchemaName.Scheduling);

                                var apptWithID =
                                    unitOfWork.EnsureInTransaction(appointmentRepository.ExecuteNQStoredProc,
                                                                   "usp_AddAppointment", appointmentParameters,
                                                                   forceRollback: appointment.ForceRollback.GetValueOrDefault(false),
                                                                   idResult: true);

                                // if any of the creation of appointments fail, rollback, and return a response indicating what failed
                                if (apptWithID.ResultCode != 0)
                                {
                                    return;
                                }
                                else
                                {
                                    appt.AppointmentID = apptWithID.ID;
                                }
                            });

                            response.DataItems = appts;
                            response.ID        = appts.Min(x => x.AppointmentID);

                            // no errors creating any appointments, so lock in all appointments created
                            if (!appointment.ForceRollback.GetValueOrDefault(false))
                            {
                                unitOfWork.TransactionScopeComplete(transactionScope);
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Error(ex);
                            response.ResultCode    = -1;
                            response.ResultMessage = "Error while saving the user's profile";
                        }
                    }
                }
            }
            else
            {
                var appointmentParameters = BuildAppointmentSpParams(appointment, false);
                var appointmentRepository = unitOfWork.GetRepository <AppointmentModel>(SchemaName.Scheduling);
                var appointmentResponse   = appointmentRepository.ExecuteNQStoredProc("usp_AddAppointment", appointmentParameters, idResult: true);
                response.ID = appointment.AppointmentID = appointmentResponse.ID;
                response.DataItems.Add(appointment);
            }

            return(response);
        }