예제 #1
0
        public async Task <Comment> RemoveAsync(int id)
        {
            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}");
                RemoveReply c = await serviceClient.RemoveAsync(new RemoveRequest()
                {
                    Id = id
                }, 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 UnauthorizedDeleteAttemptException <Comment>();
            }
        }
예제 #2
0
        public async Task <Comment> RemoveAsync(int id)
        {
            RemoveReply c = await serviceClient.RemoveAsync(new RemoveRequest()
            {
                Id = id
            });

            return(new Comment {
                Id = c.Id, PhotoId = c.PhotoId, UserName = c.UserName, Subject = c.Subject, Body = c.Body, SubmittedOn = c.SubmittedOn.ToDateTime()
            });
        }
예제 #3
0
        public async Task <Comment> RemoveAsync(int id, string tokenValue)
        {
            Grpc.Core.Metadata headers = new Grpc.Core.Metadata();
            headers.Add("Authorization", $"Bearer {tokenValue}");

            RemoveReply c = await commentsThingClient.RemoveAsync(new RemoveRequest()
            {
                Id = id
            }, headers);

            return(c.ToComment());
        }
 public static Comment ToComment(this RemoveReply c) => new Comment(c.Id, c.PhotoId, c.UserName, c.Subject, c.Body, c.SubmittedOn.ToDateTime());
예제 #5
0
 public static Photo ToPhoto(this RemoveReply p) => new Photo(p.Id, p.Title, p.PhotoFile.ToArray(), p.ImageMimeType, p.Description, p.CreatedDate.ToDateTime(), p.UserName, null);