Exemplo n.º 1
0
        public ActionResult RetVoteComent(int idDisc, int idComent, string btnAction)
        {
            string     option = btnAction.ToString();
            var        userId = User.Identity.GetUserId();
            Discussoes discs  = db.Discussoes.Find(idDisc);
            //seleciona os LIKES e DISLIKES do COMENTARIO com o id igual ao id passado por parâmetro
            Likes    li  = db.Likes.Select(x => x).Where(x => x.DiscussaoFK == idDisc).Where(x => x.ComentarioFK == idComent).Where(x => x.UtilizadorFK == userId).FirstOrDefault();
            Dislikes dis = db.Dislikes.Select(x => x).Where(x => x.DiscussaoFK == idDisc).Where(x => x.ComentarioFK == idComent).Where(x => x.UtilizadorFK == userId).FirstOrDefault();

            switch (option)
            {
            case "likesComent":
                discs.likes = discs.likes - 1;
                db.Likes.Remove(li);
                db.SaveChanges();
                break;

            case "dislikesComent":
                discs.dislikes = discs.dislikes - 1;
                db.Dislikes.Remove(dis);
                db.SaveChanges();
                break;
            }


            return(RedirectToAction("PergDisc", "PergDisc", new { id = idDisc }));
        }
Exemplo n.º 2
0
        public ActionResult RetVote(int id, string btnAction)
        {
            string     option = btnAction.ToString();
            var        userId = User.Identity.GetUserId();
            Discussoes discs  = db.Discussoes.Find(id);
            Likes      li     = db.Likes.Select(x => x).Where(x => x.DiscussaoFK == id).FirstOrDefault();
            Dislikes   dis    = db.Dislikes.Select(x => x).Where(x => x.DiscussaoFK == id).FirstOrDefault();

            switch (option)
            {
            case "likesDisc":
                discs.likes = discs.likes - 1;
                db.Likes.Remove(li);
                Session["stateVoteDisc"] = false;
                db.SaveChanges();
                break;

            case "dislikesDisc":
                discs.dislikes = discs.dislikes - 1;
                db.Dislikes.Remove(dis);
                Session["stateVoteDiscDislike"] = false;
                db.SaveChanges();
                break;
            }


            return(RedirectToAction("PergDisc", "PergDisc", new { id = id }));
        }
        public void CommentDislike(string userId, int commentId,
                                   string likeSpan, string dislikeSpan)
        {
            Dislikes dislike = repository.Dislikes
                               .FirstOrDefault(d => d.For == "Comment" && d.ForId == commentId &&
                                               d.UserId == userId);

            if (dislike == null)
            {
                dislike = new Dislikes
                {
                    For    = "Comment",
                    ForId  = commentId,
                    UserId = userId
                };
                repository.AddDislike(dislike);

                //notification
                _ = ShowNotification(userId, commentId);
            }
            else
            {
                repository.DeleteDislike(dislike.Id);
            }

            _ = CommentLikesDislikesInitial(userId, commentId, likeSpan, dislikeSpan);
        }
Exemplo n.º 4
0
            public static bool Post(string guid, bool isComment, string key)
            {
                //check if its liked
                if (LikeClass.CheckExistence(guid, isComment, key))
                {
                    return(false);
                }

                //Check if there is already a Dislike by the user
                if (CheckExistence(guid, isComment, key))
                {
                    //delete the Dislike
                    Delete(guid, isComment, key);
                    return(false);
                }

                //post new Dislike
                Dislikes Dislike = new Dislikes
                {
                    Owner_Guid = key,
                };

                if (isComment)
                {
                    Dislike.Comment_Guid = guid;
                }
                else
                {
                    Dislike.Confess_Guid = guid;
                }
                Dislike.Id = Logical.Setter(Dislike.Id);
                contextLite.Dislikes.Insert(Dislike);
                //.Dislikes.InsertOne(Dislike);
                return(true);
            }
