public async Task <IActionResult> unfallow(long id) { var currentUser = HttpContext.User; if (currentUser.HasClaim(claims => claims.Type == "Id")) { long myId; bool re = long.TryParse((currentUser.Claims.FirstOrDefault(c => c.Type == "Id").Value), out myId); if (!re) { return(BadRequest("Can't parse id")); } if (myId == id) { return(new JsonResult(new { status = "false", message = "you can't unfollow yourself" })); } User me; User otherusr; try { me = _db.Users.Include(user => user.Friends) .Where(user => user.Id == myId).Single(); otherusr = _db.Users.Include(user => user.Friends) .Where(user => user.Id == id).Single(); } catch (ArgumentNullException) { return(BadRequest("User not found")); } Friend following = null; Friend follower = null; try { following = me.Friends.Where(user => user.User1 == id && user.User2 == myId).FirstOrDefault(); follower = me.Friends.Where(user => user.User1 == myId && user.User2 == id).FirstOrDefault(); if (follower != null) { me.Friends.Remove(follower); following = otherusr.Friends.Where(user => user.User1 == myId && user.User2 == id).FirstOrDefault(); otherusr.Friends.Remove(following); _db.Remove(follower); _db.Remove(following); } else { follower = otherusr.Friends.Where(user => user.User1 == id && user.User2 == myId).FirstOrDefault(); me.Friends.Remove(following); otherusr.Friends.Remove(follower); _db.Remove(following); _db.Remove(follower); } _db.SaveChanges(); return(new JsonResult(new { status = "true", message = " success" })); } catch (Exception) { } return(new JsonResult(new { status = "false", message = "You are not following this user" })); } return(new JsonResult(new { status = "false", message = "token invalid" })); }