ResultDataDto.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace ProductionLineMonitor.Core.Dtos
  5. {
  6. public enum CodeEnum
  7. {
  8. Success,
  9. Fail,
  10. Error
  11. }
  12. public class ResultDto
  13. {
  14. public CodeEnum Code { get; set; }
  15. public string Message { get; set; }
  16. public ResultDto(CodeEnum code, string message)
  17. {
  18. Code = code;
  19. Message = message;
  20. }
  21. public static ResultDto Success()
  22. {
  23. return new ResultDto(CodeEnum.Success, "执行成功!");
  24. }
  25. public static ResultDto Fail(string message)
  26. {
  27. return new ResultDto(CodeEnum.Fail, message);
  28. }
  29. public static ResultDto Error()
  30. {
  31. return new ResultDto(CodeEnum.Error, "程序内部错误,请联系管理员!");
  32. }
  33. public static ResultDto Error(string message)
  34. {
  35. return new ResultDto(CodeEnum.Error, message);
  36. }
  37. }
  38. public class ResultDto<T> : ResultDto where T : class
  39. {
  40. public ResultDto(CodeEnum code, string message)
  41. : base(code, message)
  42. {
  43. }
  44. public T Data { get; set; }
  45. public ResultDto(CodeEnum code, string message, T data)
  46. : base(code, message)
  47. {
  48. Code = code;
  49. Message = message;
  50. Data = data;
  51. }
  52. public static ResultDto<T> Success(T data)
  53. {
  54. return new ResultDto<T>(CodeEnum.Success, "执行成功!", data);
  55. }
  56. public static new ResultDto<T> Fail(string message)
  57. {
  58. return new ResultDto<T>(CodeEnum.Fail, message);
  59. }
  60. }
  61. }