Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 5th, 2008, 07:28 AM
Authorized User
 
Join Date: Jan 2007
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reset Article View Count and Rating

Just thought I would share this.

When developing with the CMS I found I was viewing articles many times and therefore incrementing article view count. Also I may have rated articles during tested. I created the following method to simply reset these values.

Add a new stored procedure:

Code:
CREATE PROCEDURE dbo.rw_Articles_ResetViewCountAndRating
/**********************************************************************
 * SP Name:  Articles_ResetViewCountAndRatings
 * Author:   Retro
 * Date:     05/07/2008 
 * DB(s):    ASPNETDB
 *
 * Purpose:
 * Resets an Articles ViewCount and Rating/Votes
 *
 * Modification Log: Change
 ***********************************************************************
 * 05/07/2008, Ben Foster:
 * Created Stored Procedure
 *
 */
 (
     @ArticleID            int
 )
 
AS

    UPDATE rw_Articles
    SET ViewCount = 0, Votes = 0, TotalRating = 0
    WHERE (ArticleID = @ArticleID)
In SqlArticlesProvider.vb add the following method:

Code:
        ' Resets the ViewCount, Vote and TotalRating for the specified article
        Public Overrides Function ResetViewCountAndRating(ByVal articleID As Integer) As Boolean
            Using cn As New SqlConnection(Me.ConnectionString)
                Dim cmd As New SqlCommand("rw_Articles_ResetViewCountAndRating", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@ArticleID", SqlDbType.Int).Value = articleID
                cn.Open()
                Dim ret As Integer = ExecuteNonQuery(cmd)
                Return (ret = 1)
            End Using
        End Function
In ArticlesProvider.vb add the following function:

Code:
        Public MustOverride Function ResetViewCountAndRating( _
                ByVal articleID As Integer) As Boolean
In BLL Article.vb add following function:

Code:
        ' Resets an article's View Count and Rating
        Public Shared Function ResetViewCountAndRating(ByVal id As Integer) As Boolean
            Return SiteProvider.Articles.ResetViewCountAndRating(id)
        End Function
Finally on ShowArticle.aspx I add:

Code:
                <asp:LinkButton runat="server" ID="btnResetViewCountAndRating" CausesValidation="false"
                    Text="Reset View Count/Rating" Visible="false"/>
On Page_Load:

Code:
                btnResetViewCountAndRating.Visible = Me.UserCanEdit
and then click event for linkbutton:

Code:
        Protected Sub btnResetViewCountAndRating_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnResetViewCountAndRating.Click
            Article.ResetViewCountAndRating(_articleID)
        End Sub
Thought that may be of some use to some people as it will give better indication of how many views are from other people.

Shouldn't be hard to change to C#

Only thing this won't do is clear the user's rating cookie. As I only really needed this method when first going live it does not matter too much. However, if visitors rate your article and then you run this method, it will show the article as not rated but, when they view the article, their rating will be displayed.

To get by this you could extend the reset method to add a date when it was run. Then check date cookie was created. If before reset date then clear the cookie.

Thanks,
 
Old July 18th, 2008, 12:09 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

The problem with this is that, if there are already non-zero values for Rating and ViewCount (say, if the article has been posted a while), you probably don't want to go resetting them.

I think a better solution might be to restrict Rating and ViewCount incrementing by role right up front.

 
Old July 20th, 2008, 10:43 AM
Authorized User
 
Join Date: Jan 2007
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Lee,

Think you're probably right. The above only really works when first deploying the site (where view count's/ratings may have been increased/added during testing), which is what I needed it for. As a solution for the live site, retricting by role (or even preventing view counts/ratings by the person who created the article) seems like a good idea.

Thanks,







Similar Threads
Thread Thread Starter Forum Replies Last Post
Rating &ViewCount do not increment tectrix BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 15 May 30th, 2007 06:46 AM
populate details view or list view non empty rows iinfoque ASP.NET 2.0 Basics 0 March 11th, 2007 06:11 AM
Error in BLL.Article.Article.cs drohm BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 August 14th, 2006 09:56 AM
is there any in built function to count page count g.tamilselvan MySQL 1 February 15th, 2006 07:43 AM
Count, sum, count a value, return records CongoGrey Access 1 April 18th, 2005 02:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.