public void Execute() { Employee e = PayrollDatabase.GetUnionMember(memberId); if (e != null) { UnionAffiliation ua = null; if (e.Affiliation is UnionAffiliation) { ua = e.Affiliation as UnionAffiliation; } if (ua != null) { ua.AddServiceCharge(memberId, new ServiceCharge(time, charge)); } else { throw new InvalidOperationException("Tries to add service charge to union member without a union affiliation"); } } else { throw new InvalidOperationException("No such union member."); } }
protected override void RecordMembership(Employee e) { Affiliation affiliation = e.Affiliation; if (affiliation is UnionAffiliation) { UnionAffiliation unionAffiliation = affiliation as UnionAffiliation; int memberId = unionAffiliation.MemberId; PayrollDatabase.RemoveUnionMember(memberId); } e.Affiliation = Affiliation; }