Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. public int Create(ICNUser item)
  2. {
  3. return this._repository.Create(item);
  4. }
  5. public void Update(ICNUser item)
  6. {
  7. this._repository.Create(item);
  8. }
  9.  
  10. public IGenericActionResponse<ICNUser> Create(ICNUser item)
  11. {
  12. return this._repository.Create(item);
  13. }
  14.  
  15. public IGenericActionResponse Update(ICNUser item)
  16. {
  17. return this._repository.Update(item);
  18. }
  19.  
  20. namespace Web.ActionResponses
  21. {
  22.  
  23.  
  24.  
  25. public enum ActionResponseCode
  26. {
  27. Success,
  28. RecordNotFound,
  29. InvalidCreateHash,
  30. ExpiredCreateHash,
  31. ExpiredModifyHash,
  32. UnableToCreateRecord,
  33. UnableToUpdateRecord,
  34. UnableToSoftDeleteRecord,
  35. UnableToHardDeleteRecord,
  36. UserAlreadyExists,
  37. EmailCannotBeBlank,
  38. PasswordCannotBeBlank,
  39. PasswordResetHashExpired,
  40. AccountNotActivated,
  41. InvalidEmail,
  42. InvalidPassword,
  43. InvalidPageAction
  44. }
  45.  
  46. public interface IGenericActionResponse
  47. {
  48. bool RequestSuccessful { get; }
  49. ActionResponseCode ResponseCode { get; }
  50. }
  51.  
  52. public interface IGenericActionResponse<T>
  53. {
  54. bool RequestSuccessful { get; }
  55. bool RecordIsNull{get;}
  56. ActionResponseCode ResponseCode { get; }
  57. }
  58. }
  59.  
  60. namespace Web.ActionResponses
  61. {
  62.  
  63. public class GenericActionResponse<T> : IGenericActionResponse<T>
  64. {
  65. private bool _requestSuccessful;
  66. private ActionResponseCode _actionResponseCode;
  67. public T Item { get; set; }
  68. public GenericActionResponse(bool success, ActionResponseCode actionResponseCode, T item)
  69. {
  70. this._requestSuccessful = success;
  71. this._actionResponseCode = actionResponseCode;
  72. this.Item = item;
  73. }
  74.  
  75. public GenericActionResponse(bool success, ActionResponseCode actionResponseCode)
  76. {
  77. this._requestSuccessful = success;
  78. this._actionResponseCode = actionResponseCode;
  79. this.Item = default(T);
  80. }
  81.  
  82. public bool RecordIsNull
  83. {
  84. get
  85. {
  86. return this.Item == null;
  87. }
  88. }
  89.  
  90. public bool RequestSuccessful
  91. {
  92. get
  93. {
  94. return this._requestSuccessful;
  95. }
  96. }
  97.  
  98. public ActionResponseCode ResponseCode
  99. {
  100. get
  101. {
  102. return this._actionResponseCode;
  103. }
  104. }
  105.  
  106. }
  107.  
  108.  
  109.  
  110.  
  111. public class GenericActionResponse : IGenericActionResponse
  112. {
  113. private bool _requestSuccessful;
  114. private ActionResponseCode _actionResponseCode;
  115.  
  116. public GenericActionResponse(bool success, ActionResponseCode actionResponseCode)
  117. {
  118. this._requestSuccessful = success;
  119. this._actionResponseCode = actionResponseCode;
  120.  
  121. }
  122.  
  123. public bool RequestSuccessful
  124. {
  125. get
  126. {
  127. return this._requestSuccessful;
  128. }
  129. }
  130.  
  131. public ActionResponseCode ResponseCode
  132. {
  133. get
  134. {
  135. return this._actionResponseCode;
  136. }
  137. }
  138.  
  139. }}
  140.  
  141. public ActionResult ValidateResetHash(string passwordResetHash)
  142. {
  143. IGenericActionResponse result = (IGenericActionResponse)this._userManager.IsValidPasswordResetHash(passwordResetHash);
  144.  
  145. if (result.RequestSuccessful)
  146. {
  147. Models.PasswordChangeModel model = new Models.PasswordChangeModel();
  148. model.PasswordResetHash = passwordResetHash;
  149. return View("~/Areas/Public/Views/ResetPassword/PasswordChangeForm.cshtml", model);
  150. }
  151. else
  152. {
  153. switch (result.ResponseCode)
  154. {
  155. case ActionResponseCode.RecordNotFound:
  156. {
  157. FermataFish.Models.GenericActionModel responseModel = new FermataFish.Models.GenericActionModel(true, "/Login", "Login", "You have submitted an invalid password reset link.", false);
  158. return View("~/Views/Shared/GenericAction.cshtml", responseModel);
  159. }
  160. case ActionResponseCode.PasswordResetHashExpired:
  161. {
  162. FermataFish.Models.GenericActionModel responseModel = new FermataFish.Models.GenericActionModel(true, "/ResetPassword", "Reset Password", "You have submitted an expired password reset link. You must reset your password again to change it.", false);
  163. return View("~/Views/Shared/GenericAction.cshtml", responseModel);
  164. }
  165. default:
  166. {
  167. FermataFish.Models.GenericActionModel responseModel = new FermataFish.Models.GenericActionModel(true, "/", "Home", "An unknown error has occured. The system administrator has been notified. Error code:" + Enum.GetName(typeof(ActionResponseCode), result.ResponseCode), false);
  168. return View("~/Views/Shared/GenericAction.cshtml", responseModel);
  169. }
  170. }
  171. }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement