ExecutionResult.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Newtonsoft.Json;
  2. namespace OrBit.MesFileServiceNode.Host.Model
  3. {
  4. public enum ExecutionState
  5. {
  6. /// <summary>
  7. /// 返回错误信息
  8. /// </summary>
  9. FAIL = -1,
  10. /// <summary>
  11. /// 请求成功,返回新数据
  12. /// </summary>
  13. SUCCESS = 1,
  14. }
  15. public class ExecutionResult
  16. {
  17. public ExecutionState code { get; set; }
  18. public string message { get; set; }
  19. public object details { get; set; }
  20. public object data { get; set; }
  21. public string validationErrors { get; set; }
  22. public ExecutionResult()
  23. {
  24. code = ExecutionState.FAIL;
  25. }
  26. public ExecutionResult(ExecutionState _State, string _Message, object _Value = null, dynamic _Result = null)
  27. {
  28. code = _State;
  29. message = _Message;
  30. details = _Result;
  31. data = _Value;
  32. }
  33. public static ExecutionResult Success(string msg = "", object data = null, object details = null)
  34. {
  35. return new ExecutionResult(ExecutionState.SUCCESS, msg, data, details);
  36. }
  37. public static ExecutionResult Failed(string msg = "")
  38. {
  39. return new ExecutionResult(ExecutionState.FAIL, msg);
  40. }
  41. public string ToJson()
  42. {
  43. return JsonConvert.SerializeObject(this);
  44. }
  45. }
  46. }