Created
April 26, 2016 00:32
-
-
Save ainsofs/67c4e648f6dce005ff6ea88d2a0d23e6 to your computer and use it in GitHub Desktop.
Utility Classes for Creating Web Api Endpoints
This file contains hidden or 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
| interface IWebApiResponse { | |
| bool ApiSuccess { get; set; } | |
| string ApiError { get; set; } | |
| string ApiStackTrace { get; set; } | |
| } |
This file contains hidden or 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 WebApiResponse<T> : IWebApiResponse { | |
| private bool _success; | |
| private string _apiError; | |
| private string _apiStackTrace; | |
| private T _responseValue; | |
| /// <summary> | |
| /// Constructor for successful save | |
| /// </summary> | |
| /// <param name="responseValue">The object or object graph to be returned in the response</param> | |
| public WebApiResponse(T responseValue) { | |
| _responseValue = responseValue; | |
| _success = true; | |
| } | |
| /// <summary> | |
| /// Constructor for failed save | |
| /// </summary> | |
| /// <param name="apiError"></param> | |
| /// <param name="apiStackTrace"></param> | |
| /// <param name="responseValue"></param> | |
| public WebApiResponse(string apiError, string apiStackTrace, T responseValue) { | |
| _success = false; | |
| _apiError = apiError; | |
| _apiStackTrace = apiStackTrace; | |
| _responseValue = responseValue; | |
| } | |
| public T ResponseValue { | |
| get { | |
| return _responseValue; | |
| } | |
| } | |
| #region interface properties | |
| public bool ApiSuccess { | |
| get { | |
| return _success; | |
| } | |
| set { | |
| _success = value; | |
| } | |
| } | |
| public string ApiError { | |
| get { | |
| return _apiError; | |
| } | |
| set { | |
| _apiError = value; | |
| } | |
| } | |
| public string ApiStackTrace { | |
| get { | |
| return _apiStackTrace; | |
| } | |
| set { | |
| _apiStackTrace = value; | |
| } | |
| } | |
| #endregion | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment