public async Task <UserFollowedEvent> AddFollowedEvent(string userId, int eventId) { var user = await userManager.FindByIdAsync(userId); if (user != null) { var _event = await db.Events.Where(e => e.Id == eventId).FirstOrDefaultAsync(); if (_event == null) { throw new DbModelNullException(ExceptionMessageConstants.NullObject); } UserFollowedEvent ufe = new UserFollowedEvent() { Event = _event, EventId = eventId, User = user, UserId = userId }; db.UserFollowedEvents.Add(ufe); await db.SaveChangesAsync(); return(ufe); } else { throw new DbModelNullException(ExceptionMessageConstants.NullObject); } }
private async Task SendUserFollowedEventAsync(Guid followerId, Guid followedUserId) { var @event = new UserFollowedEvent { FollowerId = followerId, FollowedUserId = followedUserId }; await SendEvent(@event); }
// User events private void FollowedUser(object sender, UserFollowedEvent e) { if (e.InResultOf == UserFollowedRaisedInResultOf.AccountUserFollowingAnotherUser) { Console.WriteLine($">>> Account user ({e.FollowedBy.ScreenName}) is now following {e.FollowedUser.ScreenName}"); } else { Console.WriteLine($">>> Account user ({e.FollowedUser.ScreenName}) is now being followed by {e.FollowedBy.ScreenName}"); } }
private void TryRaiseFollowedEvents(string eventName, JObject jsonObjectEvent) { var json = jsonObjectEvent.ToString(); var followEvent = jsonObjectEvent[eventName]; var followedUsersEvents = ExtractUserToUserEventDTOs(followEvent); followedUsersEvents.ForEach(followedUsersEvent => { var sourceUser = _factories.CreateUser(followedUsersEvent.Source); var targetUser = _factories.CreateUser(followedUsersEvent.Target); var timestamp = long.Parse(followedUsersEvent.CreatedTimestamp); var dateOffset = DateTimeOffset.FromUnixTimeMilliseconds(timestamp); var accountActivityEvent = new AccountActivityEvent <Tuple <IUser, IUser> >(new Tuple <IUser, IUser>(sourceUser, targetUser)) { AccountUserId = AccountUserId, EventDate = dateOffset.UtcDateTime, Json = json }; if (followedUsersEvent.Type == "follow") { var eventArgs = new UserFollowedEvent(accountActivityEvent); this.Raise(UserFollowed, eventArgs); if (eventArgs.InResultOf == UserFollowedRaisedInResultOf.Unknown) { this.Raise(EventKnownButNotFullySupportedReceived, new EventKnownButNotSupported(json, eventArgs)); } } else if (followedUsersEvent.Type == "unfollow") { var eventArgs = new UserUnfollowedEvent(accountActivityEvent); this.Raise(UserUnfollowed, eventArgs); if (eventArgs.InResultOf == UserUnfollowedRaisedInResultOf.Unknown) { this.Raise(EventKnownButNotFullySupportedReceived, new EventKnownButNotSupported(json, eventArgs)); } } else { this.Raise(UnsupportedEventReceived, new UnsupportedMessageReceivedEvent(jsonObjectEvent.ToString())); } }); }