123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- 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 IHttpService _httpClient;
- private readonly JwtAuthenticationStateProvider _jwt;
- private List<AppealType> AppealTypes;
- public AppealTypeService(IHttpService httpClient, AuthenticationStateProvider jwt)
- {
- _httpClient = httpClient;
- _jwt = (JwtAuthenticationStateProvider)jwt;
-
- }
- public async Task<AppealRecord> getAppealRecord(int appealRecordId)
- {
- var data = await _httpClient.Get<AppealRecord>($"Appeal/GetAppealRecord?Id={appealRecordId}");
- return data;
- }
- public async Task<List<InputFieldValue>> GetInputFieldValues(int id, int state)
- {
- var data = await _httpClient.Get<List<InputFieldValue>>($"Appeal/GetInputFieldValues?Id={id}&state={state}");
- return data;
- }
- public async Task<List<AppealType>> GetItems()
- {
- if (AppealTypes == null)
- {
- AppealTypes = await _httpClient.Get<List<AppealType>>($"Appeal/GetAppealTypes");
-
- }
- return AppealTypes;
- }
- public List<AppealType> GetItems(int Type)
- {
- return AppealTypes.Where<AppealType>(at => at.Type == Type).ToList();
- }
- public List<AppealType> GetItems(PerformanceItem item)
- {
- List<AppealType> retList = new List<AppealType>();
- foreach (var at in GetItems(0))
- {
- if (!string.IsNullOrWhiteSpace(at.CanDoExpress))
- {
- var interpreter = new Interpreter();
- Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(at.CanDoExpress, "p");
- bool result = func.Invoke(item);
-
- if (result)
- {
- retList.Add(at);
- }
- }
- else
- {
- retList.Add(at);
- }
- }
- return retList;
- }
- public async Task<List<AppealRecord>> GetUserAppeals(int? userid)
- {
- var data = await _httpClient.Get<List<AppealRecord>>($"Appeal/GetAppealRecords?userId={userid}");
- return data;
- }
- public async Task<AppealType> GetItem(int appealTypeId)
- {
- if (AppealTypes == null)
- {
- AppealTypes = await _httpClient.Get<List<AppealType>>($"Appeal/GetAppealTypes");
- }
- var retData = AppealTypes.Where<AppealType>(ap => ap.Id == appealTypeId).FirstOrDefault();
- return retData;
- }
- public async Task<List<InputField>> GetInputFields(int appealTypeId,int State)
- {
- var data = await _httpClient.Get<List<InputField>>($"Appeal/GetInputField?appealTypeId={appealTypeId}&state={State}");
- return data;
- }
- public async Task<List<AttachFile>> GetAppealRecordAttachFiles(int appealRecordId)
- {
- var data = await _httpClient.Get<List<AttachFile>>($"Appeal/GetAppealRecordAttachFiles?appealRecordId={appealRecordId}");
- return data;
- }
- public async Task CreateAppeal(CreateAppealModel model)
- {
- List<AttachFile> attachFiles = new List<AttachFile>();
- foreach (var file in model.FileList)
- {
- AttachFile atfile = new AttachFile();
- var result = file.GetResponse<List<AttachFile>>();
- atfile.Id = result[0].Id;
- attachFiles.Add(atfile);
- }
- string strUrl = $"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;
- }
- try
- {
- var data = await _httpClient.Post<ApiSaveResponse>(strUrl, appealObject);
- if (!data.Success)
- {
- if (!data.Success)
- {
- throw new ApplicationException(data.ErrorMessage);
- }
- }
- }
- catch(Exception ex)
- {
- throw ex;
- }
- }
- public async Task ReviewerAppeal(ReviewerAppealModel model)
- {
- string strUrl = $"Appeal/ReviewerAppeal?appealRecordId={model.AppealRecord.Id}";
- AppealObject appealObject = new AppealObject();
- appealObject.inputFieldValues = model.inputFieldValues;
- foreach (var fValue in appealObject.inputFieldValues)
- {
- fValue.InputField = null;
- }
- try
- {
- var data = await _httpClient.Post<ApiSaveResponse>(strUrl, appealObject);
- if (!data.Success)
- {
- throw new ApplicationException(data.ErrorMessage);
- }
-
- }
- catch(Exception ex)
- {
- throw ex;
- }
- //if (!data.IsSuccessStatusCode)
- //{
- // string strContent = await data.Content.ReadAsStringAsync();
- // throw new Exception(strContent);
- //}
- }
-
-
- }
- }
|