Exemplo n.º 5
0
        public ActionResult Vote(int id, string btnAction)
        {
            string option = btnAction.ToString();
            var    userId = User.Identity.GetUserId();
            //procura na base de dados a DISCUSSAO com o id passado por parâmetro
            Discussoes discs = db.Discussoes.Find(id);
            //procura na base de dados se a DISCUSSAO TEM LIKES OU DISLIKES
            Likes    li  = db.Likes.Select(x => x).Where(x => x.DiscussaoFK == id).Where(x => x.ComentarioFK == null).Where(x => x.UtilizadorFK == userId).FirstOrDefault();
            Dislikes dis = db.Dislikes.Select(x => x).Where(x => x.DiscussaoFK == id).Where(x => x.ComentarioFK == null).Where(x => x.UtilizadorFK == userId).FirstOrDefault();

            switch (option)
            {
            case "likesDisc":

                if (discs == null)
                {
                    return(HttpNotFound());
                }

                if (li == null)
                {
                    discs.likes = discs.likes + 1;
                    var newId = db.Likes.Select(x => x.likeID).Count() + 1;
                    //cria um novo LIKE
                    var newLike = new Likes {
                        likeID = newId, dataLike = DateTime.Now, DiscussaoFK = id, UtilizadorFK = userId
                    };
                    //adiciona na BD
                    db.Likes.Add(newLike);
                    Session["stateVoteDisc"] = true;
                }
                db.SaveChanges();
                break;

            case "dislikesDisc":

                if (discs == null)
                {
                    return(HttpNotFound());
                }

                if (dis == null)
                {
                    discs.dislikes = discs.dislikes + 1;
                    var newId = db.Dislikes.Select(x => x.dislikeID).Count() + 1;
                    //cria um novo DISLIKE
                    var newDislike = new Dislikes {
                        dislikeID = newId, dataLike = DateTime.Now, DiscussaoFK = id, UtilizadorFK = userId
                    };
                    //adiciona na BD
                    db.Dislikes.Add(newDislike);
                    Session["stateVoteDiscDislike"] = true;
                }
                db.SaveChanges();
                break;
            }

            return(RedirectToAction("PergDisc", "PergDisc", new { id = id }));
        }
Exemplo n.º 6
0
        public ActionResult VoteComent(int idDisc, int idComent, string btnAction)
        {
            string     option = btnAction.ToString();
            var        userId = User.Identity.GetUserId();
            Discussoes discs  = db.Discussoes.Find(idDisc);
            //Verfica se o COMENTARIO com o ID passado por parâmetro tem algum like ou dislike
            Likes    li  = db.Likes.Select(x => x).Where(x => x.DiscussaoFK == idDisc).Where(x => x.ComentarioFK == idComent).FirstOrDefault();
            Dislikes dis = db.Dislikes.Select(x => x).Where(x => x.DiscussaoFK == idDisc).Where(x => x.ComentarioFK == idComent).FirstOrDefault();

            switch (option)
            {
            case "likesComent":

                if (discs == null)
                {
                    return(HttpNotFound());
                }

                if (li == null)
                {
                    discs.likes = discs.likes + 1;
                    var newId   = db.Likes.Select(x => x.likeID).Count() + 1;
                    var newLike = new Likes {
                        likeID = newId, dataLike = DateTime.Now, DiscussaoFK = idDisc, ComentarioFK = idComent, UtilizadorFK = userId
                    };
                    db.Likes.Add(newLike);
                }
                db.SaveChanges();
                break;

            case "dislikesComent":

                if (discs == null)
                {
                    return(HttpNotFound());
                }

                if (dis == null)
                {
                    discs.dislikes = discs.dislikes + 1;
                    var newId      = db.Dislikes.Select(x => x.dislikeID).Count() + 1;
                    var newDislike = new Dislikes {
                        dislikeID = newId, dataLike = DateTime.Now, DiscussaoFK = idDisc, ComentarioFK = idComent, UtilizadorFK = userId
                    };
                    db.Dislikes.Add(newDislike);
                }
                db.SaveChanges();
                break;
            }

            return(RedirectToAction("PergDisc", "PergDisc", new { id = idDisc }));
        }
