ServiceResponse.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Fuel.Infrastructure.Payment.Models
  8. {
  9. public class ServiceResponse
  10. {
  11. public HttpStatusCode StatusCode { get; set; }
  12. public string Message { get; set; }
  13. public object Data { get; set; }
  14. public object Result { get; set; }
  15. private bool Success { get; set; }
  16. public bool IsSuccessful()
  17. {
  18. return StatusCode == HttpStatusCode.OK;
  19. }
  20. public ServiceResponse() { }
  21. public ServiceResponse(HttpStatusCode statusCode, object data, string errorMsg = "")
  22. {
  23. StatusCode = statusCode;
  24. Data = data;
  25. Message = errorMsg;
  26. }
  27. public static ServiceResponse Ok(object data = null)
  28. {
  29. return new ServiceResponse(HttpStatusCode.OK, data);
  30. }
  31. public static ServiceResponse NotFound(string errorMsg = "")
  32. {
  33. return new ServiceResponse(HttpStatusCode.NotFound, null, errorMsg);
  34. }
  35. public static ServiceResponse Unauthorized(string errorMsg = "")
  36. {
  37. return new ServiceResponse(HttpStatusCode.Unauthorized, null, errorMsg);
  38. }
  39. public static ServiceResponse Forbidden(string errorMsg = "")
  40. {
  41. return new ServiceResponse(HttpStatusCode.Forbidden, null, errorMsg);
  42. }
  43. public static ServiceResponse BadRequest(string errorMsg = "")
  44. {
  45. return new ServiceResponse(HttpStatusCode.BadRequest, null, errorMsg);
  46. }
  47. public static ServiceResponse Error(string errorMsg = "")
  48. {
  49. return new ServiceResponse(HttpStatusCode.InternalServerError, null, errorMsg);
  50. }
  51. public static ServiceResponse Error(HttpStatusCode code, string errorMsg = "")
  52. {
  53. return new ServiceResponse(code, null, errorMsg);
  54. }
  55. public static ServiceResponse ValidateFailed(string errorMsg = "")
  56. {
  57. return new ServiceResponse(HttpStatusCode.NotAcceptable, null, errorMsg);
  58. }
  59. }
  60. }