Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions src/Analysim.Web/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,17 @@ public async Task<IActionResult> Follow([FromForm] AccountFollowVM formdata)
{
var username = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
var user = await _dbContext.Users.SingleOrDefaultAsync(u => u.UserName == username);
if (user == null) return NotFound(new { message = "User Not Found" });

// Find User
//var user = await _dbContext.Users.FindAsync(formdata.UserID);
//if (user == null) return NotFound(new { message = "User Not Found " + formdata.UserID });
if (user == null) return NotFound(new { message = "Current user not Found" });

// Find Follower
var follower = await _dbContext.Users.FindAsync(formdata.FollowerID);
if (follower == null) return NotFound(new { message = "User Not Found " + formdata.UserID });
// Find User to follow
var userToFollow = await _dbContext.Users.FindAsync(formdata.UserID);
if (userToFollow == null) return NotFound(new { message = "User to follow not Found" });

// Create Many To Many Connection
var userFollower = new UserUser
{
UserID = user.Id,
FollowerID = formdata.FollowerID
UserID = userToFollow.Id,
FollowerID = user.Id
};

// Add To Database
Expand All @@ -246,7 +242,7 @@ public async Task<IActionResult> Follow([FromForm] AccountFollowVM formdata)
return Ok(new
{
result = userFollower,
message = follower.UserName + " is now following " + user.UserName
message = user.UserName + " is now following " + userToFollow.UserName
});
}

Expand Down Expand Up @@ -845,18 +841,14 @@ public async Task<IActionResult> Unfollow([FromRoute] int userID, [FromRoute] in
{
var username = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
var user = await _dbContext.Users.SingleOrDefaultAsync(u => u.UserName == username);
if (user == null) return NotFound(new { message = "User Not Found" });

// Find User
//var user = await _dbContext.Users.FindAsync(userID);
//if (user == null) return NotFound(new { message = "User Not Found" });
if (user == null) return NotFound(new { message = "Current user not found" });

// Find Follower
var follower = await _dbContext.Users.FindAsync(followerID);
if (follower == null) return NotFound(new { message = "Follower Not Found" });
// Find UsertoFollow
var userToFollow = await _dbContext.Users.FindAsync(userID);
if (userToFollow == null) return NotFound(new { message = "User to follow not found" });

// Find Many To Many
var userFollower = await _dbContext.UserUsers.FindAsync(user.Id, follower.Id);
var userFollower = await _dbContext.UserUsers.FindAsync(userToFollow.Id, user.Id);
if (userFollower == null) return NotFound(new { message = "User Follower Connection Not FOund" });

// Remove Project
Expand All @@ -868,7 +860,7 @@ public async Task<IActionResult> Unfollow([FromRoute] int userID, [FromRoute] in
return Ok(new
{
result = userFollower,
message = follower.UserName + " has unfollow " + user.UserName
message = user.UserName + " has unfollow " + userToFollow.UserName
});
}
#endregion
Expand Down