internal static void Enable(this NHibernate.ISession session, IActiveDataItem item) { if (session == null) { throw new ArgumentNullException("session"); } if (item == null) { throw new ArgumentNullException("item"); } string tableName = item.TableName(); if (!_allowed.Contains(tableName)) { throw new ArgumentException("TableName is invalid.", "tableName"); } int record = item.Record(); if (record == 0) { throw new ArgumentException("Record cannot be zero. If this is a new object it should be saved first.", "record"); } item.Active = true; session.Update(item); var alog = session.Query <ActiveLog>().FirstOrDefault(x => x.TableName == tableName && x.Record == record && x.DisableDate == null); // if an ActiveLog with null DisableDate already exists then there is no reason to create a new one or do anything else if (alog == null) { session.Save(new ActiveLog { DisableDate = null, EnableDate = DateTime.Now.Date, Record = record, TableName = tableName }); } }
internal static void Disable(this NHibernate.ISession session, IActiveDataItem item) { if (session == null) { throw new ArgumentNullException("session"); } if (item == null) { throw new ArgumentNullException("item"); } string tableName = item.TableName(); if (!_allowed.Contains(tableName)) { throw new ArgumentException("TableName is invalid.", "tableName"); } int record = item.Record(); if (record == 0) { throw new ArgumentException("Record cannot be zero. If this is a new object it should be saved first.", "record"); } item.Active = false; session.Update(item); var alog = session.Query <ActiveLog>().FirstOrDefault(x => x.TableName == tableName && x.Record == record && x.DisableDate == null); if (alog != null) { alog.DisableDate = DateTime.Now.Date.AddDays(1); session.Update(alog); } }