using System;
using System.Data;
using SiteOffice.Data;
namespace SiteOffice.Business.ExternalMail{
/// <summary>
/// Author: Joe Audette
/// Created: 2006-08-20
/// Last Modified: 2007-06-17
///
/// 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 UserEmailAccount
{
#region Constructors
public UserEmailAccount()
{ }
public UserEmailAccount(
Guid iD)
{
GetUserEmailAccount(
iD);
}
#endregion
#region Private Properties
private Guid iD = Guid.Empty;
private Guid userGuid;
private string accountName;
private string userName;
private string email;
private string password;
private string pop3Server;
private int pop3Port;
private string smtpServer;
private int smtpPort;
private bool useSSL = true;
#endregion
#region Public Properties
public Guid ID
{
get { return iD; }
set { iD = value; }
}
public Guid UserGuid
{
get { return userGuid; }
set { userGuid = value; }
}
public string AccountName
{
get { return accountName; }
set { accountName = value; }
}
public string UserName
{
get { return userName; }
set { userName = value; }
}
public string Email
{
get { return email; }
set { email = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
public string Pop3Server
{
get { return pop3Server; }
set { pop3Server = value; }
}
public int Pop3Port
{
get { return pop3Port; }
set { pop3Port = value; }
}
public string SmtpServer
{
get { return smtpServer; }
set { smtpServer = value; }
}
public int SmtpPort
{
get { return smtpPort; }
set { smtpPort = value; }
}
public bool UseSsl
{
get { return useSSL; }
set { useSSL = value; }
}
#endregion
#region Private Methods
private void GetUserEmailAccount(Guid iD)
{
IDataReader reader = DBUserEmailAccount.GetUserEmailAccount(iD);
if (reader.Read())
{
this.iD = new Guid(reader["ID"].ToString());
this.userGuid = new Guid(reader["UserGuid"].ToString());
this.accountName = reader["AccountName"].ToString();
this.userName = reader["UserName"].ToString();
this.email = reader["Email"].ToString();
this.password = reader["Password"].ToString();
this.pop3Server = reader["Pop3Server"].ToString();
this.pop3Port = Convert.ToInt32(reader["Pop3Port"]);
this.smtpServer = reader["SmtpServer"].ToString();
this.smtpPort = Convert.ToInt32(reader["SmtpPort"]);
this.useSSL = Convert.ToBoolean(reader["UseSSL"]);
}
reader.Close();
}
private bool Create()
{
Guid newID = Guid.NewGuid();
this.iD = newID;
int rowsAffected = DBUserEmailAccount.AddUserEmailAccount(
this.iD,
this.userGuid,
this.accountName,
this.userName,
this.email,
this.password,
this.pop3Server,
this.pop3Port,
this.smtpServer,
this.smtpPort,
this.useSSL);
return (rowsAffected > 0);
}
private bool Update()
{
return DBUserEmailAccount.UpdateUserEmailAccount(
this.iD,
this.accountName,
this.userName,
this.email,
this.password,
this.pop3Server,
this.pop3Port,
this.smtpServer,
this.smtpPort,
this.useSSL);
}
#endregion
#region Public Methods
public bool Save()
{
if (this.iD != Guid.Empty)
{
return Update();
}
else
{
return Create();
}
}
#endregion
#region Static Methods
public static IDataReader GetUserEmailAccountByUser(Guid userGuid)
{
return DBUserEmailAccount.GetUserEmailAccountByUser(userGuid);
}
public static bool Delete(Guid id)
{
return DBUserEmailAccount.DeleteUserEmailAccount(id);
}
#endregion
}
}
|