Exemple #1
0
        public ListOfPublicationsViewModel(List <Publication> publications)
        {
            PublicationBO publicationBo = new PublicationBO();

            Task.Run(async() =>
            {
                QuantityOfPages = Math.Ceiling((Convert.ToDouble((await publicationBo.ListPublications()).Count) / 20));
            }).Wait();

            Publications = new List <ViewPublicationViewModel>();
            Publications = ViewPublicationViewModel.ToList(publications);
        }
        public static void Update(PublicationBO pubToUpdate)
        {
            EstimateDBEntities context = new EstimateDBEntities();
            GenericRepository <EstimatePublication> repo = new GenericRepository <EstimatePublication>(context);

            var config      = new MapperConfiguration(cfg => cfg.CreateMap <PublicationBO, EstimatePublication>());
            var mapper      = config.CreateMapper();
            var publication = mapper.Map <EstimatePublication>(pubToUpdate);

            repo.Update(publication);

            repo.Save();
        }
Exemple #3
0
 public ActionResult SavePublication(PublicationBO publicationEntity)
 {
     if (publicationEntity.EST_PUBID != 0 && publicationEntity.EST_PUBID != null)
     {
         PublicationData.Update(publicationEntity);
         return(new HttpStatusCodeResult(201, "Update successful"));
     }
     else
     {
         PublicationData.Save(publicationEntity);
         return(new HttpStatusCodeResult(201, "Creation successful"));
     }
 }
Exemple #4
0
        public ViewTechieViewModel(Techie techie)
        {
            Name = techie.Name;

            var publicationBo = new PublicationBO();

            Task.Run(async() =>
            {
                var publications = await publicationBo.ListPublicationsPerTechieId(techie.Id);

                Points = publications.Sum(a => a.Likes.Count) - publications.Sum(a => a.Dislikes.Count);
                Posts  = publications.Count;
            }).Wait();
        }
Exemple #5
0
 public PublicationController()
 {
     _publicationBo = new PublicationBO();
 }
Exemple #6
0
        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;
        }