예제 #1
0
 public bool FollowUser(string followedUserName, string followingUserName)
 {
     var userFollowing = GetUserWithName(followingUserName);
     if (userFollowing == null)
     {
         return false;
     }
     var userToFollow = GetUserWithName(followedUserName);
     if (IsFollowing(userFollowing, userToFollow))
     {
         return false;
     }
     var friendship = new Relationship()
     {
         SourceUser = userFollowing,
         DestinationUser = userToFollow,
         RelationshipType = RelationshipType.Friendship,
         TimeStamp = DateTime.Now,
         Active = true
     };
     using (var transaction = _context.Database.BeginTransaction())
     {
         _context.Relationships.Add(friendship);
         _context.SaveChanges();
         friendship.AddNotifications();
         _context.SaveChanges();
         transaction.Commit();
     }
     return true;
 }
예제 #2
0
 private ActionResult GetRelationshipNotificationPartialView(Relationship relationship, bool seen)
 {
     var model = GetRelationshipNotificationModel(relationship, seen);
     return PartialView("RelationshipNotification", model);
 }
예제 #3
0
 private FollowedNotificationViewModel.FollowTypeEnum GetRelationshipNotificationType(Relationship relationship, string currentUser)
 {
     var type = FollowedNotificationViewModel.FollowTypeEnum.NotCurrentUser;
     if (IsCurrentUser(relationship.SourceUser.UserName))
     {
         type = FollowedNotificationViewModel.FollowTypeEnum.CurrentUserFollowing;
     }
     else if (IsCurrentUser(relationship.DestinationUser.UserName))
     {
         type = FollowedNotificationViewModel.FollowTypeEnum.CurrentUserFollowed;
     }
     else if (_notificationsService.IsCurrentFollowing(relationship.SourceUser.UserName) || _notificationsService.IsCurrentFollowing(relationship.DestinationUser.UserName))
     {
         type = FollowedNotificationViewModel.FollowTypeEnum.FriendRelationship;
     }
     return type;
 }
예제 #4
0
        private FollowedNotificationViewModel GetRelationshipNotificationModel(Relationship relationship, bool seen)
        {
            var currentUser = _notificationsService.GetCurrentUserName();
            FollowedNotificationViewModel.FollowTypeEnum type = GetRelationshipNotificationType(relationship, currentUser);

            var model = new FollowedNotificationViewModel(relationship, seen)
            {
                FollowedBy = GetProfileFor(relationship.SourceUser),
                UserFollowed = GetProfileFor(relationship.DestinationUser),
                TimeStamp = relationship.TimeStamp,
                FollowType = type
            };
            return model;
        }