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.Text.Json; using System.Threading.Tasks; using wispro.sp.entity; using wispro.sp.share; using wispro.sp.web.Auth; using wispro.sp.web.Models; 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> GetUserAppeals(int? userid) { var data = await _httpClient.GetFromJsonAsync>($"http://localhost:39476/api/Appeal/GetAppealRecords?userId={userid}"); return data; } 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; } public async Task CreateAppeal(CreateAppealModel model) { List attachFiles = new List(); foreach (var file in model.FileList) { AttachFile atfile = new AttachFile(); var result = file.GetResponse>(); atfile.Id = result[0].Id; attachFiles.Add(atfile); } string strUrl = $"http://localhost:39476/api/Appeal/CreateAppeal?ItemId={model.Item.Id}&typeid={model.AppealType.Id}&reviewerId={model.AppealRecord.ReviewerId}"; AppealObject appealObject = new AppealObject(); appealObject.attachFiles = attachFiles; appealObject.inputFieldValues = model.inputFieldValues; foreach(var fValue in appealObject.inputFieldValues) { fValue.InputField = null; } var data = await _httpClient.PostAsJsonAsync(strUrl, appealObject); Console.WriteLine(JsonSerializer.Serialize(data)); } } }