public async Task LikeUser(int likerId, string likedUsernameOrId) { int likedId = 0; Int32.TryParse(likedUsernameOrId, out likedId); User liked = null; if (likedId > 0) { liked = await _repo.Get(likedId); } if (liked == null) { liked = await _repo.GetByUsername(likedUsernameOrId); likedId = liked.Id; } if (liked == null) { throw new RestException(HttpStatusCode.NotFound, new { User = "******" }); } var like = await _likesRepo.Get(likerId, likedId); if (like != null) { throw new RestException(HttpStatusCode.BadRequest, new { Like = "You already like this user" }); } like = new Like { LikerId = likerId, LikeeId = likedId, }; await _likesRepo.Create(like); }