using DynamicExpresso; using Microsoft.AspNetCore.Components.Authorization; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Net.Http.Json; using System.Threading.Tasks; using wispro.sp.entity; using wispro.sp.share; using wispro.sp.web.Auth; namespace wispro.sp.web.Services { public class AppealTypeService { private readonly HttpClient _httpClient; private readonly JwtAuthenticationStateProvider _jwt; private List AppealTypes; public AppealTypeService(HttpClient httpClient, AuthenticationStateProvider jwt) { _httpClient = httpClient; _jwt = (JwtAuthenticationStateProvider)jwt; } public async Task> GetItems() { if (AppealTypes == null) { AppealTypes = await _httpClient.GetFromJsonAsync>($"http://localhost:39476/api/Appeal/GetAppealTypes"); } return AppealTypes; } public List GetItems(PerformanceItem item) { List retList = new List(); foreach (var at in AppealTypes) { if (!string.IsNullOrWhiteSpace(at.CanDoExpress)) { var interpreter = new Interpreter(); Console.WriteLine(at.CanDoExpress); Func func = interpreter.ParseAsDelegate>(at.CanDoExpress, "p"); bool result = func.Invoke(item); if (result) { retList.Add(at); } } else { retList.Add(at); } } return retList; } public async Task GetItem(int appealTypeId) { if (AppealTypes == null) { AppealTypes = await _httpClient.GetFromJsonAsync>($"http://localhost:39476/api/Appeal/GetAppealTypes"); } var retData = AppealTypes.Where(ap => ap.Id == appealTypeId).FirstOrDefault(); return retData; } public async Task> GetInputFields(int appealTypeId,int State) { var data = await _httpClient.GetFromJsonAsync>($"http://localhost:39476/api/Appeal/GetInputField?appealTypeId={appealTypeId}&state={State}"); return data; } } }