public async Task <bool> Add(CommentJson com)
        {
            try
            {
                var NewCom = new Comment
                {
                    Name        = com.Name,
                    LastName    = com.Lastname,
                    Banned      = false,
                    CommentText = com.Message,
                    Company     = com.Company,
                    Created     = DateTime.Now,
                    Dislikes    = 0,
                    Likes       = 0,
                    Gender      = com.Gender,
                    ImageUrl    = com.Img
                };
                await _ctx.Comments.AddAsync(NewCom);

                await _ctx.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
    public void Init(CommentJson commentJson)
    {
        string authorName = commentJson.username;
        string dateStr    = System.DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(commentJson.dateUpdated)).UtcDateTime.ToString("MM/dd/yyyy");

        authorNameAndTimeText.text = authorName + "        " + dateStr;
        commentText.text           = commentJson.comment;
        authorButton.email         = commentJson.email;
        authorEmail         = commentJson.email;
        commentID           = commentJson.comment_id;
        likeNumText.text    = commentJson.like.ToString();
        dislikeNumText.text = commentJson.dislike.ToString();

        if (commentJson.liked)
        {
            likeButton.SetActive(false);
            unlikeButton.SetActive(true);
        }
        if (commentJson.disliked)
        {
            dislikeButton.SetActive(false);
            undislikeButton.SetActive(true);
        }

        RequestIcon(commentJson.email);

        canvasTrans = transform.parent.parent;
    }
        public void CommentRoot_GetJson_SuccessWithoutExceptions()
        {
            // https://derpibooru.org/api/v1/json/comments/7093003
            var             uri         = _baseUri.AppendPathSegment("/comments/7093003");
            CommentRootJson commentRoot = null;
            CommentJson     comment     = null;

            Func <Task> act = async() =>
            {
                var json = await uri.GetStringAsync();

                commentRoot = JsonSerializer.Deserialize <CommentRootJson>(json);
                comment     = commentRoot.Comment;
            };

            act.Should().NotThrow();
            commentRoot.Should().NotBeNull();

            // Property validation
            comment.Id.Should().Be(7093003);
            comment.Author.Should().Be("genervt");
            comment.AvatarUri.Should().Be("https://derpicdn.net/avatars/2018/2/20/121207d4a04abfd859d5a09.png");
            comment.Body.Should().Be("Adorable Fluttershy making cute noises.");
            comment.CreatedAt.Should().Be(DateTime.Parse("2018-04-27T19:40:27"));
            comment.EditReason.Should().BeNullOrEmpty();
            comment.EditedAt.Should().BeNull();
            comment.ImageId.Should().Be(1384692);
            comment.UpdatedAt.Should().Be(DateTime.Parse("2018-04-27T19:40:27"));
            comment.UserId.Should().Be(434362);
        }
Exemple #4
0
        //Get A single comment, primary task is to return JSON to a user who is cancelling an Edit.
        public async Task <IActionResult> GetComment(int id)
        {
            ApplicationUser user = await GetCurrentUserAsync();

            Comment comment = await _context.Comment.FindAsync(id);

            if (comment.UserId != user.Id)
            {
                return(RedirectToAction("ViewGreatHall", "Home", new { category = "All" }));
            }

            CommentJson commentJson = new CommentJson();

            commentJson.Content = comment.Content;

            return(Json(commentJson));
        }
Exemple #5
0
        public async Task <IActionResult> Add([FromBody] CommentJson com)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Wrong model"));
                }

                if (await _service.Add(com))
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Exemple #6
0
        public string SubComment()
        {
            ApiResult result = new ApiResult();

            try
            {
                var pager  = new Pager();
                var Number = ZNRequest.GetString("Number");
                if (string.IsNullOrWhiteSpace(Number))
                {
                    result.message = "参数异常";
                    return(JsonConvert.SerializeObject(result));
                }
                var UserNumber = ZNRequest.GetString("UserNumber");

                var query       = new SubSonic.Query.Select(provider).From <Comment>().Where <Comment>(x => x.ParentCommentNumber == Number);
                var recordCount = query.GetRecordCount();
                if (recordCount == 0)
                {
                    result.result  = true;
                    result.message = new { records = recordCount, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }

                var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;

                var list                   = query.Paged(pager.Index, pager.Size).OrderAsc("ID").ExecuteTypedList <Comment>();
                var users                  = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Number").From <User>().Where("Number").In(list.Select(x => x.CreateUserNumber).Distinct().ToArray()).ExecuteTypedList <User>();
                var parentComments         = new SubSonic.Query.Select(provider, "ID", "ParentCommentNumber", "Number", "CreateUserNumber").From <Comment>().Where("ParentCommentNumber").In(list.Select(x => x.Number).ToArray()).ExecuteTypedList <Comment>();
                var zans                   = db.Find <CommentZan>(x => x.CreateUserNumber == UserNumber).ToList();
                List <CommentJson> newlist = new List <CommentJson>();
                list.ForEach(x =>
                {
                    CommentJson model = new CommentJson();
                    var user          = users.FirstOrDefault(y => y.Number == x.CreateUserNumber);
                    if (user == null)
                    {
                        return;
                    }
                    model.ID             = x.ID;
                    model.Summary        = x.Summary;
                    model.Goods          = x.Goods;
                    model.Number         = x.Number;
                    model.CreateDateText = x.CreateDate.ToString("yyyy-MM-dd");
                    model.ShowPosition   = x.ShowPosition;
                    model.City           = x.City;
                    if (string.IsNullOrWhiteSpace(model.City))
                    {
                        model.ShowPosition = 0;
                    }
                    model.UserID          = user.ID;
                    model.UserNumber      = user.Number;
                    model.NickName        = user.NickName;
                    model.Avatar          = user.Avatar;
                    model.SubCommentCount = parentComments.Count(y => y.ParentCommentNumber == x.Number);
                    if (model.SubCommentCount == 1)
                    {
                        var subuser = db.Single <User>(y => y.Number == parentComments[0].CreateUserNumber);
                        var comment = db.Single <Comment>(y => y.Number == parentComments[0].Number);
                        if (subuser == null && comment == null)
                        {
                            model.SubCommentCount = 0;
                        }
                        if (subuser != null)
                        {
                            model.SubUserName = subuser.NickName;
                        }
                        if (comment != null)
                        {
                            model.SubSummary = comment.Summary;
                        }
                    }
                    model.ArticleNumber = x.ArticleNumber;
                    model.IsZan         = zans.Count(y => y.CommentNumber == x.Number);
                    newlist.Add(model);
                });
                result.result  = true;
                result.message = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = newlist
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_Comment_SubComment:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }