private void EventsOnAfterUpdate(UserAfterUpdateEventArgs userAfterUpdateEventArgs)
        {
            try
            {
                if (userAfterUpdateEventArgs.Id.HasValue)
                {
                    int userId = userAfterUpdateEventArgs.Id.Value;

                    if (_beforeUpdateCache.ContainsKey(userId))
                    {
                        if (_ruleController != null && ProfileChanged(userAfterUpdateEventArgs))
                        {
                            _ruleController.ScheduleTrigger(new Dictionary <string, string>()
                            {
                                {
                                    "UserId", userId.ToString()
                                }
                            });
                        }
                        _beforeUpdateCache.Remove(userId);
                    }
                }
            }
            catch (Exception ex)
            {
                new CSException("Triggers", string.Format("EventsOnAfterUpdate failed for userid:{0}", userAfterUpdateEventArgs.Id.GetValueOrDefault(-1)), ex).Log();
            }
        }
        private void EventsOnAfterUpdate(UserAfterUpdateEventArgs userAfterUpdateEventArgs)
        {
            try
            {
                if (userAfterUpdateEventArgs.Id.HasValue)
                {
                    int userId = userAfterUpdateEventArgs.Id.Value;

                    if (_beforeUpdateCache.ContainsKey(userId))
                    {
                        if (_ruleController != null && ProfileChanged(userAfterUpdateEventArgs))
                        {
                            _ruleController.ScheduleTrigger(new Dictionary<string, string>()
                            {
                                {
                                    "UserId", userId.ToString()
                                }
                            });
                        }
                        _beforeUpdateCache.Remove(userId);
                    }
                }
            }
            catch(Exception ex)
            {
                new CSException("Triggers", string.Format("EventsOnAfterUpdate failed for userid:{0}", userAfterUpdateEventArgs.Id.GetValueOrDefault(-1)), ex).Log();
            }
        }
        /// <summary>
        /// Only want to check that the profile has changed, the user object has a lot of stuff that we would prefer to ignore when it comes to firing event updates
        /// </summary>
        /// <param name="userAfterUpdateEventArgs"></param>
        /// <returns></returns>
        private bool ProfileChanged(UserAfterUpdateEventArgs newDetails)
        {
            User oldDetails = _beforeUpdateCache[newDetails.Id.Value];

            lock (_lockObj)
            {
                foreach (string field in _fields)
                {
                    if (field.StartsWith("-"))
                    {
                        string trimedField = field.TrimStart(new[] { '-' });

                        if (oldDetails.ProfileFields[trimedField].Value != newDetails.ProfileFields[trimedField].Value)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        bool evaluate = false;
                        //Could use reflection if we wanted to increase the number of comparison fields
                        switch (field)
                        {
                        case "UserName":
                            evaluate = oldDetails.Username != newDetails.Username;
                            break;

                        case "DisplayName":
                            evaluate = oldDetails.DisplayName != newDetails.DisplayName;
                            break;

                        case "PrivateEmail":
                            evaluate = oldDetails.PrivateEmail != newDetails.PrivateEmail;
                            break;

                        case "AccountStatus":
                            evaluate = oldDetails.AccountStatus != newDetails.AccountStatus;
                            break;

                        case "AllowSitePartnersToContact":
                            evaluate = oldDetails.AllowSitePartnersToContact != newDetails.AllowSitePartnersToContact;
                            break;

                        case "AllowSiteToContact":
                            evaluate = oldDetails.AllowSiteToContact != newDetails.AllowSiteToContact;
                            break;
                        }

                        if (evaluate)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        /// <summary>
        /// Only want to check that the profile has changed, the user object has a lot of stuff that we would prefer to ignore when it comes to firing event updates
        /// </summary>
        /// <param name="userAfterUpdateEventArgs"></param>
        /// <returns></returns>
        private bool ProfileChanged(UserAfterUpdateEventArgs newDetails)
        {
            User oldDetails = _beforeUpdateCache[newDetails.Id.Value];

            lock (_lockObj)
            {
                foreach (string field in _fields)
                {
                    if (field.StartsWith("-"))
                    {
                        string trimedField = field.TrimStart(new[] { '-' });

                        if (oldDetails.ProfileFields[trimedField].Value != newDetails.ProfileFields[trimedField].Value)
                            return true; 
                    }
                    else
                    {
                        bool evaluate = false;
                        //Could use reflection if we wanted to increase the number of comparison fields
                        switch (field)
                        {
                            case "UserName":
                                evaluate = oldDetails.Username != newDetails.Username;
                                break;
                            case "DisplayName":
                                evaluate = oldDetails.DisplayName != newDetails.DisplayName;
                                break;
                            case "PrivateEmail":
                                evaluate = oldDetails.PrivateEmail != newDetails.PrivateEmail;
                                break;
                            case "AccountStatus":
                                evaluate = oldDetails.AccountStatus != newDetails.AccountStatus;
                                break;
                            case "AllowSitePartnersToContact":
                                evaluate = oldDetails.AllowSitePartnersToContact != newDetails.AllowSitePartnersToContact;
                                break;
                            case "AllowSiteToContact":
                                evaluate = oldDetails.AllowSiteToContact != newDetails.AllowSiteToContact;
                                break;
                        }

                        if (evaluate)
                            return true;
                    }
                }
            }
            return false;
        }