public OralConsultationRightItem UpdateRight(OralConsultationRightItem item)
        {
            try
            {
                TmpOralConsultationRight entity = new TmpOralConsultationRight
                {
                    ID = item.ID,
                    OralConsultationRightID = item.OralConsultationRightID,
                    OralConsultationID      = item.OralConsultationID,
                    HumanRightID            = item.HumanRightID,
                    GUID = item.GUID
                };

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

                db.SaveChanges();

                HumanRight humanRight = db.HumanRights.Find(item.HumanRightID);
                item.HumanRightName = humanRight.HumanRightName;
                return(item);
            }
            catch (Exception ex)
            {
                exception = ex;
                return(null);
            }
        }
        public OralConsultationRightItem DeleteRight(OralConsultationRightItem item)
        {
            try
            {
                TmpOralConsultationRight entity = new TmpOralConsultationRight
                {
                    ID = item.ID,
                    OralConsultationRightID = item.OralConsultationRightID,
                    OralConsultationID      = item.OralConsultationID,
                    HumanRightID            = item.HumanRightID,
                    GUID = item.GUID
                };

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

                db.SaveChanges();
                return(item);
            }
            catch (Exception ex)
            {
                exception = ex;
                return(null);
            }
        }
        public OralConsultationRightItem InsertRight(OralConsultationRightItem item)
        {
            try
            {
                TmpOralConsultationRight entity = new TmpOralConsultationRight
                {
                    OralConsultationRightID = 0,
                    OralConsultationID      = item.OralConsultationID,
                    HumanRightID            = item.HumanRightID,
                    GUID = item.GUID
                };

                db.TmpOralConsultationRights.Add(entity);

                db.SaveChanges();

                item.ID = entity.ID;
                item.OralConsultationRightID = entity.OralConsultationRightID;
                HumanRight humanRight = db.HumanRights.Find(item.HumanRightID);
                item.HumanRightName = humanRight.HumanRightName;

                return(item);
            }
            catch (Exception ex)
            {
                exception = ex;
                return(null);
            }
        }
        public OralConsultationItem GetOralConsultationItemByID(int oralConsultationID)
        {
            var oralConsultation = db.OralConsultations.Find(oralConsultationID);
            var issue            = db.Issues.Find(oralConsultation.IssueID);

            OralConsultationItem item = new OralConsultationItem
            {
                OralConsultationID      = oralConsultation.OralConsultationID,
                IssueID                 = issue.IssueID,
                IssueName               = issue.IssueName,
                IssueDate               = issue.IssueDate,
                IssueDescription        = issue.IssueDescription,
                OralConsultationDate    = oralConsultation.OralConsultationDate,
                InvocationTypeID        = oralConsultation.InvocationTypeID,
                TargetGroupID           = oralConsultation.TargetGroupID,
                ProblemDescription      = oralConsultation.ProblemDescription,
                ConsultationDescription = oralConsultation.ConsultationDescription,
                GUID = Guid.NewGuid(),
                InitializationType = InitializationTypes.Update,
                UserID             = String.Empty,
                ChangeDate         = null
            };

            foreach (var consultant in db.OralConsultationConsultants.Where(p => p.OralConsultationID == oralConsultationID))
            {
                TmpOralConsultationConsultant itm = new TmpOralConsultationConsultant();
                itm.OralConsultationConsultantID = consultant.OralConsultationConsultantID;
                itm.OralConsultationID           = consultant.OralConsultationID;
                itm.ConsultantID = consultant.ConsultantID;
                itm.GUID         = item.GUID;
                db.TmpOralConsultationConsultants.Add(itm);
            }

            foreach (var organization in db.OralConsultationOrganizations.Where(p => p.OralConsultationID == oralConsultationID))
            {
                TmpOralConsultationOrganization itm = new TmpOralConsultationOrganization();
                itm.OralConsultationOrganizationID = organization.OralConsultationOrganizationID;
                itm.OralConsultationID             = organization.OralConsultationID;
                itm.OrganizationID = organization.OrganizationID;
                itm.GUID           = item.GUID;
                db.TmpOralConsultationOrganizations.Add(itm);
            }

            foreach (var right in db.OralConsultationRights.Where(p => p.OralConsultationID == oralConsultationID))
            {
                TmpOralConsultationRight itm = new TmpOralConsultationRight();
                itm.OralConsultationRightID = right.OralConsultationRightID;
                itm.OralConsultationID      = right.OralConsultationID;
                itm.HumanRightID            = right.HumanRightID;
                itm.GUID = item.GUID;
                db.TmpOralConsultationRights.Add(itm);
            }

            foreach (var permission in db.OralConsultationPermissions.Where(p => p.OralConsultationID == oralConsultationID))
            {
                TmpOralConsultationPermission itm = new TmpOralConsultationPermission();
                itm.OralConsultationPermissionID = permission.OralConsultationPermissionID;
                itm.OralConsultationID           = permission.OralConsultationID;
                itm.UserID   = permission.UserID;
                itm.IsChange = permission.IsChange;
                itm.IsRead   = permission.IsRead;
                itm.GUID     = item.GUID;
                db.TmpOralConsultationPermissions.Add(itm);
            }

            db.SaveChanges();

            return(item);
        }