Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 21st, 2007, 02:52 PM
Friend of Wrox
 
Join Date: Sep 2003
Location: Copenhagen, , Denmark.
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default Private Messages

Hi guys (and Maxxim in particular).

I've tried implementing a Private Messages system, and I'd like it to look as much like the one in vB as possible.

For now, I can live without users being able to send a PM to multiple people, and send/receive combinations etc.

I basically just want them to be able to send and receive messages. The problem I have mostly is that the system I know from vB makes a difference between sent and received messages, and splits the functionality accordingly.

I've thus created a SenderDeleted and a Recipient deleted bit column in my database, and have implemented different procedures for this.

However, it's against my nature as an OO programmer to make such a difference, and I would most likely prefer to merge the functionality as much as possible.

What would you guys do? My instinctive approach would be to make a single method, with an overload to indicate whether the deletion is happening from the inbox or the sent box, and based on that, execute the proper procedure.

And I'll most likely just implement a few extra lines in the weekly cleanup procedures to remove any messages where both flags are set to 1.

Comments welcome!

(By the way, jimi. I've used the tool you recommended to generate my code. So far I'm quite enthousiastic. I just won't finish the implementation till I know whether what I'm doing is the right approach :)).

Cheers.

Peter

http://entropia-online.blogspot.com/
__________________
http://entropia-online.blogspot.com/
  #2 (permalink)  
Old October 22nd, 2007, 12:46 AM
Friend of Wrox
 
Join Date: Mar 2006
Location: , , Portugal.
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Peter!

I use one single delete (by recipient). My users couldn't see sent messages. (I'm not providing a mailbox :) )

But if you want to give to yours users one oportunity to see the sent messages you could create two bit columns like you said!
Everytime you make one delete, sql see if the other column is 1 or 0. If is 1 then erase this message from DB.

  #3 (permalink)  
Old October 22nd, 2007, 01:57 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Copenhagen, , Denmark.
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Maxxim,

That'd also work. I don't have a problem with some PMs sitting around for a little bit, though. It'll allow me to possibly undo any mistaken deletes.

:)

Update - I think I might make everybody's life a bit easier, and just rewrite the procs slightly. If I add an "IsSender" bit-flag, the proc can then figure out whether to set the SenderDelete or RecipientDelete. I initially had that, but wasn't sure whether it'd work. I think it would greatly simplify things, though.
Thanks.

Peter

http://entropia-online.blogspot.com/
  #4 (permalink)  
Old October 22nd, 2007, 10:46 AM
Friend of Wrox
 
Join Date: Mar 2006
Location: , , Portugal.
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Why do you you need another column "IsSender" ?

