private void StartWorkflow(int UserId, string text, TextSourceTypeOptions sourceType, int count)
        {
            var contentItem = _contentManager.Get(UserId);
            var contact     = _contentManager.Query().ForType("CommunicationContact").List().Where(x => ((dynamic)x).CommunicationContactPart.UserIdentifier == UserId).FirstOrDefault();        //("CommunicationContact").Where(x => x.UserIdentifier_Id == UserId).List().FirstOrDefault();

            _workflowManager.TriggerEvent("UserTracking", contact, () => new Dictionary <string, object> {
                { "contact", contact },
                { "text", text },
                { "sourceType", sourceType },
                { "count", count },
                { "UserId", UserId }
            });
        }
        public Dictionary <string, int> UpdateUserProfile(int UserId, List <ProfileVM> update)
        {
            var dicSUM = new Dictionary <string, int>();

            foreach (var el in update)
            {
                TextSourceTypeOptions sourcetype = (TextSourceTypeOptions)Enum.Parse(typeof(TextSourceTypeOptions), el.Type);
                var dicout = UpdateUserProfile(UserId, el.Text, sourcetype, el.Count);
                if (dicSUM.ContainsKey(dicout.Keys.First()))
                {
                    dicSUM[dicout.Keys.First()] = dicout[dicout.Keys.First()];
                }
                else
                {
                    dicSUM.Add(dicout.Keys.First(), dicout[dicout.Keys.First()]);
                }
            }
            return(dicSUM);
        }
        public Dictionary <string, int> UpdateUserProfile(int UserId, string text, TextSourceTypeOptions sourceType, int count)
        {
            var item = _userProfilingSummaryRecord.Fetch(x => x.UserProfilingPartRecord.Id.Equals(UserId) && x.Text.Equals(text) && x.SourceType == sourceType).FirstOrDefault();

            if (item == null)
            {
                var userProfilingPartRecord = ((dynamic)_contentManager.Get(UserId)).UserProfilingPart.Record;
                item = new UserProfilingSummaryRecord()
                {
                    SourceType = sourceType,
                    Text       = text,
                    Count      = count,
                    UserProfilingPartRecord = userProfilingPartRecord
                };
                if (sourceType == TextSourceTypeOptions.ContentItem)
                {
                    try {
                        var ci = _contentManager.Get(Convert.ToInt32(text));
                        item.Data = string.Format("{{'ContentType':'{0}','Alias':'{1}'}}", ci.ContentType.Replace("'", "''"), ((dynamic)ci).AutoroutePart.DisplayAlias.Replace("'", "''"));
                    }
                    catch { }
                }
                _userProfilingSummaryRecord.Create(item);
            }
            else
            {
                item.Count += count;
                _userProfilingSummaryRecord.Update(item);
            }
            _userProfilingSummaryRecord.Flush();
            StartWorkflow(UserId, text, sourceType, item.Count);
            var data = new Dictionary <string, int>();

            data.Add(text, item.Count);
            return(data);
        }