Exemplo n.º 1
0
        public async Task <Comment> CreateAsync(Comment comment)
        {
            var tokenResult = await tokenProvider.RequestAccessToken(new AccessTokenRequestOptions()
            {
                Scopes = new string[] { "commentsgrpc" }
            });

            if (tokenResult.TryGetToken(out var token))
            {
                GrpCore.Metadata headers = new GrpCore.Metadata();
                headers.Add("Authorization", $"Bearer {token.Value}");

                CreateRequest createRequest = new CreateRequest()
                {
                    PhotoId = comment.PhotoId, Subject = comment.Subject, Body = comment.Body
                };
                CreateReply c = await serviceClient.CreateAsync(createRequest, headers);

                return(new Comment {
                    Id = c.Id, PhotoId = c.PhotoId, UserName = c.UserName, Subject = c.Subject, Body = c.Body, SubmittedOn = c.SubmittedOn.ToDateTime()
                });
            }
            else
            {
                throw new UnauthorizedCreateAttemptException <Comment>();
            }
        }
Exemplo n.º 2
0
        public async Task <Comment> CreateAsync(Comment comment)
        {
            CreateRequest createRequest = new CreateRequest()
            {
                PhotoId = comment.PhotoId, Subject = comment.Subject, Body = comment.Body
            };
            CreateReply c = await serviceClient.CreateAsync(createRequest);

            return(new Comment {
                Id = c.Id, PhotoId = c.PhotoId, UserName = c.UserName, Subject = c.Subject, Body = c.Body, SubmittedOn = c.SubmittedOn.ToDateTime()
            });
        }