예제 #1
0
 /// <summary>
 /// Deprecated Method for adding a new object to the BlogPostRatings EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBlogPostRatings(BlogPostRating blogPostRating)
 {
     base.AddObject("BlogPostRatings", blogPostRating);
 }
예제 #2
0
        /// <summary>
        /// POST: Rate a blog post
        /// </summary>
        /// <param name="id">Unique identifier of the blog post for which to rate</param>
        /// <param name="rating">User rating of a blog post</param>
        /// <returns>A JSON result containing a status message</returns>
        public JsonResult Rate(Guid id, int rating)
        {
            AjaxResponseStatus status = new AjaxResponseStatus();
            BlogPostRating postRating = new BlogPostRating
                {
                    BlogPostId = id,
                    IpAddress = Request.ServerVariables["REMOTE_ADDR"],
                    Rating = rating
                };

            using (IDataRepository<BlogPostRating> repository = new DataRepository<BlogPostRating>())
            {
                if (!repository.Fetch().Any(r => r.BlogPostId == id && r.IpAddress == postRating.IpAddress))
                {
                    repository.Create(postRating);
                    repository.SaveChanges();

                    // Acknowledge that the operation was successful
                    status.Status = "Successful";
                }
                else
                {
                    // Acknowledge that the user already rated the post
                    status.Status = "Already rated";
                }
            }

            return Json(status);
        }
예제 #3
0
 /// <summary>
 /// Create a new BlogPostRating object.
 /// </summary>
 /// <param name="blogPostId">Initial value of the BlogPostId property.</param>
 /// <param name="ipAddress">Initial value of the IpAddress property.</param>
 /// <param name="rating">Initial value of the Rating property.</param>
 public static BlogPostRating CreateBlogPostRating(global::System.Guid blogPostId, global::System.String ipAddress, global::System.Int32 rating)
 {
     BlogPostRating blogPostRating = new BlogPostRating();
     blogPostRating.BlogPostId = blogPostId;
     blogPostRating.IpAddress = ipAddress;
     blogPostRating.Rating = rating;
     return blogPostRating;
 }