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 PrivateMessageAttachment
{
#region Constructors
public PrivateMessageAttachment()
{ }
public PrivateMessageAttachment(
Guid attachmentId)
{
GetPrivateMessageAttachment(
attachmentId);
}
#endregion
#region Private Properties
private Guid attachmentID = Guid.Empty;
private Guid messageID;
private string originalFileName;
private string serverFileName;
private DateTime createdDate;
#endregion
#region Public Properties
public Guid AttachmentId
{
get { return attachmentID; }
set { attachmentID = value; }
}
public Guid MessageId
{
get { return messageID; }
set { messageID = value; }
}
public string OriginalFileName
{
get { return originalFileName; }
set { originalFileName = value; }
}
public string ServerFileName
{
get { return serverFileName; }
set { serverFileName = value; }
}
public DateTime CreatedDate
{
get { return createdDate; }
set { createdDate = value; }
}
#endregion
#region Private Methods
private void GetPrivateMessageAttachment(
Guid attachmentId)
{
IDataReader reader = DBPrivateMessageAttachment.GetPrivateMessageAttachment(
attachmentId);
if (reader.Read())
{
this.attachmentID = new Guid(reader["AttachmentID"].ToString());
this.messageID = new Guid(reader["MessageID"].ToString());
this.originalFileName = reader["OriginalFileName"].ToString();
this.serverFileName = reader["ServerFileName"].ToString();
this.createdDate = Convert.ToDateTime(reader["CreatedDate"]);
}
reader.Close();
}
private bool Create()
{
Guid newID = Guid.NewGuid();
this.attachmentID = newID;
int rowsAffected = DBPrivateMessageAttachment.AddPrivateMessageAttachment(
this.attachmentID,
this.messageID,
this.originalFileName,
this.serverFileName,
this.createdDate);
return (rowsAffected > 0);
}
private bool Update()
{
return DBPrivateMessageAttachment.UpdatePrivateMessageAttachment(
this.attachmentID,
this.messageID,
this.originalFileName,
this.serverFileName,
this.createdDate);
}
#endregion
#region Public Methods
public bool Save()
{
if (this.attachmentID != Guid.Empty)
{
return Update();
}
else
{
return Create();
}
}
#endregion
}
}
|