AppealTypeService.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using DynamicExpresso;
  2. using Microsoft.AspNetCore.Components.Authorization;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Net.Http;
  7. using System.Net.Http.Json;
  8. using System.Text.Json;
  9. using System.Threading.Tasks;
  10. using wispro.sp.entity;
  11. using wispro.sp.share;
  12. using wispro.sp.web.Auth;
  13. using wispro.sp.web.Models;
  14. namespace wispro.sp.web.Services
  15. {
  16. public class AppealTypeService
  17. {
  18. private readonly HttpClient _httpClient;
  19. private readonly JwtAuthenticationStateProvider _jwt;
  20. private List<AppealType> AppealTypes;
  21. public AppealTypeService(HttpClient httpClient, AuthenticationStateProvider jwt)
  22. {
  23. _httpClient = httpClient;
  24. _jwt = (JwtAuthenticationStateProvider)jwt;
  25. }
  26. public async Task<List<AppealType>> GetItems()
  27. {
  28. if (AppealTypes == null)
  29. {
  30. AppealTypes = await _httpClient.GetFromJsonAsync<List<AppealType>>($"http://localhost:39476/api/Appeal/GetAppealTypes");
  31. }
  32. return AppealTypes;
  33. }
  34. public List<AppealType> GetItems(PerformanceItem item)
  35. {
  36. List<AppealType> retList = new List<AppealType>();
  37. foreach (var at in AppealTypes)
  38. {
  39. if (!string.IsNullOrWhiteSpace(at.CanDoExpress))
  40. {
  41. var interpreter = new Interpreter();
  42. //Console.WriteLine(at.CanDoExpress);
  43. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(at.CanDoExpress, "p");
  44. bool result = func.Invoke(item);
  45. if (result)
  46. {
  47. retList.Add(at);
  48. }
  49. }
  50. else
  51. {
  52. retList.Add(at);
  53. }
  54. }
  55. return retList;
  56. }
  57. public async Task<List<AppealRecord>> GetUserAppeals(int? userid)
  58. {
  59. var data = await _httpClient.GetFromJsonAsync<List<AppealRecord>>($"http://localhost:39476/api/Appeal/GetAppealRecords?userId={userid}");
  60. return data;
  61. }
  62. public async Task<AppealType> GetItem(int appealTypeId)
  63. {
  64. if (AppealTypes == null)
  65. {
  66. AppealTypes = await _httpClient.GetFromJsonAsync<List<AppealType>>($"http://localhost:39476/api/Appeal/GetAppealTypes");
  67. }
  68. var retData = AppealTypes.Where<AppealType>(ap => ap.Id == appealTypeId).FirstOrDefault();
  69. return retData;
  70. }
  71. public async Task<List<InputField>> GetInputFields(int appealTypeId,int State)
  72. {
  73. var data = await _httpClient.GetFromJsonAsync<List<InputField>>($"http://localhost:39476/api/Appeal/GetInputField?appealTypeId={appealTypeId}&state={State}");
  74. return data;
  75. }
  76. public async Task CreateAppeal(CreateAppealModel model)
  77. {
  78. List<AttachFile> attachFiles = new List<AttachFile>();
  79. foreach (var file in model.FileList)
  80. {
  81. AttachFile atfile = new AttachFile();
  82. var result = file.GetResponse<List<AttachFile>>();
  83. atfile.Id = result[0].Id;
  84. attachFiles.Add(atfile);
  85. }
  86. string strUrl = $"http://localhost:39476/api/Appeal/CreateAppeal?ItemId={model.Item.Id}&typeid={model.AppealType.Id}&reviewerId={model.AppealRecord.ReviewerId}";
  87. AppealObject appealObject = new AppealObject();
  88. appealObject.attachFiles = attachFiles;
  89. appealObject.inputFieldValues = model.inputFieldValues;
  90. foreach(var fValue in appealObject.inputFieldValues)
  91. {
  92. fValue.InputField = null;
  93. }
  94. var data = await _httpClient.PostAsJsonAsync<AppealObject>(strUrl, appealObject);
  95. Console.WriteLine(JsonSerializer.Serialize(data));
  96. }
  97. }
  98. }