Skip to content

Instantly share code, notes, and snippets.

@ainsofs
Created April 26, 2016 00:32
Show Gist options
  • Select an option

  • Save ainsofs/67c4e648f6dce005ff6ea88d2a0d23e6 to your computer and use it in GitHub Desktop.

Select an option

Save ainsofs/67c4e648f6dce005ff6ea88d2a0d23e6 to your computer and use it in GitHub Desktop.
Utility Classes for Creating Web Api Endpoints
interface IWebApiResponse {
bool ApiSuccess { get; set; }
string ApiError { get; set; }
string ApiStackTrace { get; set; }
}
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