/** * ForumPost **/ /// <summary> /// Get ForumPosts paged /// </summary> /// <param name="forumPostParams">Pagination params</param> /// <param name="id">ForumTopic primary key</param> /// <returns></returns> public async Task <PagedList <ForumPost> > GetForumPosts(ForumPostParams forumPostParams, int id) { var items = _context.ForumPosts .OrderBy(u => u.Date).Where(x => x.ForumTopicId == id).AsQueryable(); return(await PagedList <ForumPost> .CreateAsync(items, forumPostParams.PageNumber, forumPostParams.PageSize)); }
public async Task <IActionResult> GetForumPosts([FromQuery] ForumPostParams forumPostParams, int id) { var boolTrue = await _repo.IncViewForumTopic(id); if (!boolTrue) { return(BadRequest("Impossible de mettre à jour le nombre de vue du sujet")); } var items = await _repo.GetForumPosts(forumPostParams, id); /// No automapp because computed field List <ForumPostForListDto> itemsDtoFinal = new List <ForumPostForListDto>(); foreach (var item in items) { var userIdCurrent = 0; if (User.Identity.IsAuthenticated) { userIdCurrent = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier)?.Value); } /// No automapp because computed field var userWithVirtual = new UserForListForumPostDto { Id = item.User.Id, Username = item.User.Username, Created = item.User.Created, MessageCount = await _repo.GetCountUserForumPost(item.UserId) }; /// No automapp because computed field var itemDtoWithVirtual = new ForumPostForListDto { Id = item.Id, ForumTopic = _mapper.Map <ForumTopicForListForumPostDto>(item.ForumTopic), // automapp, no change ForumTopicId = item.ForumTopicId, User = userWithVirtual, UserId = item.UserId, Content = item.Content, Date = item.Date, SwCurrentUser = userIdCurrent == item.UserId }; itemsDtoFinal.Add(itemDtoWithVirtual); } Response.AddPagination(items.CurrentPage, items.PageSize, items.TotalCount, items.TotalPages); return(Ok(itemsDtoFinal)); }
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)); }
public async Task <IActionResult> GetForumCategories() { var items = await _repo.GetForumCategories(); List <ForumCategorieForListDto> newDto = new List <ForumCategorieForListDto>(); foreach (var unite in items) { ForumCategorieForListDto dto = new ForumCategorieForListDto { Id = unite.Id, Name = unite.Name }; dto.CountForumTopic = await _repo.GetCountForumTopic(unite.Id); dto.CountForumPost = await _repo.GetCountForumPostFromForumCategorie(unite.Id); var lastForumPost = await _repo.GetLastForumPostFromForumCategorie(unite.Id); dto.LastForumPost = _mapper.Map <ForumPostForListForumCategorieDto>(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); } return(Ok(newDto)); }