public async Task UnfollowUserHandler(FollowUserDto request) { ClaimsPrincipal user = _iHttpContextAccessor.HttpContext.User; string followerName = user.Identity.Name.ToLower(); string followerID = ClaimExtensions.GetUserId(user); var following = await _dbContext.Users.Where(p => p.Username == request.Username.ToLower()).Select(p => new UserEntity() { Id = p.Id, Username = p.Username, Password = p.Password, Email = p.Email, UserFollowRelations = p.UserFollowRelations, }).SingleOrDefaultAsync(); var relation = await _dbContext.UserFollowRelations.Where(p => (p.FollowerId == int.Parse(followerID) && p.FollowingId == following.Id)).Select(p => new UserFollowRelationEntity() { Id = p.Id, FollowerId = p.FollowerId, FollowingId = p.FollowingId, }).SingleOrDefaultAsync(); _dbContext.UserFollowRelations.Remove(relation); await _dbContext.SaveChangesAsync(); }
public async Task FollowUserHandler(FollowUserDto request) { ClaimsPrincipal user = _iHttpContextAccessor.HttpContext.User; string followerName = user.Identity.Name.ToLower(); string followerID = ClaimExtensions.GetUserId(user); var following = await _dbContext.Users.Where(p => p.Username == request.Username.ToLower()).Select(p => new UserEntity() { Id = p.Id, Username = p.Username, Password = p.Password, Email = p.Email, UserFollowRelations = p.UserFollowRelations, }).SingleOrDefaultAsync(); var relation = new UserFollowRelationEntity(); relation.FollowerId = int.Parse(followerID); relation.FollowingId = following.Id; await _dbContext.UserFollowRelations.AddAsync(relation); await _dbContext.SaveChangesAsync(); var activityLog = new ActivityLogEntity() { ActorId = int.Parse(followerID), ActorName = user.Identity.Name, ActionTypeId = (int)ActionLogEnums.Follow, ActionTypeName = "Follow", TargetTweetId = -1, TargetUserId = following.Id, Date = DateTime.Now, }; await _dbContext.ActivityLogs.AddAsync(activityLog); await _dbContext.SaveChangesAsync(); }
public async Task UnfollowUser(FollowUserDto request) { await _iFollowUserCommand.UnfollowUserHandler(request); }