PmsCustomApi.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using ProjectManagementSystem.Common.Logger;
  2. using ProjectManagementSystem.Common.Models.Crms;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace ProjectManagementSystem.Common.Service
  9. {
  10. public class PmsCustomApi
  11. {
  12. private static RestApi restApi = new RestApi();
  13. public static WebMgrResponse<T> Get<T>(string apiName, object pars)
  14. {
  15. try
  16. {
  17. string url = Common.Function.AppSetting.GetPmsApiCustomUrl(apiName);
  18. var res = restApi.Get<WebMgrResponse<T>>(url, pars, null, out string content);
  19. //CLog.Instance.SystemLog.WriteDebug($"Get {url}{Environment.NewLine} {JsonConvert.SerializeObject(pars)}{Environment.NewLine} {content}");
  20. return res;
  21. }
  22. catch (Exception ex)
  23. {
  24. CLog.Instance.SystemLog.WriteError(ex.Message);
  25. return new WebMgrResponse<T>() { message = ex.Message };
  26. }
  27. }
  28. public static WebMgrResponse<T> Post<T>(string apiName, object body)
  29. {
  30. try
  31. {
  32. string url = Common.Function.AppSetting.GetPmsApiCustomUrl(apiName);
  33. var res = restApi.Post<WebMgrResponse<T>>(url, null, body, out string content);
  34. //CLog.Instance.SystemLog.WriteDebug($"Post {url}{Environment.NewLine} {JsonConvert.SerializeObject(body)}{Environment.NewLine} {content}");
  35. return res;
  36. }
  37. catch (Exception ex)
  38. {
  39. CLog.Instance.SystemLog.WriteError(ex.Message);
  40. return new WebMgrResponse<T>() { message = ex.Message };
  41. }
  42. }
  43. }
  44. }