Exemplo n.º 1
0
        public async Task <IEnumerable <TeamArticleDto> > GetAllTeamArticleDto(string token)
        {
            List <TeamArticle> teamArticles = (List <TeamArticle>) await _repo.GetTeamArticles();

            List <TeamArticleDto> dtos = new List <TeamArticleDto>();

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                foreach (var item in teamArticles)
                {
                    var response = await httpClient.GetAsync($"api/Team/{item.TeamID}");

                    string apiResponse = await response.Content.ReadAsStringAsync();

                    var            team   = JsonConvert.DeserializeObject <TeamDto>(apiResponse);
                    TeamArticleDto newDto = new TeamArticleDto();
                    newDto.ArticleID = item.ArticleID;
                    newDto.Title     = item.Title;
                    newDto.Content   = item.Body;
                    newDto.Date      = item.Date;
                    newDto.TeamID    = item.TeamID;
                    newDto.Team      = team;
                    newDto.IsVisible = item.IsVisible;
                    newDto.IsPinned  = item.IsPinned;
                    dtos.Add(newDto);
                }
            }
            return(dtos);
        }