private List <DtoComment> GetCommentsByCommentId(int postId) { string endpointComment = ConfigurationManager.AppSettings["Comments"]; List <DtoComment> comments = new List <DtoComment>(); var text = client.DownloadString($"{_urlApi}/{endpointComment}?postId={postId}"); object desSerializedObject = _serializer.DeserializeObject(text); if (desSerializedObject != null) { var respuesta = (object[])desSerializedObject; foreach (var item in respuesta) { var dataComment = (Dictionary <string, object>)item; DtoComment Comment = new DtoComment { Id = (int)dataComment["id"], Name = dataComment["name"].ToString(), PostId = (int)dataComment["postId"], Body = dataComment["body"].ToString(), Email = dataComment["email"].ToString(), }; comments.Add(Comment); } } return(comments); }
public void AddComment(DtoComment commentDto) { Comment comment = new Comment(); comment.UserId = commentDto.UserId; comment.PostId = commentDto.PostId; comment.Description = commentDto.Description; comment.CommentCount = commentDto.CommentCount; comment.IsDeleted = commentDto.IsDeleted; db.comments.Add(comment); db.SaveChanges(); }
public List <PostTweetsUsers> GetFriendsConn(int id) { List <DtoUser> userid = new List <DtoUser>(); var result1 = context.connections.Where(x => x.UserIdOne == id && x.IsActive == true).ToList(); foreach (var item in result1) { DtoUser user1 = new DtoUser(); user1.UserId = item.UserIdTwo; userid.Add(user1); } var result2 = context.connections.Where(x => x.UserIdTwo == id && x.IsActive == true).ToList(); foreach (var item in result2) { DtoUser user2 = new DtoUser(); user2.UserId = item.UserIdOne; userid.Add(user2); } DtoUser user = new DtoUser(); user.UserId = id; userid.Add(user); List <DtoUser> users = new List <DtoUser>(); foreach (var item in userid) { DtoUser user3 = new DtoUser(); user3 = userM.GetDtoUserbyId(item.UserId); users.Add(user3); } List <PostTweetsUsers> ptu = new List <PostTweetsUsers>(); foreach (var item in users) { var gelen = context.Post.Where(x => x.UserID == item.UserId) .Include(x => x.Likes) .Include(x => x.Shares). Include(x => x.Comments) .ToList(); foreach (var posts in gelen) { List <DtoComment> commenDtoList = new List <DtoComment>(); PostTweetsUsers post = new PostTweetsUsers(); post.Likeactive = posts.Likes.Any(x => x.IsActive == true); post.Shareactive = posts.Shares.Any(x => x.IsActive == true); post.UserId = item.UserId; post.Name = item.FullName; post.useractive = item.IsActive; post.userdelete = item.IsDeleted; post.Postid = posts.Id; post.ProfilPhoto = item.ProfilPhoto; post.PostPhoto = posts.Photo; post.Text = posts.Description; post.Createddate = posts.CreatedDate; post.LikeCount = posts.Likes.Where(x => x.IsDeleted == false && x.IsActive == true).Count(); post.ShareCount = posts.Likes.Where(x => x.IsDeleted == false && x.IsActive == true).Count(); post.ReplyCount = posts.Comments.Where(x => x.IsDeleted == false && x.IsActive == true).Count(); var result = context.comments.Where(x => x.PostId == posts.Id).ToList(); if (result != null) { foreach (var item2 in result) { DtoComment comment = new DtoComment(); comment.Description = item2.Description; comment.UserId = item2.UserId; comment.PostId = item2.PostId; comment.IsActive = item2.IsActive; comment.IsDeleted = item2.IsDeleted; comment.Photo = userM.GetDtoUserbyId(item2.UserId).ProfilPhoto; comment.Fullname = userM.GetDtoUserbyId(item2.UserId).FullName; commenDtoList.Add(comment); } } post.comments = commenDtoList; ptu.Add(post); } } return(ptu.OrderByDescending(x => x.Createddate).ToList()); }
public IActionResult SendComment(DtoComment commentDto) { comm.AddComment(commentDto); return(Json(true)); }