public async Task <ActionResult> Follow(string username) { var user = await userRepository.GetUserByNameAsync(username); var follower = UserId; var model = new Follow(); model.FollowerId = UserId; model.FollowedId = user.Id; model.FollowedOn = DateTime.Now; await this.followRepository.Create(model, user.Id); return(RedirectToAction("Profile", "HomeBlog", new { username = username })); }
public async Task Create(Follow model, string userId) { if (model.FollowedId.Equals(model.FollowerId)) { return; } var follow = await FollowedUser(model.FollowedId, model.FollowerId); if (follow != null) { this.db.Follow.Remove(follow); } else { this.db.Follow.Add(model); } await this.db.SaveChangesAsync(); }