using System.ComponentModel;
public static void Main()
foo.ObjectState = ObjectState.Unchanged;
Console.WriteLine(foo.ObjectState);
foo.Division = new Division();
foo.TicketType = new TicketType();
Console.WriteLine(foo.ObjectState);
public enum ObjectState { New, Unchanged, Changed, Deleted };
public abstract class BasicObject : System.Object, INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
PropertyChangedEventHandler handler = PropertyChanged;
handler(this, new PropertyChangedEventArgs(name));
private ObjectState _objectState;
public ObjectState ObjectState
get { return _objectState; }
set { _objectState = value; }
public DateTime UpdateProperty(DateTime oldValue, DateTime newValue)
if (oldValue != newValue && ObjectState != ObjectState.New && ObjectState != ObjectState.Deleted)
ObjectState = ObjectState.Changed;
public bool UpdateProperty(bool oldValue, bool newValue)
if (oldValue != newValue && ObjectState != ObjectState.New && ObjectState != ObjectState.Deleted)
ObjectState = ObjectState.Changed;
public string UpdateProperty(string oldValue, string newValue)
if (oldValue != newValue && ObjectState != ObjectState.New && ObjectState != ObjectState.Deleted)
ObjectState = ObjectState.Changed;
public Division UpdateProperty(Division oldValue, Division newValue)
if (oldValue != newValue && ObjectState != ObjectState.New && ObjectState != ObjectState.Deleted)
ObjectState = ObjectState.Changed;
public TicketType UpdateProperty(TicketType oldValue, TicketType newValue)
if (oldValue != newValue && ObjectState != ObjectState.New && ObjectState != ObjectState.Deleted)
ObjectState = ObjectState.Changed;
public abstract class BusinessObject : BasicObject
private DateTime _dateCreated;
private DateTime _dateLastModified;
private DateTime? _dateDeleted;
public BusinessObject() { SetProperties(); }
private void SetProperties()
_dateCreated = DateTime.Now;
_dateLastModified = DateTime.Now;
public DateTime DateCreated
get { return _dateCreated; }
set { _dateCreated = UpdateProperty(_dateCreated, value); OnPropertyChanged("DateCreated"); }
public DateTime DateLastModified
get { return _dateLastModified; }
set { _dateLastModified = UpdateProperty(_dateLastModified, value); OnPropertyChanged("DateLastModified"); }
get { return _isDeleted; }
set { _isDeleted = UpdateProperty(_isDeleted, value); OnPropertyChanged("IsDeleted"); }
public class Division : BusinessObject
public Division() : base()
private void SetProperties()
public Division(int _divisionId) : base()
set { _name = UpdateProperty(_name, value); OnPropertyChanged("Name"); }
public class TicketType : BusinessObject
public TicketType() : base()
private void SetProperties()
public TicketType(int _ticketTypeId) : base()
set { _name = UpdateProperty(_name, value); OnPropertyChanged("Name"); }
public class Ticket : BusinessObject
private Division _division;
private TicketType _ticketType;
private void SetProperties()
public Ticket(int _ticketId) : base()
get { return _division; }
set { _division = UpdateProperty(_division, value); OnPropertyChanged("Division"); }
public TicketType TicketType
get { return _ticketType; }
set { _ticketType = UpdateProperty(_ticketType, value); OnPropertyChanged("TicketType"); }