public static EmailList Load(Int32 emailListId, bool useCache)
        {
            if (emailListId == 0)
            {
                return(null);
            }
            EmailList emailList = null;
            string    key       = "EmailList_" + emailListId.ToString();

            if (useCache)
            {
                emailList = ContextCache.GetObject(key) as EmailList;
                if (emailList != null)
                {
                    return(emailList);
                }
            }
            emailList = new EmailList();
            if (emailList.Load(emailListId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, emailList);
                }
                return(emailList);
            }
            return(null);
        }
        public static bool Delete(Int32 emailListId)
        {
            EmailList emailList = new EmailList();

            if (emailList.Load(emailListId))
            {
                return(emailList.Delete());
            }
            return(false);
        }
 /// <summary>
 /// Loads the given EmailList object from the given database data reader.
 /// </summary>
 /// <param name="emailList">The EmailList object to load.</param>
 /// <param name="dr">The database data reader to read data from.</param>
 public static void LoadDataReader(EmailList emailList, IDataReader dr)
 {
     //SET FIELDS FROM ROW DATA
     emailList.EmailListId           = dr.GetInt32(0);
     emailList.StoreId               = dr.GetInt32(1);
     emailList.Name                  = dr.GetString(2);
     emailList.Description           = NullableData.GetString(dr, 3);
     emailList.IsPublic              = dr.GetBoolean(4);
     emailList.SignupRuleId          = dr.GetInt16(5);
     emailList.SignupEmailTemplateId = NullableData.GetInt32(dr, 6);
     emailList.LastSendDate          = LocaleHelper.ToLocalTime(NullableData.GetDateTime(dr, 7));
     emailList.IsDirty               = false;
 }
        public static EmailListCollection LoadForStore(int maximumRows, int startRowIndex, string sortExpression)
        {
            int storeId = Token.Instance.StoreId;
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT");
            if (maximumRows > 0)
            {
                selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString());
            }
            selectQuery.Append(" " + EmailList.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_EmailLists");
            selectQuery.Append(" WHERE StoreId = @storeId");
            if (!string.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, storeId);
            //EXECUTE THE COMMAND
            EmailListCollection results = new EmailListCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        EmailList emailList = new EmailList();
                        EmailList.LoadDataReader(emailList, dr);
                        results.Add(emailList);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
示例#5
0
        public static EmailListCollection LoadForEmail(string email, int maximumRows, int startRowIndex, string sortExpression)
        {
            string        loweredEmail = email.ToLowerInvariant();
            StringBuilder selectQuery  = new StringBuilder();

            selectQuery.Append("SELECT DISTINCT");
            if (maximumRows > 0)
            {
                selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString());
            }
            selectQuery.Append(" " + EmailList.GetColumnNames("EL"));
            selectQuery.Append(" FROM ac_EmailListUsers ELU, ac_EmailLists EL");
            selectQuery.Append(" WHERE ELU.EmailListId = EL.EmailListId");
            selectQuery.Append(" AND ELU.Email = @email");
            if (!string.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@email", System.Data.DbType.String, loweredEmail);
            //EXECUTE THE COMMAND
            EmailListCollection results = new EmailListCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        EmailList emailList = new EmailList();
                        EmailList.LoadDataReader(emailList, dr);
                        results.Add(emailList);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
 public static SaveResult Insert(EmailList emailList)
 {
     return(emailList.Save());
 }
 public static SaveResult Update(EmailList emailList)
 {
     return(emailList.Save());
 }
 public static bool Delete(EmailList emailList)
 {
     return(emailList.Delete());
 }