public SugestPublicationViewModel(Publication publication) { Id = publication.Id; Title = publication.Title; #region Pega tecnologias if (publication.Techies.Count > 0) { Techies = new List <TechiesViewModel>(); List <Task <Techie> > tasks = new List <Task <Techie> >(); var techieBo = new TechieBO(); foreach (var tecId in publication.Techies) { tasks.Add(Task.Run(() => techieBo.SearchTechie(tecId))); } Task.WaitAll(tasks.ToArray()); Parallel.ForEach(tasks, task => Techies.Add(new TechiesViewModel(task.Result))); } #endregion Points = publication.Likes.Count - publication.Dislikes.Count; }
public ViewPublicationViewModel(Publication publication) { Id = publication.Id; Title = publication.Title; Description = publication.Description; #region Pega tecnologias if (publication.Techies.Count > 0) { Techies = new List <TechiesViewModel>(); List <Task <Techie> > tasks = new List <Task <Techie> >(); var techieBo = new TechieBO(); foreach (var tecId in publication.Techies) { tasks.Add(Task.Run(() => techieBo.SearchTechie(tecId))); } Task.WaitAll(tasks.ToArray()); Parallel.ForEach(tasks, task => Techies.Add(new TechiesViewModel(task.Result))); } #endregion #region Dados usuario User = new UserInfosViewModel { Id = publication.UserId }; var userBo = new UserBO(); Task.Run(async() => { var user = await userBo.SearchUserPerId(publication.UserId); if (user != null) { User.Name = user.Name; User.Picture = user.Picture; User.Profession = user.Profession; } }).Wait(); #endregion #region Reactions Reactions = new ReactionsViewModel { AgreeQuantity = publication.Likes.Count, DisagreeQuantity = publication.Dislikes.Count, Like = null }; PublicationBO publicationBo = new PublicationBO(); Task.Run(async() => { Reactions.Comments = (await publicationBo.SearchPublicationById(publication.Id)).Comments.Count; }).Wait(); if (!string.IsNullOrEmpty(UtilBO.ValorAuthorizationHeader(System.Web.HttpContext.Current))) { var hashToken = UtilBO.ValorAuthorizationHeader(System.Web.HttpContext.Current); if (!string.IsNullOrEmpty(hashToken)) { Token token = new Token(); var decriptedToken = token.DecodeToken(hashToken); var decriptedTokenValue = decriptedToken.Remove((decriptedToken.Count() - 2), 2).Remove(0, 7); if (publication.Likes.Contains(decriptedTokenValue.ToObjectId())) { Reactions.Like = true; } else if (publication.Dislikes.Contains(decriptedTokenValue.ToObjectId())) { Reactions.Like = false; } } } #endregion Comments = CreatedCommentViewModel.ToList(publication.Comments); DateCreation = publication.DateCreation; }