public bool                 InteractionCaseCreate(appointments appointment)
        {
            try
            {
                using (var db = GetContextO())
                {
                    List <int>    siteIds      = t.IntLst(appointment.site_ids);
                    List <string> replacements = t.TextLst(appointment.replacements);

                    if (replacements == null)
                    {
                        replacements = new List <string>();
                    }

                    if (appointment.title != "")
                    {
                        replacements.Add("Title::" + appointment.title);
                    }

                    if (appointment.description != "")
                    {
                        replacements.Add("Description::" + appointment.description);
                    }

                    if (appointment.info != "")
                    {
                        replacements.Add("Info::" + appointment.info);
                    }

                    if (appointment.expire_at != DateTime.MinValue)
                    {
                        replacements.Add("Expire::" + appointment.expire_at.ToString());
                    }

                    if (replacements.Count == 0)
                    {
                        replacements = null;
                    }

                    int interCaseId = sdkSqlCon.InteractionCaseCreate((int)appointment.template_id, "", siteIds, appointment.global_id, t.Bool(appointment.connected), replacements);

                    var match = db.appointments.Single(x => x.global_id == appointment.global_id);

                    match.microting_uid = "" + interCaseId;
                    match.updated_at    = DateTime.Now;
                    match.version       = match.version + 1;

                    db.SaveChanges();

                    db.appointment_versions.Add(MapAppointmentVersions(match));
                    db.SaveChanges();
                }

                return(true);
            }
            catch (Exception ex)
            {
                log.LogWarning("Not Specified", t.PrintException(t.GetMethodName() + " failed to create, for the following reason:", ex));
                AppointmentsUpdate(appointment.global_id, WorkflowState.Failed_to_expection, appointment.body, t.PrintException(t.GetMethodName() + " failed to create, for the following reason:", ex), null);
                return(false);
            }
        }
        public bool                 SyncInteractionCase()
        {
            // read input
            #region create
            appointments appoint = AppointmentsFindOne(WorkflowState.Processed);

            if (appoint != null)
            {
                if (InteractionCaseCreate(appoint))
                {
                    bool isUpdated = AppointmentsUpdate(appoint.global_id, WorkflowState.Created, appoint.body, appoint.expectionString, null);

                    if (isUpdated)
                    {
                        return(true);
                    }
                    else
                    {
                        log.LogVariable("Not Specified", nameof(appoint), appoint.ToString());
                        log.LogException("Not Specified", "Failed to update Outlook appointment, but Appointment created in SDK input", new Exception("FATAL issue"), true);
                    }
                }
                else
                {
                    log.LogVariable("Not Specified", nameof(appoint), appoint.ToString());
                    log.LogException("Not Specified", "Failed to created Appointment in SDK input", new Exception("FATAL issue"), true);
                }

                return(false);
            }
            #endregion

            #region delete
            appoint = AppointmentsFindOne(WorkflowState.Canceled);

            if (appoint != null)
            {
                if (InteractionCaseDelete(appoint))
                {
                    bool isUpdated = AppointmentsUpdate(appoint.global_id, WorkflowState.Revoked, appoint.body, appoint.expectionString, null);

                    if (isUpdated)
                    {
                        return(true);
                    }
                    else
                    {
                        log.LogVariable("Not Specified", nameof(appoint), appoint.ToString());
                        log.LogException("Not Specified", "Failed to update Outlook appointment, but Appointment deleted in SDK input", new Exception("FATAL issue"), true);
                    }
                }
                else
                {
                    log.LogVariable("Not Specified", nameof(appoint), appoint.ToString());
                    log.LogException("Not Specified", "Failed to deleted Appointment in SDK input", new Exception("FATAL issue"), true);
                }

                return(false);
            }
            #endregion

            // read output
            return(InteractionCaseProcessed());
        }