Example #1
0
        public ReputationComment ToDALModel(ReputationCommentEntity reputation)
        {
            ReputationComment repComDAL = new ReputationComment()
            {
                UserId    = reputation.UserId,
                CommentId = reputation.ContentCommentId,
                Score     = reputation.Score
            };

            return(repComDAL);
        }
Example #2
0
        public ReputationCommentEntity CreateReputationCommentEntity(RateCommentPostDTO reputation)
        {
            ReputationCommentEntity repInfo = new ReputationCommentEntity()
            {
                UserId           = reputation.userId,
                ContentCommentId = reputation.commentId,
                Score            = reputation.score
            };

            return(repInfo);
        }
Example #3
0
        public ReputationCommentEntity ToDomainModel(ReputationComment reputation)
        {
            ReputationCommentEntity repCommDomain = new ReputationCommentEntity()
            {
                Id               = reputation.Id,
                UserId           = reputation.UserId,
                ContentCommentId = reputation.CommentId,
                Score            = reputation.Score,
                user             = this.ToDomainModel(reputation.User)
            };

            return(repCommDomain);
        }
Example #4
0
        public ActionResult RateComment(int id, int infoId, int placeId, int value)
        {
            var rce = new ReputationCommentEntity
            {
                Score            = value == 1 ? true : false,
                ContentCommentId = id,
                UserId           = (Session["user"] as UserEntity).Id
            };

            try
            {
                var commentService = ServiceFactory.getCommentServices();
                commentService.Rate(rce);
            }
            catch (Exception e)
            {
                ;
            }
            return(RedirectToAction(nameof(InfoDetails), new { id = infoId, placeId = placeId }));
        }
Example #5
0
 //koristi reputationCommentRepository
 public bool Rate(ReputationCommentEntity repCom)
 {
     //Ako je ocjena ista obavijesti korisnika
     //Ako je razlicita - promijeni
     //Ako nije do sad ocijenjeno - ocijeni
     if (_unitOfWork.ReputationCommentRepository.Exists(ri => ri.UserId == repCom.UserId && ri.CommentId == repCom.ContentCommentId && ri.Score == repCom.Score))
     {
         throw new Exception("Već ste dali takvu ocjenu za ovaj komentar!");
     }
     else if (_unitOfWork.ReputationCommentRepository.Exists(ri => ri.UserId == repCom.UserId && ri.CommentId == repCom.ContentCommentId && ri.Score == !repCom.Score))
     {
         _unitOfWork.ReputationCommentRepository.Update(repCom, _unitOfWork.Save);
         return(true);
     }
     else
     {
         _unitOfWork.ReputationCommentRepository.Insert(repCom, _unitOfWork.Save);
         return(true);
     }
 }
Example #6
0
        public IHttpActionResult Rate(RateCommentPostDTO reputationComment)
        {
            bool success = true;

            if (ModelState.IsValid)
            {
                try
                {
                    ReputationCommentEntity repCommentDomain = _DTOAssempler.CreateReputationCommentEntity(reputationComment);
                    ICommentServices        commentService   = ServiceFactory.getCommentServices();
                    success = commentService.Rate(repCommentDomain);
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
            else
            {
                return(BadRequest("Neispravni podaci"));
            }

            return(Ok(success));
        }
Example #7
0
        public void BasicCommentTest()
        {
            var ce = new CommentEntity();

            ce.Id            = 7;
            ce.UserId        = 2;
            ce.ContentInfoId = 14;
            var time = DateTime.Now;

            ce.EndTime = time;
            ce.Content = "Comment content";

            Assert.AreEqual(ce.Id, 7, 0, "Wrong Id");
            Assert.AreEqual(ce.UserId, 2, 0, "Wrong UserId");
            Assert.AreEqual(ce.EndTime, time, "Wrong EndTime");
            Assert.AreEqual(ce.ContentInfoId, 14, 0, "Wrong ContentInfoId");
            Assert.AreEqual(ce.Content, "Comment content", "Wrong content");

            var reputation = new List <ReputationCommentEntity>();
            var rep        = new ReputationCommentEntity();

            rep.ContentCommentId = 7;
            rep.Id     = 4;
            rep.Score  = true;
            rep.UserId = 6;
            reputation.Add(rep);
            reputation.Add(rep);
            ce.reputation = reputation;
            Assert.AreEqual(ce.GetReputation(), 2, 0, "Wrong reputation calculation");

            rep       = new ReputationCommentEntity();
            rep.Score = false;
            reputation.Add(rep);
            ce.reputation = reputation;
            Assert.AreEqual(ce.GetReputation(), 1, 0, "Wrong reputation subtraction");
        }