Exemplo n.º 1
0
        public bool RateComment(int commentId, int profileId, RateType vote)
        {
            var comm = _commentRepository.GetCommentById(commentId, x => x.Post, x => x.Rating);

            if ((comm == null) ||
                (!_memberService.IsMember(profileId, comm.Post.GroupId)))
            {
                return(false);
            }

            var rate = comm.Rating.FirstOrDefault(x => x.ProfileId == profileId);

            if (rate != null && rate.Value != vote)
            {
                rate.Value = vote;
            }
            else if (rate == null)
            {
                CommentRate r = new CommentRate
                {
                    ProfileId = profileId,
                    Value     = vote
                };
                comm.Rating.Add(r);
            }
            return(_commentRepository.UpdateComment(comm) != null);
        }
        public CommentRateViewModel(CommentRate commentRate)
        {
            RatingImage = "/View/Resources/stars_rating_0.png";

            if (commentRate != null)
            {
                Comment = commentRate.ContentOfComment;
                Time    = commentRate.CommentDateTime.ToLongDateString() + " " + commentRate.CommentDateTime.ToLongTimeString();
                if (commentRate.Ocena >= 1 && commentRate.Ocena <= 5)
                {
                    RatingImage = "/View/Resources/stars_rating_" + commentRate.Ocena + ".png";
                }
            }
        }
        public static void generate()
        {
            var dbContext = new WebContext();

            for (int i = 4; i < 52; i++)
            {
                CommentRate cr = new CommentRate();
                cr.Id        = i;
                cr.Rate      = (i % 2 == 0? -1:1);
                cr.UserLogin = "******" + i.ToString();
                cr.CommentId = i;
                dbContext.CommentRate.Add(cr);
            }
            dbContext.SaveChanges();
        }