using System;
using System.Data;
using SiteOffice.Data;
namespace SiteOffice.Business.PrivateMail{
/// <summary>
/// Author: Joe Audette
/// Created: 2006-08-02
/// Last Modified: 2007-11-15
///
/// The use and distribution terms for this software are covered by the
/// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
/// which can be found in the file CPL.TXT at the root of this distribution.
/// By using this software in any fashion, you are agreeing to be bound by
/// the terms of this license.
///
/// You must not remove this notice, or any other, from this software.
/// </summary>
public class PrivateMessage
{
#region Constructors
public PrivateMessage()
{ }
public PrivateMessage(
Guid messageId)
{
GetPrivateMessage(
messageId);
}
#endregion
#region Private Properties
private Guid messageID = Guid.Empty;
private Guid fromUser;
private Guid priorityID;
private string subject;
private string body;
private string toCSVList;
private string ccCSVList;
private string bccCSVList;
private string toCSVLabels;
private string ccCSVLabels;
private string bccCSVLabels;
private DateTime createdDate;
private DateTime sentDate;
#endregion
#region Public Properties
public Guid MessageId
{
get { return messageID; }
set { messageID = value; }
}
public Guid FromUser
{
get { return fromUser; }
set { fromUser = value; }
}
public Guid PriorityId
{
get { return priorityID; }
set { priorityID = value; }
}
public string Subject
{
get { return subject; }
set { subject = value; }
}
public string Body
{
get { return body; }
set { body = value; }
}
public string ToCsvList
{
get { return toCSVList; }
set { toCSVList = value; }
}
public string CCCsvList
{
get { return ccCSVList; }
set { ccCSVList = value; }
}
public string BccCsvList
{
get { return bccCSVList; }
set { bccCSVList = value; }
}
public string ToCsvLabels
{
get { return toCSVLabels; }
set { toCSVLabels = value; }
}
public string CCCsvLabels
{
get { return ccCSVLabels; }
set { ccCSVLabels = value; }
}
public string BccCsvLabels
{
get { return bccCSVLabels; }
set { bccCSVLabels = value; }
}
public DateTime CreatedDate
{
get { return createdDate; }
set { createdDate = value; }
}
public DateTime SentDate
{
get { return sentDate; }
set { sentDate = value; }
}
#endregion
#region Private Methods
private void GetPrivateMessage(
Guid messageId)
{
IDataReader reader = DBPrivateMessage.GetPrivateMessage(
messageId);
if (reader.Read())
{
this.messageID = new Guid(reader["MessageID"].ToString());
this.fromUser = new Guid(reader["FromUser"].ToString());
this.priorityID = new Guid(reader["PriorityID"].ToString());
this.subject = reader["Subject"].ToString();
this.body = reader["Body"].ToString();
this.toCSVList = reader["ToCSVList"].ToString();
this.ccCSVList = reader["CcCSVList"].ToString();
this.bccCSVList = reader["BccCSVList"].ToString();
this.toCSVLabels = reader["ToCSVLabels"].ToString();
this.ccCSVLabels = reader["CcCSVLabels"].ToString();
this.bccCSVLabels = reader["BccCSVLabels"].ToString();
this.createdDate = Convert.ToDateTime(reader["CreatedDate"]);
this.sentDate = Convert.ToDateTime(reader["SentDate"]);
}
reader.Close();
}
private bool Create()
{
Guid newID = Guid.NewGuid();
this.messageID = newID;
int rowsAffected = DBPrivateMessage.AddPrivateMessage(
this.messageID,
this.fromUser,
this.priorityID,
this.subject,
this.body,
this.toCSVList,
this.ccCSVList,
this.bccCSVList,
this.toCSVLabels,
this.ccCSVLabels,
this.bccCSVLabels,
this.createdDate,
this.sentDate);
return (rowsAffected > 0);
}
private bool Update()
{
return DBPrivateMessage.UpdatePrivateMessage(
this.messageID,
this.fromUser,
this.priorityID,
this.subject,
this.body,
this.toCSVList,
this.ccCSVList,
this.bccCSVList,
this.toCSVLabels,
this.ccCSVLabels,
this.bccCSVLabels,
this.createdDate,
this.sentDate);
}
#endregion
#region Public Methods
public bool Save()
{
if (this.messageID != Guid.Empty)
{
return Update();
}
else
{
return Create();
}
}
#endregion
}
}
|