StaffGradeService.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Microsoft.AspNetCore.Components.Authorization;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net.Http;
  6. using System.Net.Http.Json;
  7. using System.Threading.Tasks;
  8. using wispro.sp.entity;
  9. using wispro.sp.share;
  10. using wispro.sp.web.Auth;
  11. using static System.Net.WebRequestMethods;
  12. namespace wispro.sp.web.Services
  13. {
  14. public class StaffGradeService
  15. {
  16. private readonly IHttpService _httpClient;
  17. private readonly JwtAuthenticationStateProvider _jwt;
  18. public StaffGradeService(IHttpService httpClient, AuthenticationStateProvider jwt)
  19. {
  20. _httpClient = httpClient;
  21. _jwt = (JwtAuthenticationStateProvider)jwt;
  22. }
  23. public async Task<List<StaffGrade>> GetAll()
  24. {
  25. try
  26. {
  27. var _StaffGrade = await _httpClient.Get<List<StaffGrade>>($"StaffGrade/GetAll");
  28. return _StaffGrade;
  29. }
  30. catch(Exception ex)
  31. {
  32. if (ex.Message.Contains("Unauthorized"))
  33. {
  34. _jwt.NotifyUserLogOut();
  35. }
  36. return null;
  37. }
  38. }
  39. public async Task<ApiSaveResponse> Save(StaffGrade staffGrade)
  40. {
  41. try
  42. {
  43. var data = await _httpClient.Post<ApiSaveResponse>($"StaffGrade/Save", staffGrade);
  44. return data;
  45. }
  46. catch(Exception ex)
  47. {
  48. return new ApiSaveResponse() { Success = false, ErrorMessage = $"请求发生错误!\r\n {ex.Message}" };
  49. }
  50. }
  51. }
  52. }