Beispiel #1
0
        public async Task <IActionResult> LikeItem(int id)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            int.TryParse(userId, out int requesterId);
            var model = new LikeItemModel
            {
                ItemId = id,
                UserId = requesterId
            };
            var result = await likesManager.LikeItemAsync(model);

            return(Json(result));
        }
Beispiel #2
0
        public async Task SendLike(string itemId)
        {
            if (!int.TryParse(itemId, out int parsedId))
            {
                return;
            }
            var model = new LikeItemModel
            {
                UserId = sessionHelper.GetCurrentUserId(),
                ItemId = parsedId
            };
            var result = await likesManager.LikeItemAsync(model);

            await Clients.Group(itemId.ToString()).SendAsync("OnItemLiked", result, Context.ConnectionId);
        }