/** * ForumTopic */ /// <summary> /// Get ForumTopic in paged list in a ForumCategorie /// </summary> /// <param name="forumTopicParams">Pagination params</param> /// <param name="id">ForumCategorie primary key</param> /// <returns></returns> public async Task <PagedList <ForumTopic> > GetForumTopics(ForumTopicParams forumTopicParams, int id) { var items = _context.ForumTopics .OrderByDescending(u => u.Date).Where(x => x.ForumCategorieId == id).AsQueryable(); return(await PagedList <ForumTopic> .CreateAsync(items, forumTopicParams.PageNumber, forumTopicParams.PageSize)); }
public async Task <IActionResult> GetForumTopics([FromQuery] ForumTopicParams forumTopicParams, int id) { var items = await _repo.GetForumTopics(forumTopicParams, id); /// No automapp because computed field List <ForumTopicForListDto> newDto = new List <ForumTopicForListDto>(); foreach (var item in items) { var lastForumPost = await _repo.GetLastForumPostFromAForumTopic(item.Id); ForumTopicForListDto dto = new ForumTopicForListDto { Id = item.Id, Name = item.Name, ForumCategorieId = item.ForumCategorieId, ForumCategorie = _mapper.Map <ForumCategorieForListForumTopicDto>(item.ForumCategorie), Date = item.Date, View = item.View, LastForumPost = null, // computed field PageLastForumPost = 0 // computed field }; dto.CountForumPost = await _repo.GetCountLastForumPostFromAForumTopic(item.Id); // computed field // LastForumPost dto.LastForumPost = _mapper.Map <ForumPostForListForumTopicDto>(lastForumPost); if (lastForumPost != null) { var countLastForumPost = await _repo.GetCountLastForumPostFromAForumTopic(lastForumPost.ForumTopicId); var pageSize = new ForumPostParams(); double calc = ((countLastForumPost + pageSize.PageSize - 1) / pageSize.PageSize); dto.PageLastForumPost = Convert.ToInt32(Math.Ceiling(calc)); } else { dto.PageLastForumPost = 0; } newDto.Add(dto); } Response.AddPagination(items.CurrentPage, items.PageSize, items.TotalCount, items.TotalPages); return(Ok(newDto)); }