using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using TEAMModelOS.Model.Core; using TEAMModelOS.SDK.Context.Configuration; using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest; using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse; using TEAMModelOS.SDK.Extension.HttpClient.Implements; using TEAMModelOS.SDK.Helper.Common.JsonHelper; using TEAMModelOS.Service.Core.Interfaces; namespace TEAMModelOS.Service.Core.Implements { public class SchoolsService : ISchoolsService { private readonly HttpClientSchool _httpClientSchool; public SchoolsService(HttpClientSchool httpClientSchool) { _httpClientSchool = httpClientSchool; } public async Task> GetSchools(JosnRPCRequest getSchool) { string schoolString = await RequestSchoolInfo(getSchool); if (!string.IsNullOrEmpty(schoolString)) { JosnRPCResponse> response = MessagePackHelper.JsonToObject>>(schoolString); if (response.error == null && response != null) { List schoolInfo = response.result; return schoolInfo; } else return null; } else return null; } private async Task RequestSchoolInfo(JosnRPCRequest getSchool) { string SchoolCodeKey = BaseConfigModel.Configuration["HaBookAuth:SchoolCodeKey"]; Dictionary dict = new Dictionary { { "Authorization", SchoolCodeKey } }; Dictionary codeInfo = new Dictionary { { "countryId", getSchool.@params.CountryId }, { "provinceId", getSchool.@params.ProvinceId }, { "cityId", getSchool.@params.CityId } }; Dictionary data = new Dictionary { { "data", codeInfo } }; JosnRPCRequest> request = new JosnRPCRequest> { @params = data, method = "SchoolCode" }; string postData = MessagePackHelper.ObjectToJson(request); return await _httpClientSchool.HttpPostAsync(BaseConfigModel.Configuration["HaBookAuth:ServiceUrl"], postData); } } }