Esempio n. 1
0
        public async Task <IActionResult> OnPostAsync(int postId)
        {
            var likeChannel = GrpcChannel.ForAddress("https://localhost:5007");
            var likeClient  = new Liker.LikerClient(likeChannel);

            var reply = await likeClient.AddImageLikeAsync(new PostIdRequest()
            {
                PostId = postId,
                UserId = User.GetUserId(),
                //Status = PostIdRequest.Types.Status.Like
            });

            IsLiked = true;

            return(new RedirectToPageResult("", new{ postId = postId }));
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostAsync(int postId)
        {
            var likeChannel = new Grpc.Core.Channel("localhost:5007", SslCredentials.Insecure);
            var likeClient  = new Liker.LikerClient(likeChannel);

            var reply = await likeClient.AddImageLikeAsync(new PostIdRequest()
            {
                PostId = postId,
                UserId = User.GetUserId(),
                //Status = PostIdRequest.Types.Status.Like
            });

            IsLiked = true;

            return(new RedirectToPageResult("", new{ postId = postId }));
        }
Esempio n. 3
0
        public async Task OnGetAsync(CancellationToken ct)
        {
            try
            {
                var allPosts   = _postService.GetAll();
                var allPostsId = _postService.GetAll().Select(x => x.Id);

                //var channel = new Channel("localhost:5007", SslCredentials.Insecure);
                var channel = GrpcChannel.ForAddress("https://localhost:5007");
                var client  = new Liker.LikerClient(channel);

                var reply = await client.GetAllImagesAndLikesAsync(new Ids()
                {
                    ArrayPostid = { allPostsId }
                }, cancellationToken : ct);

                if (reply.ImageLikeList.Any())
                {
                    foreach (var like in reply.ImageLikeList)
                    {
                        var likedPost = allPosts.Where(p => p.Id == like.PostId).Select(l =>
                        {
                            l.TotalLikeCount = like.TotalCount;
                            return(l);
                        });

                        Posts = allPosts.Union(likedPost).ToList();
                    }
                }
                else
                {
                    Posts = allPosts;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> OnGet(int postId)
        {
            PostViewModel = await _db.Posts.FindAsync(postId);

            var likeChannel = GrpcChannel.ForAddress("https://localhost:5007");
            var likeClient  = new Liker.LikerClient(likeChannel);
            var likeReply   = await likeClient.GetImageLikesAsync(new PostIdRequest()
            {
                PostId = postId,
                UserId = User.GetUserId(),
            });

            Likes = likeReply.TotalCount;
            if (likeReply.UserId == User.GetUserId() && likeReply.Status == TotalLikesReply.Types.Status.Like)
            {
                IsLiked = true;
            }
            else
            {
                IsLiked = false;
            }
            return(Page());
        }