Esempio n. 1
0
        /// <summary>
        /// Update the alert message
        /// </summary>
        public MailMessage Update(MailMessage data, TransactionMode mode, IPrincipal authContext = null)
        {
            var conn = this.CreateConnection();

            try
            {
                using (conn.LockConnection())
                {
                    if (!data.Key.HasValue)
                    {
                        throw new ArgumentException("Update object must have a key");
                    }

                    var dbData = new DbMailMessage(data);

                    // Create table if not exists
                    if (!conn.Connection.TableMappings.Any(o => o.MappedType == typeof(DbMailMessage)))
                    {
                        conn.Connection.CreateTable <DbMailMessage>();
                    }
                    conn.Connection.Update(dbData);

                    return(data);
                }
            }
            catch (Exception e)
            {
                this.m_tracer.TraceError("Error updating alert message: {0}", e);
                throw;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Insert the specified object
        /// </summary>
        public MailMessage Insert(MailMessage data, TransactionMode mode, IPrincipal authContext)
        {
            var conn = this.CreateConnection();

            try
            {
                using (conn.LockConnection())
                {
                    if (!data.Key.HasValue)
                    {
                        data.Key = Guid.NewGuid();
                    }

                    // Insert into each rcpt
                    foreach (var itm in data.RcptToXml.Distinct())
                    {
                        var dbData = new DbMailMessage(data);

                        // Route to proper RCPT TO
                        dbData.Recipient = itm.ToByteArray();

                        if (String.IsNullOrEmpty(dbData.CreatedBy))
                        {
                            dbData.CreatedBy = authContext?.Identity.Name ?? AuthenticationContext.Current.Principal?.Identity?.Name;
                        }

                        // Create table if not exists
                        if (!conn.Connection.TableMappings.Any(o => o.MappedType == typeof(DbMailMessage)))
                        {
                            conn.Connection.CreateTable <DbMailMessage>();
                        }

                        conn.Connection.Insert(dbData);
                    }
                    return(data);
                }
            }
            catch (Exception e)
            {
                this.m_tracer.TraceError("Error inserting alert message: {0}", e);
                throw;
            }
        }