private bool InsertRight(OralConsultationItem item, OralConsultation entity)
        {
            foreach (var itm in db.TmpOralConsultationRights.Where(p => p.GUID == item.GUID))
            {
                OralConsultationRight dbItem = new OralConsultationRight
                {
                    OralConsultation        = entity,
                    HumanRightID            = itm.HumanRightID,
                    OralConsultationID      = itm.OralConsultationID,
                    OralConsultationRightID = itm.OralConsultationRightID
                };
                db.OralConsultationRights.Add(dbItem);
            }

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

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

            foreach (var itm in db.TmpOralConsultationRights.Where(p => p.GUID == item.GUID))
            {
                existingItems.Add(itm.OralConsultationRightID);
                OralConsultationRight dbItem = new OralConsultationRight
                {
                    OralConsultation        = entity,
                    HumanRightID            = itm.HumanRightID,
                    OralConsultationID      = itm.OralConsultationID,
                    OralConsultationRightID = itm.OralConsultationRightID
                };

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

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

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

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

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

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

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