private bool InsertOrganization(OralConsultationItem item, OralConsultation entity)
        {
            foreach (var itm in db.TmpOralConsultationOrganizations.Where(p => p.GUID == item.GUID))
            {
                OralConsultationOrganization dbItem = new OralConsultationOrganization
                {
                    OralConsultation               = entity,
                    OrganizationID                 = itm.OrganizationID,
                    OralConsultationID             = itm.OralConsultationID,
                    OralConsultationOrganizationID = itm.OralConsultationOrganizationID
                };
                db.OralConsultationOrganizations.Add(dbItem);
            }

            List <int> deletionTempItems = new List <int>();

            foreach (var itm3 in db.TmpOralConsultationOrganizations.Where(p => p.GUID == item.GUID))
            {
                deletionTempItems.Add(itm3.ID);
            }
            foreach (int ID in deletionTempItems)
            {
                db.TmpOralConsultationOrganizations.Remove(db.TmpOralConsultationOrganizations.Find(ID));
            }
            return(true);
        }
        private bool UpdateOrganization(OralConsultationItem item, OralConsultation entity)
        {
            List <int> existingItems = new List <int>();

            foreach (var itm in db.TmpOralConsultationOrganizations.Where(p => p.GUID == item.GUID))
            {
                existingItems.Add(itm.OralConsultationOrganizationID);
                OralConsultationOrganization dbItem = new OralConsultationOrganization
                {
                    OralConsultation               = entity,
                    OrganizationID                 = itm.OrganizationID,
                    OralConsultationID             = itm.OralConsultationID,
                    OralConsultationOrganizationID = itm.OralConsultationOrganizationID
                };

                if (itm.OralConsultationOrganizationID == 0)
                {
                    db.OralConsultationOrganizations.Add(dbItem);
                }
                else
                {
                    db.OralConsultationOrganizations.Attach(dbItem);
                    db.Entry(dbItem).State = EntityState.Modified;
                }
            }

            List <int> deletedItems = new List <int>();

            foreach (var itm2 in db.OralConsultationOrganizations.Where(p => p.OralConsultationID == item.OralConsultationID))
            {
                deletedItems.Add(itm2.OralConsultationOrganizationID);
            }

            List <int> common = deletedItems.Except(existingItems).ToList();

            foreach (int deletionID in common)
            {
                db.OralConsultationOrganizations.Remove(db.OralConsultationOrganizations.Find(deletionID));
            }

            List <int> deletionTempItems = new List <int>();

            foreach (var itm3 in db.TmpOralConsultationOrganizations.Where(p => p.GUID == item.GUID))
            {
                deletionTempItems.Add(itm3.ID);
            }
            foreach (int ID in deletionTempItems)
            {
                db.TmpOralConsultationOrganizations.Remove(db.TmpOralConsultationOrganizations.Find(ID));
            }
            return(true);
        }