Example #1
0
        public UsersRating GetUsersRating(int blogid)
        {
            var        credential = RateWithAccount ? Context.User.Identity.Name : ExpUtil.GetIPAddress(Context);
            BlogRating rating     = null;

            if (RateWithAccount)
            {
                rating = _db.BlogRatings.FirstOrDefault(r => r.BlogID == blogid && r.credential == credential);
            }
            else
            {
                rating = _db.BlogRatings.FirstOrDefault(r => r.BlogID == blogid && r.credential == credential && DbFunctions.DiffDays(r.ratetime, DateTime.Today) == 0);
            }
            var self = new UsersRating
            {
                BlogID          = blogid,
                credential      = credential,
                RateWithAccount = RateWithAccount
            };

            if (rating != null)
            {
                self.Rating  = rating;
                self.HasPost = rating.PostId.HasValue;
            }
            return(self);
        }
Example #2
0
        public BlogRating AddBlogRating(int blogid, int value, string credential, int?postid = null)
        {
            if (!RatingValue.ContainsKey(value))
            {
                return(null);
            }
            value = RatingValue[value];
            var rate = new BlogRating();

            rate.value      = value;
            rate.ratetime   = DateTime.Now;
            rate.credential = credential;
            rate.BlogID     = blogid;
            rate.RatingID   = Guid.NewGuid();
            rate.PostId     = postid;
            _db.BlogRatings.Add(rate);
            _db.SaveChanges();
            TriggerRateBlog(rate);
            return(rate);
        }
Example #3
0
 private void TriggerRateBlog(BlogRating r) => OnRateBlog?.Invoke(this, new RateEventArgs(r, Context));