Пример #1
0
        public AddCommentResponse Add(string comment, int recipeId, int userId)
        {
            var response = new AddCommentResponse();

            var recipe = _recipesService.GetRecipeById(recipeId);

            if (recipe != null)
            {
                var newComment = new Comment()
                {
                    Message     = comment,
                    DateCreated = DateTime.Now,
                    RecipeId    = recipeId,
                    UserId      = userId
                };

                _commentsRepository.Add(newComment);

                response.Comment = newComment;
            }
            else
            {
                response.Status.IsSuccessful = false;
                response.Status.Message      = $"The recipe with Id {recipeId} was not found";
            }

            return(response);
        }
Пример #2
0
        public static AddCommentResponse mapFromCommentToAddCommentResponse(Comment comment)
        {
            AddCommentResponse result = new AddCommentResponse();

            result.Id      = comment.Id;
            result.Message = comment.Message;
            return(result);
        }
Пример #3
0
 public Task Handle(AddCommentResponse message, IMessageHandlerContext context)
 {
     return(context.Send <RequestCreatePullRequest>(msg =>
     {
         msg.CommentBranchName = this.Data.BranchName;
         msg.BaseBranchName = this.configurationManager.MasterBranchName;
     }));
 }
Пример #4
0
 public override Task <AddCommentResponse> AddComment(AddCommentRequest request, ServerCallContext context)
 {
     try
     {
         PostComment.Comment comment = new PostComment.Comment();
         var returnValue             = comment.AddComment((global::PostComment.Comment)request.Comment);
         var response = new AddCommentResponse {
             Value = returnValue
         };
         return(Task.FromResult(response));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "Error invoking AddComment");
         throw new RpcException(new Status(StatusCode.Internal, ex.Message));
     }
 }
        public AddCommentResponse Post([FromBody] Comment commentArg)
        {
            var response = new AddCommentResponse();

            response.Success = false;
            if (context.OrderRecord.Where(o => o.ProductVariationID == commentArg.ProductId && o.UserId == commentArg.UserId).Count() != 0)
            {
                context.Comment.Add(commentArg);
                context.SaveChanges();
                response.Success = true;
                response.Message = "Comment Added Successfully";
            }
            else
            {
                response.Message = "User has not purchase this product. Cannot comment";
            }
            return(response);
        }
Пример #6
0
        public override Task <AddCommentResponse> AddComment(Protos.AddCommentRequest request, ServerCallContext context)
        {
            AddCommentResponse output = new AddCommentResponse();

            Comment comment = new Comment();

            comment.PostPostId = request.Postid;
            comment.Text       = request.Text;
            comment.Post       = _context.Posts.Find(request.Postid);
            output.BResult     = false;
            if (comment == null || request.Postid == 0)
            {
                return(Task.FromResult(output));
            }
            if (comment.CommentId == 0)
            {
                _context.Comments.Add(comment);
                _context.SaveChanges();
                output.BResult = true;
            }

            return(Task.FromResult(output));
        }
Пример #7
0
        private void AddCommentFinished(object sender, add_commentCompletedEventArgs e)
        {
            AsyncCallState<OperationFinished<AddCommentResponse>> state =
                (AsyncCallState<OperationFinished<AddCommentResponse>>) e.UserState;
            AddCommentResponse response;

            if(e.Error != null)
            {
                response = new AddCommentResponse
                           	{
                           		Error = e.Error,
                                Status = AddCommentStatus.Failed,
                                PostedComment = null,
                           		UserState = state.UserState
                           	};
            }
            else
            {
                AddCommentStatus parsedStatus = StatusMessageParser.ParseAddCommentStatus(e.Result);

                response = new AddCommentResponse
                           	{
                           		Error = e.Error,
                           		Status = parsedStatus,
                           		PostedComment = parsedStatus == AddCommentStatus.Successful
                           		                	?
                           		                		new Comment(e.comment)
                           		                	:
                           		                		null,
                           		UserState = state.UserState
                           	};

                response.Error = response.Status == AddCommentStatus.Unknown
                                    ?
                                        new UnknownOperationStatusException(e.Result)
                                    :
                                        null;
            }

            state.CallbackDelegate(response);
        }