private bool InsertConsultant(OralConsultationItem item, OralConsultation entity)
        {
            foreach (var itm in db.TmpOralConsultationConsultants.Where(p => p.GUID == item.GUID))
            {
                OralConsultationConsultant dbItem = new OralConsultationConsultant
                {
                    OralConsultation             = entity,
                    ConsultantID                 = itm.ConsultantID,
                    OralConsultationID           = itm.OralConsultationID,
                    OralConsultationConsultantID = itm.OralConsultationConsultantID
                };
                db.OralConsultationConsultants.Add(dbItem);
            }

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

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

            foreach (var itm in db.TmpOralConsultationConsultants.Where(p => p.GUID == item.GUID))
            {
                existingItems.Add(itm.OralConsultationConsultantID);
                OralConsultationConsultant dbItem = new OralConsultationConsultant
                {
                    OralConsultation             = entity,
                    ConsultantID                 = itm.ConsultantID,
                    OralConsultationID           = itm.OralConsultationID,
                    OralConsultationConsultantID = itm.OralConsultationConsultantID
                };

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

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

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

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

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

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

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