Advertisement
Guest User

Untitled

a guest
Aug 20th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. public class ExceptionConverter : IExceptionConverter
  2. {
  3. //need the parameter
  4. public HttpStatusCode Convert(/*need to pass this the repository method*/)
  5. {
  6. try
  7. {
  8. //call the void repository method here
  9. }
  10. catch (Exception exception)
  11. {
  12. if (exception is ObjectNotFoundException)
  13. return HttpStatusCode.NotFound;
  14. if (exception is InvalidOperationException)
  15. return HttpStatusCode.BadRequest;
  16. }
  17. return HttpStatusCode.OK;
  18. }
  19. }
  20.  
  21. public interface IHandleCrudOperations
  22. {
  23. //All of these methods need to be able to take in many different parameters
  24. //They will always need a parameter though
  25. void Remove();
  26. void Add();
  27. void Edit();
  28. void Clone();
  29. }
  30.  
  31. //userRepository
  32. public void Remove(int userKey)
  33. public void Add(User user)
  34. public void Edit(User user)
  35. public void Clone(CloneUserRequest)
  36.  
  37. //groupRepository
  38. public void Remove(string groupName)
  39. public void Add(string groupName)
  40. public void Edit(EditGroupRequest)
  41. public void Clone(CloneGroupRequest)
  42.  
  43. public interface IHandleCrudOperations
  44. {
  45. //All of these methods need to be able to take in many different parameters
  46. //They will always need a parameter though
  47. void Remove<T>(T item);
  48. void Add<T>(T item);
  49. void Edit<T>(T item);
  50. void Clone<T>(T item);
  51. }
  52.  
  53. //userRepository
  54. public void Remove<T>(T item)
  55. {
  56. //SERIOUS code smell here
  57. var userKey = (int)(object)item
  58. //stuff
  59. }
  60.  
  61. //groupRepository
  62. public void Remove<T>(T item)
  63. {
  64. //SERIOUS code smell here
  65. var groupName = (string)(object)item
  66. //stuff
  67. }
  68.  
  69. public interface IHandleCrudOperations<TRemove, TAdd, TEdit, TClone>
  70. {
  71. void Remove(TKey item);
  72. void Add(TAdd item);
  73. void Edit(TEdit item);
  74. void Clone(TClone item);
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement