static public void Save(DealerMailingList objDealerMailingList, Database db, DbTransaction trans, bool CommitTrans)
 {
     try
     {
         if (objDealerMailingList.IsModified == true)
         {
             if (objDealerMailingList.ID == 0)
             {
                 Insert(objDealerMailingList, db, trans);
             }
             else
             {
                 Update(objDealerMailingList, db, trans);
             }
         }
         if (CommitTrans == true)
         {
             trans.Commit();
         }
     }
     catch (Exception e)
     {
         if (CommitTrans == true)
         {
             //we were hoping to commit the transaction which means we're at the end so
             //Roll back the transaction. Otherwise just rethrow the error and let the next
             //higher level catch it and rollback
             trans.Rollback();
         }
         //and then rethrow the error
         throw (e);
     }
 }
        static public void Delete(DealerMailingList objDealerMailingList)
        {
            Database db = DatabaseFactory.CreateDatabase("BRGCaseMail");

            System.Data.Common.DbCommand dbCommand = db.GetStoredProcCommand("p_DealerMailingListDelete");
            db.AddInParameter(dbCommand, "ID", DbType.Int32, objDealerMailingList.ID);
            db.ExecuteNonQuery(dbCommand);
        }
 static private void LoadDealerMailingList(DealerMailingList objDealerMailingList, IDataReader _reader)
 {
     if (_reader.IsDBNull(0) != true)
     {
         objDealerMailingList.ID = _reader.GetInt32(0);
     }
     if (_reader.IsDBNull(1) != true)
     {
         objDealerMailingList.DealerID = _reader.GetInt32(1);
     }
     if (_reader.IsDBNull(2) != true)
     {
         objDealerMailingList.CreationDate = _reader.GetDateTime(2);
     }
     if (_reader.IsDBNull(3) != true)
     {
         objDealerMailingList.StartFilterDate = _reader.GetDateTime(3);
     }
     if (_reader.IsDBNull(4) != true)
     {
         objDealerMailingList.EndFilterDate = _reader.GetDateTime(4);
     }
     if (_reader.IsDBNull(5) != true)
     {
         objDealerMailingList.FiledCasesOnly = _reader.GetBoolean(5);
     }
     if (_reader.IsDBNull(6) != true)
     {
         objDealerMailingList.NumberCases = _reader.GetInt32(6);
     }
     if (_reader.IsDBNull(7) != true)
     {
         objDealerMailingList.MarkedAsSold = _reader.GetBoolean(7);
     }
     if (_reader.IsDBNull(8) != true)
     {
         objDealerMailingList.Description = _reader.GetString(8);
     }
     if (_reader.IsDBNull(9) != true)
     {
         objDealerMailingList.TemplateFilePath = _reader.GetString(9);
     }
     if (_reader.IsDBNull(10) != true)
     {
         objDealerMailingList.CsvFilePath = _reader.GetString(10);
     }
     if (_reader.IsDBNull(11) != true)
     {
         objDealerMailingList.MailMergeFilePath = _reader.GetString(11);
     }
     if (_reader.IsDBNull(12) != true)
     {
         objDealerMailingList.TrackingLetterRecieved = _reader.GetBoolean(12);
     }
 }
 static public void Save(DealerMailingList objDealerMailingList)
 {
     if (objDealerMailingList.IsModified == true)
     {
         if (objDealerMailingList.ID == 0)
         {
             Insert(objDealerMailingList);
         }
         else
         {
             Update(objDealerMailingList);
         }
     }
 }
        static private void Insert(DealerMailingList objDealerMailingList)
        {
            Database db = DatabaseFactory.CreateDatabase("BRGCaseMail");

            System.Data.Common.DbCommand dbCommand = db.GetStoredProcCommand("p_DealerMailingListInsert");
            db.AddOutParameter(dbCommand, "ID", DbType.Int32, 4);
            if (objDealerMailingList.DealerID > 0)
            {
                db.AddInParameter(dbCommand, "DealerID", DbType.Int32, objDealerMailingList.DealerID);
            }
            else
            {
                db.AddInParameter(dbCommand, "DealerID", DbType.Int32, Convert.DBNull);
            }
            if (objDealerMailingList.CreationDate > DateTime.MinValue)
            {
                db.AddInParameter(dbCommand, "CreationDate", DbType.DateTime, objDealerMailingList.CreationDate);
            }
            else
            {
                db.AddInParameter(dbCommand, "CreationDate", DbType.DateTime, Convert.DBNull);
            }
            if (objDealerMailingList.StartFilterDate > DateTime.MinValue)
            {
                db.AddInParameter(dbCommand, "StartFilterDate", DbType.DateTime, objDealerMailingList.StartFilterDate);
            }
            else
            {
                db.AddInParameter(dbCommand, "StartFilterDate", DbType.DateTime, Convert.DBNull);
            }
            if (objDealerMailingList.EndFilterDate > DateTime.MinValue)
            {
                db.AddInParameter(dbCommand, "EndFilterDate", DbType.DateTime, objDealerMailingList.EndFilterDate);
            }
            else
            {
                db.AddInParameter(dbCommand, "EndFilterDate", DbType.DateTime, Convert.DBNull);
            }
            db.AddInParameter(dbCommand, "FiledCasesOnly", DbType.Boolean, objDealerMailingList.FiledCasesOnly);
            db.AddInParameter(dbCommand, "NumberCases", DbType.Int32, objDealerMailingList.NumberCases);
            db.AddInParameter(dbCommand, "MarkedAsSold", DbType.Boolean, objDealerMailingList.MarkedAsSold);
            db.AddInParameter(dbCommand, "Description", DbType.String, objDealerMailingList.Description);
            db.AddInParameter(dbCommand, "TemplateFilePath", DbType.String, objDealerMailingList.TemplateFilePath);
            db.AddInParameter(dbCommand, "CsvFilePath", DbType.String, objDealerMailingList.CsvFilePath);
            db.AddInParameter(dbCommand, "MailMergeFilePath", DbType.String, objDealerMailingList.MailMergeFilePath);
            db.AddInParameter(dbCommand, "TrackingLetterRecieved", DbType.Boolean, objDealerMailingList.TrackingLetterRecieved);
            db.ExecuteNonQuery(dbCommand);
            objDealerMailingList.ID = Int32.Parse(db.GetParameterValue(dbCommand, "ID").ToString());
        }
        public DealerMailingList Copy()
        {
            DealerMailingList _dealerMailingList = new DealerMailingList();

            _dealerMailingList.ID                = _iD;
            _dealerMailingList.DealerID          = _dealerID;
            _dealerMailingList.CreationDate      = _creationDate;
            _dealerMailingList.StartFilterDate   = _startFilterDate;
            _dealerMailingList.EndFilterDate     = _endFilterDate;
            _dealerMailingList.FiledCasesOnly    = _filedCasesOnly;
            _dealerMailingList.NumberCases       = _numberCases;
            _dealerMailingList.MarkedAsSold      = _markedAsSold;
            _dealerMailingList.Description       = _description;
            _dealerMailingList.TemplateFilePath  = _templateFilePath;
            _dealerMailingList.CsvFilePath       = _csvFilePath;
            _dealerMailingList.MailMergeFilePath = _mailMergeFilePath;
            return(_dealerMailingList);
        }
        static public List <DealerMailingList> GetAll()
        {
            List <DealerMailingList> objDealerMailingLists = new List <DealerMailingList>();
            Database db = DatabaseFactory.CreateDatabase("BRGCaseMail");

            using (IDataReader reader = db.ExecuteReader(CommandType.Text, _selectViewSQL))
            {
                while (reader.Read())
                {
                    DealerMailingList objDealerMailingList = new DealerMailingList();
                    LoadDealerMailingList(objDealerMailingList, reader);
                    objDealerMailingList.IsModified = false;
                    objDealerMailingLists.Add(objDealerMailingList);
                }
                // always call Close when done reading.
                reader.Close();
                return(objDealerMailingLists);
            }
        }
        static public DealerMailingList GetByID(int ID)
        {
            DealerMailingList objDealerMailingList = new DealerMailingList();
            string            query = _selectViewSQL + " where ID = " + ID;
            Database          db    = DatabaseFactory.CreateDatabase("BRGCaseMail");

            using (IDataReader reader = db.ExecuteReader(CommandType.Text, query))
            {
                if (reader.Read())
                {
                    LoadDealerMailingList(objDealerMailingList, reader);
                    // always call Close when done reading.
                    reader.Close();
                    objDealerMailingList.IsModified = false;
                    return(objDealerMailingList);
                }
                else
                {
                    return(null);
                }
            }
        }
 public MailMergeHelper(Dealer dealer, DealerMailingList dealerMailingList)
 {
     _dealer            = dealer;
     _dealerMailingList = dealerMailingList;
 }