예제 #1
0
        public ActionResult <CommentViewModel> Post([FromBody] Comment comment)
        {
            try
            {
                bool success = _commentsService.Create(comment);

                if (success)
                {
                    return(CreatedAtAction("Get", new Comment {
                        Id = comment.Id
                    }, new CommentViewModel(comment)));
                }
                else
                {
                    return(NotFound());
                }
            }
            // TODO: Better exception handling, for instance when there is an id conflict return a `Conflict`
            catch (Exception e)
            {
                return(BadRequest(new
                {
                    status = HttpStatusCode.BadRequest,
                    message = $"{e.Message}: {e.InnerException?.Message}"
                }));
            }
        }
예제 #2
0
        public BroadcastResult Handle(AddCommentCommand command)
        {
            _commentsService.Create(command.CreateDto);
            UpdateCache(command.TargetType, command.TargetId);

            return(BroadcastResult.Success);
        }
예제 #3
0
        public BroadcastResult Handle(AddCommentCommand command)
        {
            var commentsTarget = command.Context.GetCommentsTarget();

            _commentsService.Create(command.CreateDto);
            UpdateCache(commentsTarget.Type, commentsTarget.EntityId.Value);

            return(BroadcastResult.Success);
        }
        public HttpResponseMessage CreateComment(string blogId, string postId, HttpRequestMessage request)
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            try
            {
                ICommentsService commentsService = ObjectFactory.GetInstance <ICommentsService>();

                XmlReader       reader = XmlReader.Create(request.Content.ReadAsStreamAsync().Result);
                SyndicationFeed feed   = SyndicationFeed.Load(reader);

                if (feed != null)
                {
                    SyndicationItem item = feed.Items.FirstOrDefault();

                    if (item != null)
                    {
                        Comment newComment = new Comment
                        {
                            content   = ((TextSyndicationContent)item.Content).Text,
                            published = item.PublishDate,
                            updated   = item.LastUpdatedTime
                        };

                        var author = item.Authors.FirstOrDefault();

                        if (author != null)
                        {
                            newComment.author = author.Name;
                            newComment.postId = String.Format("posts/{0}", postId);
                            commentsService.Create(newComment);

                            response.StatusCode = HttpStatusCode.Created;
                            response.Headers.Add("Location", String.Format("{0}/blogs/{1}/posts/{2}/{3}", this.serviceURI, blogId, postId, newComment.Id));
                        }
                        else
                        {
                            response.StatusCode = HttpStatusCode.BadRequest;
                        }
                    }
                    else
                    {
                        response.StatusCode = HttpStatusCode.BadRequest;
                    }
                }
                else
                {
                    response.StatusCode = HttpStatusCode.BadRequest;
                }
            }
            catch (Exception)
            {
                response.StatusCode = HttpStatusCode.InternalServerError;
            }

            return(response);
        }
예제 #5
0
        public async Task <IActionResult> Create(string postId, CommentForCreateDto commentForCreateDto)
        {
            Comment commentToCreate = _mapper.Map <Comment>(commentForCreateDto);

            commentToCreate.PostId   = postId;
            commentToCreate.UserId   = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            commentToCreate.Username = User.FindFirst(ClaimTypes.Name).Value;
            await _commentsService.Create(commentToCreate);

            return(Ok());
        }
예제 #6
0
 public IActionResult Create([FromBody] Comment comment)
 {
     try
     {
         _commentsService.Create(comment);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(BadRequest());
     }
     return(Ok(comment));
 }
예제 #7
0
        public async Task <IActionResult> Create(CommentView commentView)
        {
            try
            {
                commentView.UserId = HttpContext.User.Identity.Name;
                await _commentsService.Create(commentView);

                return(Ok());
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
예제 #8
0
 public IActionResult PostComments([FromForm] CommentsDto comments)
 {
     try
     {
         var result = _commentsService.Create(comments);
         if (result)
         {
             return(RedirectToAction("GetPost"));
         }
         return(Ok(new { Message = "Error" }));
     }
     catch (DbUpdateConcurrencyException)
     {
         return(Ok(new { Message = "Error" }));
     }
 }
예제 #9
0
 public JsonResult AddComment(AddCommentViewModel model)
 {
     if (ModelState.IsValid)
     {
         var commentDto = new UserCommentDto
         {
             MovieID       = model.MovieID,
             UserComment   = model.UserComment,
             UserID        = HttpContext.User.Identity.GetUserId(),
             UserName      = HttpContext.User.Identity.GetUserName(),
             CommentRating = 0
         };
         commentsService.Create(commentDto);
         return(Json(new { success = true, responseText = "Comment was added." }));
     }
     return(Json(new { success = false, responseText = "Error during comment adding." }));
 }
예제 #10
0
 public Task <CommentItem> Create(CommentCreateContract contract)
 {
     return(_service.Create(contract));
 }
예제 #11
0
        public void Post([FromBody] CommentPostDTO comment)
        {
            User addedBy = usersService.GetCurrentUser(HttpContext);

            commentsService.Create(comment, addedBy);
        }
예제 #12
0
 public async Task <ActionResult <Comment> > Create([FromBody] Comment comment)
 {
     return(Ok(await _commentsService.Create(comment)));
 }
예제 #13
0
        public IHttpActionResult PostComment(Comment comment)
        {
            var newComment = CommentService.Create(comment, User.Identity);

            return(Results(newComment));
        }