Last active
May 4, 2020 02:43
-
-
Save ZhenDeng/50dcb2a7fead7a63dd9e2a144c5b90a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TerminateCourseService : ITerminateCourseService | |
{ | |
public IVisaTerminationWorkflowService _visaTerminationWorkflow { get; set; } | |
public TerminateCourseService() | |
{ | |
} | |
public ITerminationWorkflowService GetTerminationWorkflow(TerminationReason terminationReason) // because IVisaTerminationWorkflowService inherit from ITerminationWorkflowService | |
{ | |
ITerminationWorkflowService terminationWorkflow = null; | |
switch (terminationReason) | |
{ | |
case TerminationReason.VisaCategory: | |
case TerminationReason.VisaRenewal: | |
terminationWorkflow = _visaTerminationWorkflow; | |
break; | |
} | |
return terminationWorkflow; | |
} | |
public async Task<ServiceResponse<bool>> UpdateVevoStatusWorktray(TerminationReason terminationReason) | |
{ | |
Func<Task<bool>> func = async delegate | |
{ | |
var terminationWorkflow = GetTerminationWorkflow(terminationReason); | |
//Trigger the related workflow terminatin process | |
var triggerRequestDataDTO = new TriggerRequestDataDTO() | |
{ | |
//IsOnshore = process.IsOnshore, | |
TerminateCourseProcessId = process.ProcessRequest_Id, | |
TriggerSource = TriggerSource.VevoStatusWorktrayItem, | |
WorktrayItemId = vevoStatusDTO.WorkTrayId | |
}; | |
await terminationWorkflow.Trigger(triggerRequestDataDTO); | |
return true; | |
}; | |
return await ExecuteAsync(func); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
***Parent class | |
public abstract class AbstractTerminationWorkflowService : ITerminationWorkflowService | |
{ | |
protected readonly IProcessRequestStatusChangeService<TerminateCourseProcessRequest> _processRequestStatusChangeService; | |
public Lazy<IServicesExternalApiConnector> _externalServiceConnector { get; set; } | |
public AbstractTerminationWorkflowService(IProcessRequestStatusChangeService<TerminateCourseProcessRequest> processRequestStatusChangeService) | |
{ | |
_processRequestStatusChangeService = processRequestStatusChangeService; | |
} | |
public virtual async Task<bool> Trigger(TriggerRequestDataDTO triggerRequestData) | |
{ | |
throw new NotImplementedException(); | |
} | |
public virtual async Task<DateTime?> GetTriggerDate(ProcessRequest processRequest, CreateTerminateCourseDTO createTerminateCourseDTO) | |
{ | |
throw new NotImplementedException(); | |
} | |
public virtual async Task<bool> TerminateCourseProcessCreated(Guid terminateCourseProcessId) | |
{ | |
throw new NotImplementedException(); | |
} | |
protected async Task AddWorktrayItemToSchool(Guid terminationProcessRequestId, string studentNumber) // this is equal to private method here | |
{ | |
throw new NotImplementedException(); | |
} | |
} | |
***Parent class interface | |
public interface ITerminationWorkflowService | |
{ | |
Task<bool> Trigger(TriggerRequestDataDTO triggerRequestData) | |
Task<DateTime?> GetTriggerDate(ProcessRequest processRequest, CreateTerminateCourseDTO createTerminateCourseDTO); | |
Task<bool> TerminateCourseProcessCreated(Guid terminateCourseProcessId); | |
} | |
***Child class | |
public class VisaTerminationWorkflowService : AbstractTerminationWorkflowService, IVisaTerminationWorkflowService | |
{ | |
public VisaTerminationWorkflowService(IProcessRequestStatusChangeService<TerminateCourseProcessRequest> processRequestStatusChangeService) | |
: base(processRequestStatusChangeService) // inherite service from parent | |
public override async Task<bool> Trigger(TriggerRequestDataDTO triggerRequestData) | |
{ | |
return await base.Trigger(triggerRequestData); | |
} | |
public override async Task<DateTime?> GetTriggerDate(ProcessRequest processRequest, CreateTerminateCourseDTO createTerminateCourseDTO) | |
{ | |
// use same method in parent class declared in parent interface | |
return await base.GetTriggerDate(processRequest, createTerminateCourseDTO); | |
} | |
// use method in the body | |
public override async Task<bool> TerminateCourseProcessCreated(Guid terminateCourseProcessId) | |
{ | |
// can directly use protected method from parent class | |
AddWorktrayItemToSchool(terminationProcessRequestId, studentNumber) | |
var triggerRequestDataDTO = new TriggerRequestDataDTO() | |
{ | |
TerminateCourseProcessId = terminateCourseProcessId, | |
TriggerSource = TriggerSource.Expulsion | |
}; | |
return true | |
} | |
} | |
*** Child class interface | |
public interface IVisaTerminationWorkflowService : ITerminationWorkflowService | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment