Index: ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/implementations/Employee.vb
===================================================================
diff -u -r1726 -r1730
--- ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/implementations/Employee.vb (.../Employee.vb) (revision 1726)
+++ ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/implementations/Employee.vb (.../Employee.vb) (revision 1730)
@@ -20,4 +20,7 @@
Return employee.Initials.Equals(Initials, StringComparison.CurrentCultureIgnoreCase)
End Function
+ Public overrides Function ToString() As String Implements IEmployee.ToString
+ Return $"Employee: {FirstName} {LastName} ({Initials})"
+ End Function
End Class
Index: ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/implementations/activity state/ActivityFinishedState.vb
===================================================================
diff -u
--- ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/implementations/activity state/ActivityFinishedState.vb (revision 0)
+++ ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/implementations/activity state/ActivityFinishedState.vb (revision 1730)
@@ -0,0 +1,24 @@
+Imports ActiviteitenOpvolging
+
+Public Class ActivityFinishedState
+ Inherits ActivityState
+
+ Private ReadOnly _employee As IEmployee
+
+ 'Not from other state.
+ Public Sub New(activity As IActivity, employee As IEmployee)
+ Me.Activity = activity
+ _employee = employee
+ End Sub
+
+ 'From other state.
+ Public Sub New(state As ActivityState)
+ Activity = state.Activity
+ _employee = state.GetEmployee()
+ End Sub
+
+ '''
+ Public Overrides Function ActivityStateEnum() As ActivityStateEnum
+ Return ActiviteitenOpvolging.ActivityStateEnum.Finished
+ End Function
+End Class
Index: ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/implementations/activity state/ActivityStartedState.vb
===================================================================
diff -u -r1729 -r1730
--- ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/implementations/activity state/ActivityStartedState.vb (.../ActivityStartedState.vb) (revision 1729)
+++ ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/implementations/activity state/ActivityStartedState.vb (.../ActivityStartedState.vb) (revision 1730)
@@ -1,5 +1,5 @@
Public Class ActivityStartedState
- inherits ActivityState
+ Inherits ActivityState
Private ReadOnly _employee As IEmployee
@@ -24,4 +24,22 @@
Public Overrides Function GetEmployee() As IEmployee
Return _employee
End Function
+
+ '''
+ Public Overrides Sub StopActivity(employee As IEmployee)
+ if Not _employee.Equals(employee) Then
+ 'Different employee.
+ throw New Exception($"A different employee can't stop a started activity. Current activity belongs to {employee.ToString()}")
+ End If
+ Activity.State = New ActivityStoppedState(Me)
+ End Sub
+
+ '''
+ Public Overrides Sub FinishActivity(employee As IEmployee)
+ if Not _employee.Equals(employee) Then
+ 'Different employee.
+ throw New Exception($"A different employee can't finish a started activity. Current activity belongs to {employee.ToString()}")
+ End If
+ Activity.State = New ActivityFinishedState(Me)
+ End Sub
End Class
Index: ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/implementations/activity state/ActivityStoppedState.vb
===================================================================
diff -u
--- ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/implementations/activity state/ActivityStoppedState.vb (revision 0)
+++ ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/implementations/activity state/ActivityStoppedState.vb (revision 1730)
@@ -0,0 +1,33 @@
+Public Class ActivityStoppedState
+ inherits ActivityState
+
+ Private ReadOnly _employee As IEmployee
+
+ 'Not from other state.
+ Public Sub New(activity As IActivity, employee As IEmployee)
+ Me.Activity = activity
+ _employee = employee
+ End Sub
+
+ 'From other state.
+ Public Sub New(state As ActivityState)
+ Activity = state.Activity
+ _employee = state.GetEmployee()
+ End Sub
+
+ '''
+ Public Overrides Function ActivityStateEnum() As ActivityStateEnum
+ Return ActiviteitenOpvolging.ActivityStateEnum.Stopped
+ End Function
+
+ '''
+ Public Overrides Function GetEmployee() As IEmployee
+ Return _employee
+ End Function
+
+ '''
+ Public Overrides Sub StartActivity(employee As IEmployee)
+ 'Everyone can start this activity.
+ Activity.State = New ActivityStartedState(Me, employee)
+ End Sub
+End Class
Index: ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/IEmployee.vb
===================================================================
diff -u -r1726 -r1730
--- ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/IEmployee.vb (.../IEmployee.vb) (revision 1726)
+++ ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/IEmployee.vb (.../IEmployee.vb) (revision 1730)
@@ -8,4 +8,5 @@
Property CurrentActivity As IActivity
Function Equals(obj As Object) As Boolean
+ Function ToString() As String
End Interface