Skip to content

Instantly share code, notes, and snippets.

@vbilopav
Last active September 1, 2015 12:36
Show Gist options
  • Save vbilopav/cfbd50c1bb846c6da4ea to your computer and use it in GitHub Desktop.
Save vbilopav/cfbd50c1bb846c6da4ea to your computer and use it in GitHub Desktop.
[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