我得到了一個奇怪的問題,就像我有一個網站,用戶可以在朋友個人資料頁面上發表評論。每當用戶發表評論時,我的應用程序會向該網頁所有者發送電子郵件,您知道以通知他/她的個人資料頁上的新發布的評論。問題是我想停止發送電子郵件的應用程序,如果該用戶最近發佈了評論,比如5個小時前/更早。這是我使用的功能想嘗試一下:通過LINQ to SQL檢索數據
Public Function CheckForNewPost(ByVal arg As String) As Boolean
Dim x As Integer = 0
Using dc As New WhatEverDataContext()
Dim newcomment = From mytable In dc.PostTable _
Where mytable.PostingUser.ToLower() = User.Identity.Name.ToLower() And mytable.PageOwner.ToLower() = arg.ToLower() And mytable.PostedDate.AddHours(5) >= DateTime.Now _
Select mytable
For Each comment In newcomment
x = x + 1
Next
If x > 0 Then
'user has posted a comment recently
Return True
Else
Return False
End If
End Using
End Function
然後我用這樣的:
Protected Sub Repeater1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewInsertedEventArgs) Handles Repeater1.ItemInserted
'send our mail
Dim PageOwner As String = Request.QueryString.Get("PageOwnerName")
If CheckForNewPost(PageOwner) = False Then
SendEMail(PageOwner)
End If
End Sub
但是即使用戶剛剛提前5小時發佈,該應用仍然會發送郵件。 你覺得我在這裏做什麼?