public static GiftCertificate Load(Int32 giftCertificateId, bool useCache) { if (giftCertificateId == 0) { return(null); } GiftCertificate giftCertificate = null; string key = "GiftCertificate_" + giftCertificateId.ToString(); if (useCache) { giftCertificate = ContextCache.GetObject(key) as GiftCertificate; if (giftCertificate != null) { return(giftCertificate); } } giftCertificate = new GiftCertificate(); if (giftCertificate.Load(giftCertificateId)) { if (useCache) { ContextCache.SetObject(key, giftCertificate); } return(giftCertificate); } return(null); }
public static bool Delete(Int32 giftCertificateId) { GiftCertificate giftCertificate = new GiftCertificate(); if (giftCertificate.Load(giftCertificateId)) { return(giftCertificate.Delete()); } return(false); }
public static GiftCertificateCollection 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(" " + GiftCertificate.GetColumnNames(string.Empty)); selectQuery.Append(" FROM ac_GiftCertificates"); 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 GiftCertificateCollection results = new GiftCertificateCollection(); int thisIndex = 0; int rowCount = 0; using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows))) { if (thisIndex >= startRowIndex) { GiftCertificate giftCertificate = new GiftCertificate(); GiftCertificate.LoadDataReader(giftCertificate, dr); results.Add(giftCertificate); rowCount++; } thisIndex++; } dr.Close(); } return(results); }
private static bool IsUnique(string serialKey) { GiftCertificate gc = GiftCertificateDataSource.LoadForSerialNumber(serialKey); return(gc == null); }
public static SaveResult Insert(GiftCertificate giftCertificate) { return(giftCertificate.Save()); }
public static bool Delete(GiftCertificate giftCertificate) { return(giftCertificate.Delete()); }