Skip to content

Instantly share code, notes, and snippets.

@upnxt
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save upnxt/103791b923843fcecf77 to your computer and use it in GitHub Desktop.
Save upnxt/103791b923843fcecf77 to your computer and use it in GitHub Desktop.
public class EmployeeRecognition : IRecognitionHandler
{
public void Recognize(RecognizeRequest request)
{
if (request.GetType() != typeof(EmployeeRecognizeRequest))
{
throw new HandlerException("No handler available for the given request");
}
//do custom logic to remove points from user
}
}
public class ManagerRecognition : IRecognitionHandler
{
private readonly IRecognitionHandler _nextHandler;
public ManagerRecognition(IRecognitionHandler nextHandler)
{
_nextHandler = nextHandler;
}
public void Recognize(RecognizeRequest request)
{
if (request.GetType() != typeof(ManageRecognizeRequest))
{
_nextHandler.Recognize(request);
return;
}
//do custom logic to charge managers account
}
}
public class RecognitionProvider : IRecognitionProvider
{
private readonly IRecognitionHandler _recognitionHandler;
public RecognitionProvider(IRecognitionHandler recognitionHandler)
{
_recognitionHandler = recognitionHandler;
}
public void Recognize(RecognizeRequest request)
{
_recognitionHandler.Recognize(request);
}
}
public class RecognizeRequest
{
public int CompanyId { get; set; }
public int FromId { get; set; }
public int ToId { get; set; }
public string Message { get; set; }
public decimal Amount { get; set; }
}
public class ManagerRecognizeRequest : RecognizeRequest { }
public class EmployeeRecognizeRequest : RecognizeRequest { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment