Пример #1
0
        public JsonResult Comment(int topic, string comment)
        {
            if (topic == 0)
            {
                return(Json(new { status = HttpStatusCode.BadRequest }));
            }


            var cTopic = communityService.GetTopic(topic);

            if (cTopic == null)
            {
                return(Json(new { status = HttpStatusCode.NotFound }));
            }

            if (String.IsNullOrEmpty(comment))
            {
                return(Json(new { status = HttpStatusCode.NoContent }));
            }

            ApplicationUser user = memberService.GetUser(User.Identity.Name);


            CommuityTopicComment commentTopic = new CommuityTopicComment
            {
                Content          = comment,
                ComemmentTime    = DateTime.Now,
                CommentUserId    = user.Id,
                CommunityTopicID = topic
            };

            communityService.CreateComment(commentTopic);
            communityService.SaveTopic();
            var jsonData = new
            {
                status = HttpStatusCode.OK,
                data   = new
                {
                    Id            = commentTopic.ID,
                    Content       = commentTopic.Content,
                    Name          = commentTopic.CommentUser.FullName,
                    ComemmentTime = commentTopic.ComemmentTime.ToString()
                }
            };

            return(Json(jsonData));
        }