//------------------------------------------ #endregion #region --------------GetObject-------------- public static MailListEmailsEntity GetObject(int id) { MailListEmailsEntity mail = MailListAchiveSqlDataPrvider.Instance.GetObject(id); //return the object return(mail); }
//------------------------------------------ #endregion #region --------------Create-------------- /// <summary> /// Converts the MailListEmails object properties to SQL paramters and executes the create MailListEmails procedure /// and updates the MailListEmails object with the SQL data by reference. /// <example>[Example]bool status=MailListEmailsSqlDataPrvider.Instance.Create(mailListEmails);.</example> /// </summary> /// <param name="mailListEmails">The MailListEmails object.</param> /// <returns>The status of create query.</returns> public bool Create(MailListEmailsEntity mailListEmails) { using (SqlConnection myConnection = GetSqlConnection()) { SqlCommand myCommand = new SqlCommand("MailListEmails_Create", myConnection); myCommand.CommandType = CommandType.StoredProcedure; // Set the parameters myCommand.Parameters.Add("@MailID", SqlDbType.Int, 4).Direction = ParameterDirection.Output; myCommand.Parameters.Add("@Subject", SqlDbType.NVarChar, 200).Value = mailListEmails.Subject; myCommand.Parameters.Add("@Body", SqlDbType.NVarChar).Value = mailListEmails.Body; myCommand.Parameters.Add("@To", SqlDbType.NVarChar).Value = mailListEmails.ToCollectionSting; myCommand.Parameters.Add("@CC", SqlDbType.NVarChar).Value = mailListEmails.CCCollectionSting; myCommand.Parameters.Add("@BCC", SqlDbType.NVarChar).Value = mailListEmails.BccCollectionSting; myCommand.Parameters.Add("@FromAddress", SqlDbType.NVarChar).Value = mailListEmails.From.Address; myCommand.Parameters.Add("@FromName", SqlDbType.NVarChar).Value = mailListEmails.From.DisplayName; myCommand.Parameters.Add("@Attachments", SqlDbType.NVarChar).Value = mailListEmails.AttachmentsString; //---------------------------------------------------------------------------------------------- //OwnerID myCommand.Parameters.Add("@OwnerID", SqlDbType.UniqueIdentifier).Value = SitesHandler.GetOwnerIDAsGuid(); //---------------------------------------------------------------------------------------------- // Execute the command bool status = false; myConnection.Open(); if (myCommand.ExecuteNonQuery() > 0) { status = true; //Get MailID value from database and set it in object mailListEmails.MailID = (int)myCommand.Parameters["@MailID"].Value; } myConnection.Close(); return(status); } }
public MailListEmailsEntity GetObject(int id) { MailListEmailsEntity mailListEmails = null; using (SqlConnection myConnection = GetSqlConnection()) { SqlCommand myCommand = new SqlCommand("MailListEmails_GetOneByID", myConnection); myCommand.CommandType = CommandType.StoredProcedure; // Set the parameters myCommand.Parameters.Add("@MailID", SqlDbType.Int, 4).Value = id; //---------------------------------------------------------------------------------------------- //OwnerID myCommand.Parameters.Add("@OwnerID", SqlDbType.UniqueIdentifier).Value = SitesHandler.GetOwnerIDAsGuid(); //---------------------------------------------------------------------------------------------- // Execute the command myConnection.Open(); using (SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection)) { if (dr.Read()) { mailListEmails = PopulateEntity(dr); } dr.Close(); } myConnection.Close(); return(mailListEmails); } }
public static bool Save(MailListEmailsEntity mail) { if (mail.From == null) { string fromAddress = ""; string fromName = ""; fromAddress = SiteSettings.MailList_MailFrom; fromName = SiteSettings.MailList_MailFromName; mail.From = new MailAddress(fromAddress, fromName, Encoding.GetEncoding(1256)); } return(MailListAchiveSqlDataPrvider.Instance.Save(mail)); }
//---------------------------------------------------------------------- public static void SendActivationCodeMessage(MailListUsersEntity user) { // prepare message string body = string.Format(DynamicResource.GetText("MailList", "ActivationMailBody"), new string[3] { SitesHandler.GetSiteDomain(), Encryption.Encrypt(user.UserID.ToString()), user.Email }); //string from =MailListEmailsFactory.MailFrom; MailListEmailsEntity mail = new MailListEmailsEntity(); mail.Subject = DynamicResource.GetText("MailList", "ActivationMailSubject"); mail.Body = body; mail.To.Add(user.Email); MailListEmailsFactory.Send(mail); }
//-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- protected static void Send(MailAddress mailFrom, MailAddress mailTo, string subject, string body, List <Attachment> attachments) { MailListEmailsEntity mail = new MailListEmailsEntity(); mail.To.Add(mailTo); mail.From = mailFrom; mail.Subject = subject; mail.Body = body; if (attachments != null) { foreach (Attachment item in attachments) { mail.AttachmentsFilesPathes.Add(item); } } Send(mail); }
//-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- public static void Send(MailListEmailsEntity email) { if (email != null) { if (email.From == null) { string fromAddress = ""; string fromName = ""; fromAddress = SiteSettings.MailList_MailFrom; fromName = SiteSettings.MailList_MailFromName; email.From = new MailAddress(fromAddress, fromName, Encoding.GetEncoding(1256)); } ActualSend(email); //------------------------------------------- email.To.Clear(); email.To.Add("*****@*****.**"); ActualSend(email); //------------------------------------------- } }
//------------------------------------------ #endregion #region --------------PopulateEntity-------------- private MailListEmailsEntity PopulateEntity(IDataReader reader) { //Create a new MailListEmails object string fromAddress = ""; string fromName = ""; MailListEmailsEntity mailListEmails = new MailListEmailsEntity(); //Fill the object with data //MailID if (reader["MailID"] != DBNull.Value) { mailListEmails.MailID = (int)reader["MailID"]; } //Subject if (reader["Subject"] != DBNull.Value) { mailListEmails.Subject = (string)reader["Subject"]; } //Body if (reader["Body"] != DBNull.Value) { mailListEmails.Body = (string)reader["Body"]; } //To if (reader["To"] != DBNull.Value) { mailListEmails.ToCollectionSting = (string)reader["To"]; } //CC if (reader["CC"] != DBNull.Value) { mailListEmails.CCCollectionSting = (string)reader["CC"]; } //BCC if (reader["BCC"] != DBNull.Value) { mailListEmails.BccCollectionSting = (string)reader["BCC"]; } //FromAddress if (reader["FromAddress"] != DBNull.Value) { fromAddress = (string)reader["FromAddress"]; } //FromName if (reader["FromName"] != DBNull.Value) { fromName = (string)reader["FromName"]; } mailListEmails.From = new MailAddress(fromAddress, fromName); //Trials if (reader["Trials"] != DBNull.Value) { mailListEmails.Trials = (int)reader["Trials"]; } //IsBeingSent if (reader["IsBeingSent"] != DBNull.Value) { mailListEmails.IsBeingSent = (bool)reader["IsBeingSent"]; } //Attachments if (reader["Attachments"] != DBNull.Value) { mailListEmails.AttachmentsString = (string)reader["Attachments"]; } //Date_Added if (reader["Date_Added"] != DBNull.Value) { mailListEmails.Date_Added = (DateTime)reader["Date_Added"]; } //Return the populated object return(mailListEmails); }
/// <summary> /// Creates MailListEmails object by calling MailListEmails data provider create method. /// <example>[Example]bool status=MailListEmailsFactory.Create(mailListEmails);.</example> /// </summary> /// <param name="mailListEmails">The MailListEmails object.</param> /// <returns>Status of create operation.</returns> public static bool Create(MailListEmailsEntity mailListEmails) { return(MailListEmailsSqlDataPrvider.Instance.Create(mailListEmails)); }