Exemplo n.º 1
0
        /// <summary>
        /// Make a profile updated joined activity object from the more generic database activity object
        /// </summary>
        /// <param name="activity"></param>
        /// <returns></returns>
        private ProfileUpdatedActivity GenerateProfileUpdatedActivity(Activity activity)
        {
            var dataPairs = ActivityBase.UnpackData(activity);

            if (!dataPairs.ContainsKey(ProfileUpdatedActivity.KeyUserId))
            {
                // Log the problem then skip
                _loggingService.Error(
                    $"A profile updated activity record with id '{activity.Id}' has no user id in its data.");
                return null;
            }

            var userId = dataPairs[ProfileUpdatedActivity.KeyUserId];
            var user = _context.MembershipUser.FirstOrDefault(x => x.Id == new Guid(userId));

            if (user == null)
            {
                // Log the problem then skip
                _loggingService.Error(
                    $"A profile updated activity record with id '{activity.Id}' has a user id '{userId}' that is not found in the user table.");
                return null;
            }

            return new ProfileUpdatedActivity(activity, user);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Turn the unprocessed data into keyed name-value pairs
        /// </summary>
        /// <returns></returns>
        public static Dictionary<string, string> UnpackData(Activity activity)
        {
            if (activity == null)
            {
                throw new ApplicationException("Attempting to unpack activity data when no database record.");
            }

            var keyValuePairs = new Dictionary<string, string>();

            // Form of data is "name=value,name=value" etc
            var keyValuePairsRaw = activity.Data.Split(new[] { ',' });

            var pattern = new Regex(RegexNameValue, RegexOptions.None);

            foreach (var keyValuePairRaw in keyValuePairsRaw)
            {
                var match = pattern.Match(keyValuePairRaw);

                if (match.Success)
                {
                    keyValuePairs.Add(match.Groups[1].Value, match.Groups[2].Value);
                }
            }

            return keyValuePairs;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Make a badge activity object from the more generic database activity object
        /// </summary>
        /// <param name="activity"></param>
        /// <returns></returns>
        private BadgeActivity GenerateBadgeActivity(Activity activity)
        {
            // Get the corresponding badge
            var dataPairs = ActivityBase.UnpackData(activity);

            if (!dataPairs.ContainsKey(BadgeActivity.KeyBadgeId))
            {
                // Log the problem then skip
                _loggingService.Error(
                    $"A badge activity record with id '{activity.Id}' has no badge id in its data.");
                return null;
            }

            var badgeId = dataPairs[BadgeActivity.KeyBadgeId];
            var badge = _badgeService.Get(new Guid(badgeId));

            if (badge == null)
            {
                // Log the problem then skip
                _loggingService.Error(
                    $"A badge activity record with id '{activity.Id}' has a badge id '{badgeId}' that is not found in the badge table.");
                return null;
            }

            var userId = dataPairs[BadgeActivity.KeyUserId];
            var user = _context.MembershipUser.FirstOrDefault(x => x.Id == new Guid(userId));

            if (user == null)
            {
                // Log the problem then skip
                _loggingService.Error(
                    $"A badge activity record with id '{activity.Id}' has a user id '{userId}' that is not found in the user table.");
                return null;
            }

            return new BadgeActivity(activity, badge, user);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Make a profile updated joined activity object from the more generic database activity object
        /// </summary>
        /// <param name="activity"></param>
        /// <returns></returns>
        private ProfileUpdatedActivity GenerateProfileUpdatedActivity(Activity activity)
        {
            var dataPairs = ActivityBase.UnpackData(activity);

            if (!dataPairs.ContainsKey(ProfileUpdatedActivity.KeyUserId))
            {
                // Log the problem then skip
                _loggingService.Error(string.Format("A profile updated activity record with id '{0}' has no user id in its data.", activity.Id));
                return null;
            }

            var userId = dataPairs[ProfileUpdatedActivity.KeyUserId];
            var user = _membershipRepository.Get(new Guid(userId));

            if (user == null)
            {
                // Log the problem then skip
                _loggingService.Error(string.Format("A profile updated activity record with id '{0}' has a user id '{1}' that is not found in the user table.",
                    activity.Id, userId));
                return null;
            }

            return new ProfileUpdatedActivity(activity, user);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Make a badge activity object from the more generic database activity object
        /// </summary>
        /// <param name="activity"></param>
        /// <returns></returns>
        private BadgeActivity GenerateBadgeActivity(Activity activity)
        {
            // Get the corresponding badge
            var dataPairs = ActivityBase.UnpackData(activity);

            if (!dataPairs.ContainsKey(BadgeActivity.KeyBadgeId))
            {
                // Log the problem then skip
                _loggingService.Error(string.Format("A badge activity record with id '{0}' has no badge id in its data.", activity.Id.ToString()));
                return null;
            }

            var badgeId = dataPairs[BadgeActivity.KeyBadgeId];
            var badge = _badgeRepository.Get(new Guid(badgeId));

            if (badge == null)
            {
                // Log the problem then skip
                _loggingService.Error(string.Format("A badge activity record with id '{0}' has a badge id '{1}' that is not found in the badge table.",
                    activity.Id.ToString(), badgeId));
                return null;
            }

            var userId = dataPairs[BadgeActivity.KeyUserId];
            var user = _membershipRepository.Get(new Guid(userId));

            if (user == null)
            {
                // Log the problem then skip
                _loggingService.Error(string.Format("A badge activity record with id '{0}' has a user id '{1}' that is not found in the user table.",
                    activity.Id, userId));
                return null;
            }

            return new BadgeActivity(activity, badge, user);
        }
Exemplo n.º 6
0
 public void Delete(Activity item)
 {
     _context.Activity.Remove(item);
 }
Exemplo n.º 7
0
 public Activity Add(Activity newActivity)
 {
     return _context.Activity.Add(newActivity);
 }
Exemplo n.º 8
0
 public void Update(Activity item)
 {
     // Check there's not an object with same identifier already in context
     if (_context.Activity.Local.Select(x => x.Id == item.Id).Any())
     {
         throw new ApplicationException("Object already exists in context - you do not need to call Update. Save occurs on Commit");
     }
     _context.Entry(item).State = EntityState.Modified;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Constructor - useful when constructing a badge activity after reading database
 /// </summary>
 public ProfileUpdatedActivity(Activity activity, MembershipUser user)
 {
     ActivityMapped = activity;
     User = user;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Constructor - useful when constructing a badge activity after reading database
 /// </summary>
 public BadgeActivity(Activity activity, Badge badge, MembershipUser user)
 {
     ActivityMapped = activity;
     Badge = badge;
     User = user;
 }