Last active
September 1, 2015 12:36
-
-
Save vbilopav/cfbd50c1bb846c6da4ea to your computer and use it in GitHub Desktop.
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
[DataContract] | |
public class Response | |
{ | |
[DataMember] | |
public List<ResponseError> Errors { get; set; } | |
[DataMember] | |
public List<string> Warnings { get; set; } | |
[DataMember] | |
public bool Success { get; set; } | |
public Response() { Success = true; } | |
public Response(params string[] errors) | |
{ | |
Success = false; | |
Errors = new List<ResponseError>(); | |
foreach (string s in errors) { Errors.Add(new ResponseError { ErrorMessage = s }); } | |
} | |
public static Response Fail(string msg) | |
{ | |
return new Response | |
{ | |
Success = false, | |
Errors = new List<ResponseError> | |
{ | |
new ResponseError | |
{ | |
ErrorMessage = msg | |
} | |
} | |
}; | |
} | |
public Response<string> ToStringResponse(string value) | |
{ | |
return new Response<string>(value) | |
{ | |
Errors = this.Errors, | |
Success = this.Success, | |
Warnings = this.Warnings | |
}; | |
} | |
} | |
[DataContract] | |
public class Response<T> : Response where T : class | |
{ | |
[DataMember] | |
public T Model { get; set; } | |
public Response() { Success = true; } | |
public Response(T model) : base() { Model = model; } | |
} | |
[DataContract] | |
public class ResponseError | |
{ | |
[DataMember] | |
public object AttemptedValue { get; set; } | |
[DataMember] | |
public string ErrorMessage { get; set; } | |
[DataMember] | |
public string ErrorId { get; set; } | |
[DataMember] | |
public string PropertyName { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment