Пример #1
0
        public PostListDto GetByIdAsDto(int id)
        {
            Post getPost = _postRepository.GetById(id, x => x.Include(y => y.PostImages)
                                                   .Include(a => a.PostVideos).Include(comment => comment.PostComments)
                                                   .ThenInclude(tr => tr.CreatedUser).ThenInclude(hg => hg.UserDetail)
                                                   .Include(s => s.CreatedUser).ThenInclude(t => t.UserDetail));

            PostListDto postListDto = new PostListDto
            {
                Id                 = getPost.Id,
                Text               = getPost.Text,
                CreatedDate        = getPost.CreatedDate,
                ImageUrl           = getPost.PostImages.Count() == 0 ? "" : getPost.PostImages.FirstOrDefault().ImageUrl, //TODO It can be more photos of the post
                VideoUrl           = getPost.PostVideos.Count() == 0 ? "" : getPost.PostVideos.FirstOrDefault().VideoUrl, //TODO It can be more videos of the post
                CreatedByUserName  = getPost.CreatedUser == null ? "" : getPost.CreatedUser.UserName,
                CreatedByUserPhoto = getPost.CreatedUser.UserDetail.ProfilePhotoPath,
                PostType           = getPost.PostType,
                Comments           = getPost.PostComments.ToList().Select(y => new PostCommentListDto
                {
                    Text               = y.Text,
                    CreatedDate        = y.CreatedDate,
                    Id                 = y.Id,
                    CreatedByUserName  = y.CreatedUser.UserName,
                    CreatedByUserPhoto = y.CreatedUser.UserDetail.ProfilePhotoPath,
                    PostId             = y.PostId
                }).ToList()
            };

            return(postListDto);
        }
        public PostListDto GetFeed(int startIdx, int count, string userId)
        {
            if (count > _maxPostsPerPage)
            {
                count = _maxPostsPerPage;
            }
            string query = "MATCH(p: Post) -[:PostedBy]->(posting: User), " +
                           "(me: User{ UserId: '" + userId + "'}) " +
                           "WHERE NOT EXISTS((posting) -[:Blocked] - (me)) " +
                           "AND(me.UserId = posting.UserId OR " +
                           $"p.Visability = {(int)PostVisabilityOptions.All} OR (p.Visability = {(int)PostVisabilityOptions.Followers} " +
                           "AND EXISTS((me) -[:Following]->(posting)))) " +
                           "AND(EXISTS((p) -[:Recomended]->(me)) " +
                           "OR EXISTS((p) -[:Referencing]->(me)) " +
                           "OR EXISTS((p) < -[:CommentedOn] - (: Comment) -[:Referencing]->(me)) " +
                           "OR EXISTS((me) - [:Following]->(posting)) " +
                           "OR me.UserId = posting.UserId ) " +
                           "OPTIONAL MATCH(p)< -[l: Like] - (: User) " +
                           "OPTIONAL MATCH(p)-[rel:Referencing]->(ref:User)" +
                           "RETURN DISTINCT " +
                           "p AS Post, posting AS CreatedBy, " +
                           "EXISTS( (p) < -[:Like]-(me) ) AS IsLiked, " +
                           "COUNT(DISTINCT l) AS Likes, COLLECT(DISTINCT {rel:rel,user:ref}) AS Referencing " +
                           $"ORDER BY p.CreatedOn DESC SKIP {startIdx} LIMIT {count}";
            var         res         = Query(query);
            PostListDto postListDto = new PostListDto()
            {
                Posts = DeserializeFeed(res)
            };

            return(postListDto);
        }
Пример #3
0
        /// <summary>
        ///取得單一PO文
        /// </summary>
        public PostListDto GetSingle(string id)
        {
            PostListDto single = (from p in _posts.GetAll2()
                                  join u in _members.GetAll2()
                                  on p.UserId equals u.UserId
                                  join f in _forums.GetAll2()
                                  on p.ForumId equals f.ForumId
                                  where p.PostId.ToString() == id
                                  select new PostListDto
            {
                ForumName = f.ForumName,
                PostId = p.PostId,
                Title = p.Title,
                Description = p.Description,
                CreatedDate = p.CreatedDate,
                UserId = p.UserId,
                UserName = u.Name,
                Rank = _titles.GetAll2().FirstOrDefault(x => x.TitleId == u.TitleId).TitleName,
                RankColor = _titles.GetAll2().FirstOrDefault(x => x.TitleId == u.TitleId).RankColor,
                LikeNumber = p.LikeNumber,
                DisLikeNumber = p.DisLikeNumber,
                State = p.State
            }).FirstOrDefault();

            return(single);
        }
Пример #4
0
 public IActionResult Edit(PostListDto json)
 {
     if (ModelState.IsValid)
     {
         _postservice.Edit(json);
         return(Ok());
     }
     return(Ok());
 }
Пример #5
0
        public void Edit(PostListDto json)
        {
            Posts edit = _posts.GetAll().FirstOrDefault(p => p.PostId == json.PostId);

            edit.Title       = json.Title;
            edit.Description = json.Description;
            edit.State       = json.State;
            _posts.Update(edit);
            _posts.SaveContext();
        }
Пример #6
0
 public IHttpActionResult GetPosts(int start, int count)
 {
     try
     {
         var         token  = Request.Headers.GetValues("x-auth-token").First();
         var         userId = _tokenManager.GetUserId(token);
         PostListDto posts  = _postManager.GetPosts(start, count, userId);
         return(Ok(posts));
     }
     catch (Exception e)
     {
         _log.Error(e);
         return(InternalServerError());
     }
 }
Пример #7
0
        public async Task <PostListDto> GetLatestPostsAsync(
            string postTypeSlug,
            int?categoryId = null,
            string lang    = Language.KEY_fa_IR,
            int pageSize   = 10
            )
        {
            var postType = await _postTypeRepository
                           .GetBySlugAsync(postTypeSlug);

            if (postType == null)
            {
                throw new PostTypeNotFoundException();
            }

            var query = _repository
                        .Query()
                        .Include(_ => _.PostType)
                        .Include(_ => _.CreatorUser)
                        .Include(_ => _.Category)
                        .Include(_ => _.PostTags)
                        .ThenInclude(_ => _.Tag)
                        .AddPublishedRules()
                        .BelongsToWebsite(_websiteInfo.Id)
                        .WithPostType(postType.Id)
                        .HasLanguage(lang);

            if (categoryId.HasValue)
            {
                query = query.HasCategory(categoryId.Value);
            }

            var result = new PostListDto {
                PostTypeSlug = postType.Slug,
                Title        = postType.Title,
                Items        = await query
                               .OrderByDescending(_ => _.PublishDate)
                               .ThenBy(_ => _.OrderNumber)
                               .Take(pageSize)
                               .Select(_ => _.Adapt <PostItemDto>())
                               .ToListAsync()
            };

            return(await Task.FromResult(result));
        }
Пример #8
0
 public IActionResult Delete([FromBody] PostListDto json)
 {
     _postservice.Delete(json.PostId.ToString());
     return(Ok());
 }