Exemplo n.º 7
0
 public bool AddDislike(Dislikes dislike)
 {
     try
     {
         _context.Dislikes.Add(dislike);
         _context.SaveChanges();
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }
        public ActionResult RemoveDislike(string userId, string For, int forId, string spanId)
        {
            ViewData["Id"] = userId;

            Dislikes dislike = repository.Dislikes
                               .FirstOrDefault(d => d.For == For && d.ForId == forId && d.UserId == userId);

            repository.DeleteDislike(dislike.Id);

            return(PartialView("LikesDislikesCount", new LikesDislikes
            {
                For = For,
                ForId = forId,
                spanId = spanId,
                Likes = repository.Likes.Where(l => l.For == For && l.ForId == forId),
                Dislikes = repository.Dislikes.Where(d => d.For == For && d.ForId == forId)
            }));
        }
Exemplo n.º 9
0
 public ActionResult UpdateConfiguracaoExcluidas([FromQuery] int excluido)
 {
     try
     {
         var      sidut = ControllerContext.HttpContext.User.Identity.Name;
         int      idUt  = Int32.Parse(sidut);
         Dislikes l     = new Dislikes();
         l.Utilizadorid = idUt;
         l.Tagid        = excluido;
         _context.Dislikes.Add(l);
         _context.SaveChanges();
         return(Ok(l));
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.Print(e.ToString());
         return(StatusCode(StatusCodes.Status500InternalServerError));
     }
 }
Exemplo n.º 10
0
        public void Dislike(Guid proposalId, Guid userId)
        {
            var like = Db.Likes.FirstOrDefault(d => d.ProposalId == proposalId && d.UserId == userId);
            var isAlreadyDisliked = Db.Dislikes.FirstOrDefault(d => d.ProposalId == proposalId && d.UserId == userId);

            if (like != null)
            {
                Db.Likes.Remove(like);
            }

            if (isAlreadyDisliked != null)
            {
                Db.Dislikes.Remove(isAlreadyDisliked);
                return;
            }

            var dislike = new Dislikes(proposalId, userId);

            Db.Dislikes.Add(dislike);
        }
Exemplo n.º 11
0
        public void IfIsAlreadyDislikedReturnErrorResult()
        {
            //Arrange
            List <Dislikes> dislikes = new List <Dislikes>();
            var             dislike1 = new Dislikes
            {
                User = new Users()
                {
                    UserName = "******"
                },
                Movie = new Movies()
                {
                    Id = Guid.NewGuid()
                }
            };
            var dislike2 = new Dislikes
            {
                User = new Users()
                {
                    UserName = "******"
                },
                Movie = new Movies()
                {
                    Id = Guid.NewGuid()
                }
            };

            dislikes.Add(dislike1);
            dislikes.Add(dislike2);
            dislikesRepo.Setup(x => x.All()).Returns(dislikes.AsQueryable());
            var sut = new VoteServiceTest(movies.Object, genresRepo.Object, commentsRepo.Object, userRepo.Object, likesRepo.Object, dislikesRepo.Object, saver.Object);

            //Act
            var result = sut.LikeOrDislikeAMovie(dislike1.User.UserName, dislike1.Movie.Id, false);

            //Assert
            likesRepo.Verify(x => x.All(), Times.Exactly(1));
            Assert.AreEqual(result.ResulType, ResultType.AlreadyExists);
            Assert.AreEqual(result.ErrorMsg, Constants.ThisUserAlreadyLikedOrDisliked);
        }
        public ActionResult AddDislike(string userId, string For, int forId, string spanId)
        {
            ViewData["Id"] = userId;

            Dislikes dislike = new Dislikes
            {
                For    = For,
                ForId  = forId,
                UserId = userId
            };

            repository.AddDislike(dislike);

            return(PartialView("LikesDislikesCount", new LikesDislikes
            {
                For = For,
                ForId = forId,
                spanId = spanId,
                Likes = repository.Likes.Where(l => l.For == For && l.ForId == forId),
                Dislikes = repository.Dislikes.Where(d => d.For == For && d.ForId == forId)
            }));
        }
Exemplo n.º 13
0
    public void Finalize(IEnumerable <Deity> deities)
    {
        AcceptsPrayers     = Globals.Random.NextDouble() < 0.66f;
        DonationMultiplier = Globals.Random.NextDouble() < 0.66 ? 1 : -1;
        SacrificeCost      = Globals.Random.NextDouble() < 0.2f ? 5 : -1;

        Archetype.Finalize(this, deities);
        foreach (var domain in Domains)
        {
            domain.Finalize(this, deities);
        }

        Likes    = Likes.Distinct().ToList();
        Dislikes = Dislikes.Distinct().ToList();

        var common = Likes.Where(Dislikes.Contains).ToArray();

        foreach (var thing in common)
        {
            Likes.Remove(thing);
            Dislikes.Remove(thing);
        }
    }
Exemplo n.º 14
0
 public ActionResult RemoveConfiguracaoRestricao([FromQuery] int excluido)
 {
     try
     {
         var      sidut = ControllerContext.HttpContext.User.Identity.Name;
         int      idUt  = Int32.Parse(sidut);
         Dislikes l     = _context.Dislikes.Find(idUt, excluido);
         if (l == null)
         {
             return(NotFound(excluido));
         }
         else
         {
             _context.Dislikes.Remove(l);
             _context.SaveChanges();
             return(Ok(l));
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.Print(e.ToString());
         return(StatusCode(StatusCodes.Status500InternalServerError));
     }
 }
Exemplo n.º 15
0
        public async Task VideoDislikes(int videoId, string userId)
        {
            bool     likeInd    = false;
            bool     dislikeInd = false;
            Dislikes dislike    = repository.Dislikes
                                  .FirstOrDefault(d => d.For == "Video" &&
                                                  d.ForId == videoId && d.UserId == userId);

            if (dislike == null)
            {
                dislike = new Dislikes
                {
                    For    = "Video",
                    ForId  = videoId,
                    UserId = userId
                };
                repository.AddDislike(dislike);
                dislikeInd = true;

                _ = ShowNotification(userId, videoId);
            }
            else
            {
                repository.DeleteDislike(dislike.Id);
            }

            int totalLikes = repository.Likes
                             .Where(l => l.For == "Video" && l.ForId == videoId)
                             .Count();
            int totalDislikes = repository.Dislikes
                                .Where(d => d.For == "Video" && d.ForId == videoId)
                                .Count();

            await Clients.All.SendAsync("AddRemoveDislike", videoId, userId,
                                        totalLikes, likeInd, totalDislikes, dislikeInd);
        }
Exemplo n.º 16
0
 private void Apply(DislikeAdded e)
 {
     Dislikes.Add(new Dislike {
         Id = e.DislikeId, Description = e.Description, ParticipantId = e.ParticipantId
     });
 }
Exemplo n.º 17
0
        private void Apply(DislikeDeleted e)
        {
            var dislike = Dislikes.First(l => l.Id == e.DislikeIdentifier);

            Dislikes.Remove(dislike);
        }
Exemplo n.º 18
0
 private void Apply(DislikeUpdated e)
 {
     Dislikes.First(dl => dl.Id == e.DislikeIdentifier).Description = e.Description;
 }
Exemplo n.º 19
0
        private void Apply(DislikeVoteToggled e)
        {
            var dislikeItem = Dislikes.First(l => l.Id == e.DislikeIdentifier);

            dislikeItem.ToggleVote(e.ParticipantId);
        }