Table:
Code:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Forums_Pmsg](
    [PmsgID] [int] IDENTITY(1,1) NOT NULL,
    [AddedDate] [datetime] NOT NULL CONSTRAINT [DF_Forums_Pmsg_AddedDate]  DEFAULT (getdate()),
    [AddedBy] [nvarchar](256) COLLATE Latin1_General_CI_AS NOT NULL,
    [IsRead] [bit] NOT NULL CONSTRAINT [DF_Forums_Pmsg_IsRead]  DEFAULT ((0)),
    [DeletedBySender] [bit] NOT NULL CONSTRAINT [DF_Forums_Pmsg_DeleteBySender]  DEFAULT ((0)),
    [DeletedByOwner] [bit] NOT NULL CONSTRAINT [DF_Forums_Pmsg_DeleteByOwner]  DEFAULT ((0)),
    [ToMember] [nvarchar](256) COLLATE Latin1_General_CI_AS NOT NULL,
    [Title] [nvarchar](256) COLLATE Latin1_General_CI_AS NOT NULL,
    [Body] [ntext] COLLATE Latin1_General_CI_AS NOT NULL,
 CONSTRAINT [PK_Forums_Pmsg] PRIMARY KEY CLUSTERED 
(
    [PmsgID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
Delete Procedure:
Code:
CREATE PROCEDURE [dbo].[Forums_DeletePmsg]
(
    @PmsgID int,
    @IsSender bit,
    @UserName nvarchar(256)
)
AS

DECLARE @Sender nvarchar(256)
DECLARE @Owner nvarchar(256)
DECLARE @DeletedBySender bit
DECLARE @DeletedByOwner bit

Select    @Sender = AddedBy, 
        @Owner = ToMember, 
        @DeletedBySender = DeletedBySender, 
        @DeletedByOwner = DeletedByOwner 
   FROM Forums_Pmsg WHERE PmsgID = @PmsgID

IF @IsSender = 1
  BEGIN
   --Security: Verify if really is the sender
   IF LOWER(@UserName) = LOWER(@Sender)
   BEGIN
     --Check if the owner already delete it previously
       IF @DeletedByOwner = 1
       BEGIN
          -- Then erase from DB
          DELETE FROM Forums_Pmsg WHERE PmsgID = @PmsgID
       END ELSE -- The owner didn't want to delete yet 
       BEGIN
          Update Forums_Pmsg SET DeletedBySender = 1 WHERE PmsgID = @PmsgID
       END
    END
   END ELSE -- If @IsSender = 0 then the currentUser is the owner
   BEGIN
   --Security: Verify if really is the owner
   IF LOWER(@UserName) = LOWER(@Owner)
   BEGIN
     --Check if the sender already delete it previously
       IF @DeletedBySender = 1
       BEGIN
          -- Then erase from DB
          DELETE FROM Forums_Pmsg WHERE PmsgID = @PmsgID
       END ELSE -- The sender didn't deleted yet 
       BEGIN
          Update Forums_Pmsg SET DeletedByOwner = 1 WHERE PmsgID = @PmsgID
       END
END
   END
DAL Function:
Code:
        Public Overrides Function DeletePmsg(ByVal pmsgID As Integer, ByVal isSender As Boolean, ByVal userName As String) As Boolean
            Using cn As New SqlConnection(Me.ConnectionString)
                Dim cmd As New SqlCommand("Forums_DeletePmsg", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@PmsgID", SqlDbType.Int).Value = pmsgID
                cmd.Parameters.Add("@IsSender", SqlDbType.Bit).Value = CInt(isSender)
                cmd.Parameters.Add("@Username", SqlDbType.Bit).Value = userName
                cn.Open()
                Dim ret As Integer = ExecuteNonQuery(cmd)
                Return (ret = 1)
            End Using
        End Function
With this you preserve you DB so clean as possible!
I didn't test the script... But I think it's okay! (Verify if I missed some "begin" or "end" on delete procedure...
  #5 (permalink)  
Old October 22nd, 2007, 11:00 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Copenhagen, , Denmark.
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default

Maxxim,

The IsSender variable to the procedures you use, is exactly what I meant when I stated I'd add a bitflag IsSender to the procs (procedures) :)

I also added a "DeleteAll" procedure, for when a user wants to completely clean up. I left out the Update, because I don't think people should be able to update a private messages once it's been sent.

:)

I'll keep you updated, and will post my code when I'm done :)

http://entropia-online.blogspot.com/
  #6 (permalink)  
Old October 22nd, 2007, 11:19 AM
Friend of Wrox
 
Join Date: Mar 2006
Location: , , Portugal.
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ohhh I thought that you wanted to add another column!

Be carefull about the deleteAll procedure!

If you want the same pmsg to owner and sender, if one of them deleteall... Te other one couldn't see it anymore!

I agree with the NO UPDATE possibility !
I don't have this either on my PM system...

Good Luck!

  #7 (permalink)  
Old October 22nd, 2007, 12:57 PM
Friend of Wrox
 
Join Date: Sep 2003
Location: Copenhagen, , Denmark.
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default

Maxxim,

I solved that by making "Delete" equal to an update to the column. I.e. The delete does nothing more than toggling the SenderDelete (or RecipientDelete) to 1. I'm also going to implement a constraint where Sender and Recipient cannot be/include the same person. (I know, cheating, but as the immortal Al Bundy always said: "It's only cheating if you get caught!").

I.e.

CREATE PROCEDURE [dbo].[EO_Forums_DeletePrivateMessageByID]
(
    @PrivateMessageID int
    , @UserName nvarchar(256)
    , @IsSender bit
)
AS
IF @IsSender = 0
-- This is the recipient
BEGIN
    UPDATE EO_PrivateMessages
    SET RecipientDelete = 1
    WHERE PrivateMessageID = @PrivateMessageID
    AND RecipientName = @UserName
END
ELSE
BEGIN
    UPDATE EO_PrivateMessages
    SET SenderDelete = 1
    WHERE PrivateMessageID = @PrivateMessageID
    AND SenderName = @UserName
END

and

ALTER PROCEDURE [dbo].[EO_Forums_DeletePrivateMessages]
(
    @UserName nvarchar(256)
    , @IsSender bit
)
AS
IF @IsSender = 0
-- This is the recipient
BEGIN
    UPDATE EO_PrivateMessages
    SET RecipientDelete = 1
    WHERE RecipientName = @UserName
END
ELSE
BEGIN
    UPDATE EO_PrivateMessages
    SET SenderDelete = 1
    WHERE SenderName = @UserName
END

Edit: Whoops. Forgot to add the Addsender bit. Also, I am not to worried about verifying the username. The user will only be able to call the method from code, which ensures a valid username is there. And they'll only see their own Private Messages.


http://entropia-online.blogspot.com/
  #8 (permalink)  
Old October 22nd, 2007, 01:18 PM
Friend of Wrox
 
Join Date: Mar 2006
Location: , , Portugal.
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

very good!

Didn't you preserve your "addedBy" ?

Did you remove this properties from BaseForum?

  #9 (permalink)  
Old October 22nd, 2007, 01:28 PM
Friend of Wrox
 
Join Date: Mar 2006
Location: , , Portugal.
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Did you already make something on UI ?

How you think populate the textBox where the user will write the name for the DestinationUserName?

I used some basics functions but i'm thinking to upgrade it and use somethings like this:

http://www.asp.net/AJAX/AjaxControlT...oComplete.aspx

  #10 (permalink)  
Old October 22nd, 2007, 02:19 PM
Friend of Wrox
 
Join Date: Sep 2003
Location: Copenhagen, , Denmark.
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default

Maxxim - I thought AddedBy was a confusing name, so for now, I'm trying to just do without :p. I haven't tested yet, but you might be right. It being in the BasePage could potentially mess up my cunning plan.

And I did indeed ponder some autocomplete thingy that looks up usernames in the database. I also have found a nice little "popup" control somewhere on codeproject when someone receives a PM: http://www.codeproject.com/aspnet/asppopup.asp. I intend to just fire this every 5 minutes or so, in order to avoid excessive bandwith. It'll also ensure I won't have to create events etc.

However, I'll be happy just to start off with something basic for now, and then extend it later on... For the moment I'm still trying to deal with my resizing CSS problem ;)

http://entropia-online.blogspot.com/
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Private Messages in Forum Antilles128 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 March 19th, 2008 08:19 AM
Please help!!!!!Private Sub Worksheet_Change VicM Excel VBA 1 March 6th, 2008 10:35 PM
private constructor in C# n.nsivakumar C# 1 August 16th, 2006 07:08 AM
C++ classes and private members steuckcl Visual C++ 1 November 2nd, 2005 05:30 PM
Using Private Sub cutovoi Excel VBA 0 February 5th, 2004 12:55 PM



All times are GMT -4. The time now is 10:39 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.