public TypeConsultationInstanceItem InsertInstance(TypeConsultationInstanceItem item)
        {
            try
            {
                TmpTypeConsultationInstance entity = new TmpTypeConsultationInstance
                {
                    TypeConsultationInstanceID = 0,
                    TypeConsultationID         = item.TypeConsultationID,
                    OrganizationID             = item.OrganizationID,
                    GUID = item.GUID
                };

                db.TmpTypeConsultationInstances.Add(entity);

                db.SaveChanges();

                item.ID = entity.ID;
                item.TypeConsultationInstanceID = entity.TypeConsultationInstanceID;
                Organization organization = db.Organizations.Find(item.OrganizationID);
                item.OrganizationName = organization.OrganizationName;

                return(item);
            }
            catch (Exception ex)
            {
                exception = ex;
                return(null);
            }
        }
        public TypeConsultationInstanceItem UpdateInstance(TypeConsultationInstanceItem item)
        {
            try
            {
                TmpTypeConsultationInstance entity = new TmpTypeConsultationInstance
                {
                    ID = item.ID,
                    TypeConsultationInstanceID = item.TypeConsultationInstanceID,
                    TypeConsultationID         = item.TypeConsultationID,
                    OrganizationID             = item.OrganizationID,
                    GUID = item.GUID
                };

                db.TmpTypeConsultationInstances.Attach(entity);
                db.Entry(entity).State = EntityState.Modified;

                db.SaveChanges();

                Organization organization = db.Organizations.Find(item.OrganizationID);
                item.OrganizationName = organization.OrganizationName;
                return(item);
            }
            catch (Exception ex)
            {
                exception = ex;
                return(null);
            }
        }
        public TypeConsultationInstanceItem DeleteInstance(TypeConsultationInstanceItem item)
        {
            try
            {
                TmpTypeConsultationInstance entity = new TmpTypeConsultationInstance
                {
                    ID = item.ID,
                    TypeConsultationInstanceID = item.TypeConsultationInstanceID,
                    TypeConsultationID         = item.TypeConsultationID,
                    OrganizationID             = item.OrganizationID,
                    GUID = item.GUID
                };

                db.TmpTypeConsultationInstances.Attach(entity);
                db.TmpTypeConsultationInstances.Remove(entity);

                db.SaveChanges();
                return(item);
            }
            catch (Exception ex)
            {
                exception = ex;
                return(null);
            }
        }