private static List <Guid> GetUserList(NotificationProfile config, Dictionary <string, object> variablesValues, Guid operatorUserId)
        {
            DbContext   commonContext = DynamicModelBuilder.CreateDataSource();
            List <Guid> userList      = new List <Guid>();
            List <NotificationRecipientAttribute> recipientConfigs = config.NotificationRecipientAttributes.ToList() as List <NotificationRecipientAttribute>;
            MetadataService client = new MetadataService();

            foreach (NotificationRecipientAttribute reipientConfig in recipientConfigs)
            {
                FilterCriteriaHelper helper      = new FilterCriteriaHelper(reipientConfig.RecipientEntityId ?? Guid.Empty, variablesValues);
                CriteriaOperator     theOperator = helper.GeneratrCriteria(reipientConfig.Criterion);
                var  filterEntiy      = MetadataProvider.Instance.EntiyMetadata.Where(c => c.EntityId == reipientConfig.RecipientEntityId).First();
                Type filterEntityType = DynamicTypeBuilder.Instance.GetDynamicType(filterEntiy.Name);

                IQueryable query = commonContext.Set(filterEntityType).AsQueryable();
                System.Linq.Expressions.Expression exception = GetExpression(query, theOperator);
                query = query.Provider.CreateQuery(exception);
                IEnumerator     iter = query.GetEnumerator();
                EntityAttribute att  = filterEntiy.Attributes.Where(c => c.AttributeId == reipientConfig.AttributeId).First();
                while (iter.MoveNext())
                {
                    object userIdValue = GetPropertyValue(iter.Current, att.PhysicalName);
                    if (userIdValue is Guid)
                    {
                        Guid userId = (Guid)GetPropertyValue(iter.Current, att.PhysicalName);
                        if (!userList.Contains(userId) && userId != operatorUserId)
                        {
                            userList.Add(userId);
                        }
                    }
                }
            }
            if (config.Subscriptions != null)
            {
                foreach (var subscription in config.Subscriptions)
                {
                    if (subscription.UserId != null && subscription.UserId != operatorUserId)
                    {
                        if (!userList.Contains((Guid)subscription.UserId))
                        {
                            userList.Add((Guid)subscription.UserId);
                        }
                    }
                }
            }
            return(userList);
        }
        private static void ProcessOneEntity(NotificationProfile config, DbContext commonContext,
                                             Guid entityId, Guid operatorUserId, string relationEntityName
                                             , Dictionary <string, object> oldValue, int languageId, bool isSys)
        {
            if (commonContext == null)
            {
                commonContext = DynamicModelBuilder.CreateDataSource();
            }
            var entityInfo                   = MetadataProvider.Instance.EntiyMetadata.Where(c => c.EntityId == config.ProfileVariables.First().NotificationVariable.EntityId).First();
            var entityTypeId                 = entityInfo.EntityId;
            FilterCriteriaHelper helper      = new FilterCriteriaHelper(oldValue, entityTypeId);
            CriteriaOperator     theOperator = helper.GeneratrCriteria(config.Criterion);

            string primaryKey = string.Empty;

            primaryKey = entityInfo.Attributes.Where(c => c.IsPKAttribute == true).First().TableColumnName;

            Type entityInfoType = DynamicTypeBuilder.Instance.GetDynamicType(entityInfo.Name);

            //fetch data
            if (entityId != Guid.Empty)
            {
                theOperator = new GroupOperator(GroupOperatorType.And, theOperator, GetKeyOperator(entityId, primaryKey));
            }
            IQueryable query = commonContext.Set(entityInfoType).AsQueryable();

            try
            {
                System.Linq.Expressions.Expression expression = GetExpression(query, theOperator);
                query = query.Provider.CreateQuery(expression);
                IEnumerator iter           = query.GetEnumerator();
                var         tempEntityList = new ArrayList();
                while (iter.MoveNext())
                {
                    tempEntityList.Add(iter.Current);
                }
                Type attentionType = DynamicTypeBuilder.Instance.GetDynamicType("Notification");
                var  entityList    = new ArrayList();

                foreach (var item in tempEntityList)
                {
                    bool isExist = false;
                    if (entityId == Guid.Empty && isSys)
                    {
                        IQueryable     notificationQuery = commonContext.Set(attentionType).AsQueryable();
                        BinaryOperator binaryOperator    = new BinaryOperator();
                        binaryOperator.OperatorType = BinaryOperatorType.Equal;
                        binaryOperator.LeftOperand  = ConstantValue.Parse("ObjectId");
                        binaryOperator.RightOperand = (Guid)item.GetType().GetProperty(primaryKey).GetValue(item, null);
                        System.Linq.Expressions.Expression attentionException = GetExpression(notificationQuery, binaryOperator);
                        notificationQuery = notificationQuery.Provider.CreateQuery(attentionException);
                        IEnumerator notificationIter = notificationQuery.GetEnumerator();

                        while (notificationIter.MoveNext())
                        {
                            if (notificationIter.Current != null)
                            {
                                isExist = true;
                                continue;
                            }
                        }
                    }
                    if (!isExist)
                    {
                        entityList.Add(item);
                    }
                }
                if (entityList.Count <= 0)
                {
                    return;
                }
                CreateNotificationItem(entityList, primaryKey, entityInfo.Name, config, operatorUserId, relationEntityName, oldValue, languageId);
            }
            catch
            {
            }
        }