TeacherService.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. using Azure.Cosmos;
  2. using Azure.Storage.Blobs.Models;
  3. using Azure.Storage.Sas;
  4. using Microsoft.AspNetCore.Http;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.Extensions.Options;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Dynamic;
  10. using System.IdentityModel.Tokens.Jwt;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Text.Json;
  14. using System.Threading.Tasks;
  15. using TEAMModelOS.Models;
  16. using TEAMModelOS.SDK.Models;
  17. using TEAMModelOS.SDK.DI;
  18. using TEAMModelOS.SDK.Extension;
  19. using TEAMModelOS.SDK.Filter;
  20. using TEAMModelOS.SDK.Models.Cosmos;
  21. using HTEXLib.COMM.Helpers;
  22. using TEAMModelOS.SDK.Models.Service;
  23. using Microsoft.Extensions.Configuration;
  24. using System.Net.Http;
  25. using TEAMModelOS.SDK;
  26. using static TEAMModelOS.SDK.Models.Teacher;
  27. namespace TEAMModelOS.Services
  28. {
  29. public static class TeacherService
  30. {
  31. public static async Task<TeacherInfo> TeacherInfo(AzureCosmosFactory _azureCosmos, Teacher teacher, string name, string picture, string id, AzureStorageFactory _azureStorage, Option _option)
  32. {
  33. List<object> schools = new List<object>();
  34. List<AreaDto> areas = new List<AreaDto>();
  35. string defaultschool = null;
  36. //TODO 取得Teacher 個人相關數據(課程清單、虛擬教室清單、歷史紀錄清單等),學校數據另外API處理,多校切換時不同
  37. var client = _azureCosmos.GetCosmosClient();
  38. int total = 0;
  39. int tsize = 0;
  40. List<Area> areasDbs = new List<Area>();
  41. List<AreaSetting> areaSettings = new List<AreaSetting>();
  42. try
  43. {
  44. if (teacher == null)
  45. {
  46. teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
  47. teacher.name = $"{name}";
  48. teacher.picture = $"{picture}";
  49. }
  50. else
  51. {
  52. name = teacher.name;
  53. picture = teacher.picture;
  54. id = teacher.id;
  55. }
  56. ///教师的个人空间
  57. tsize = teacher.size;
  58. ///教师的总空间 包含 个人空间和学校赠送的空间累加
  59. total = teacher.size;
  60. HashSet<string> areaIds = new HashSet<string>();
  61. if (teacher.areas.IsNotEmpty())
  62. {
  63. teacher.areas.ForEach(x => {
  64. areaIds.Add(x.areaId);
  65. });
  66. }
  67. if (teacher.schools.IsNotEmpty())
  68. {
  69. teacher.schools.ForEach(x => {
  70. if (!string.IsNullOrEmpty(x.areaId))
  71. {
  72. areaIds.Add(x.areaId);
  73. }
  74. });
  75. }
  76. if (areaIds.Count > 0)
  77. {
  78. string queryText = $"select value(c) from c where c.id in ({string.Join(",", areaIds.Select(x => $"'{x}'"))})";
  79. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: queryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base-Area") }))
  80. {
  81. areasDbs.Add(item);
  82. }
  83. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AreaSetting>(queryText: queryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("AreaSetting") }))
  84. {
  85. areaSettings.Add(item);
  86. }
  87. }
  88. if (teacher.areas.IsNotEmpty())
  89. {
  90. foreach (var areat in teacher.areas)
  91. {
  92. Area area = areasDbs.Find(x => x.id.Equals(areat.areaId));
  93. AreaSetting setting = null;
  94. if (area != null)
  95. {
  96. setting = areaSettings.Find(x => x.id.Equals(areat.areaId));
  97. }
  98. int access = 0;
  99. if (setting != null && !string.IsNullOrWhiteSpace(setting.accessConfig))
  100. {
  101. access = 1;
  102. }
  103. if (setting != null)
  104. {
  105. setting.accessConfig = null;
  106. }
  107. areas.Add(new AreaDto { areaId = area.id, name = area.name, standard = area.standard, standardName = area.standardName, setting = setting, access = access });
  108. }
  109. }
  110. //检查是否有加入学校,如果加入学校,则当个人空间size是0G的时候,则免费获得一个G空间,但无论加入多少个学校,只能获取一次 1G的免费空间。没有加入学校则默认0G空间,除非自己购买空间
  111. if (teacher.schools.IsNotEmpty())
  112. {
  113. foreach (var sc in teacher.schools)
  114. {
  115. string statusNow = sc.status != null ? sc.status : "";
  116. if (statusNow.Equals("join") || statusNow.Equals("invite") || statusNow.Equals("request"))
  117. {
  118. dynamic schoolExtobj = new ExpandoObject();
  119. schoolExtobj.schoolId = sc.schoolId;
  120. schoolExtobj.name = sc.name;
  121. schoolExtobj.status = sc.status;
  122. schoolExtobj.time = sc.time;
  123. schoolExtobj.picture = sc.picture;
  124. schoolExtobj.areaId = $"{sc.areaId}";
  125. Area area = null;
  126. int access = 0;
  127. if (!string.IsNullOrEmpty($"{sc.areaId}"))
  128. {
  129. area = areasDbs.Find(x => x.id.Equals(sc.areaId));
  130. AreaSetting setting = null;
  131. if (area != null)
  132. {
  133. setting = areaSettings.Find(x => x.id.Equals(sc.areaId));
  134. }
  135. if (setting != null && !string.IsNullOrWhiteSpace(setting.accessConfig))
  136. {
  137. access = 1;
  138. }
  139. }
  140. if (area != null)
  141. {
  142. schoolExtobj.area = new { area.name, area.id, area.institution, area.provName, area.code, area.cityCode, area.cityName, area.standard, area.provCode, area.pk, access };
  143. }
  144. else
  145. {
  146. schoolExtobj.area = area;
  147. }
  148. var sctch = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(id, new PartitionKey($"Teacher-{sc.schoolId}"));
  149. if (sctch.Status == 200 && sctch!= null && sctch.ContentStream!=null)
  150. {
  151. var jsonDoc = await JsonDocument.ParseAsync(sctch.ContentStream);
  152. SchoolTeacher schoolTeacher = jsonDoc.RootElement.ToObject<SchoolTeacher>();
  153. if (!schoolTeacher.name.Equals($"{name}") || !schoolTeacher.picture.Equals($"{picture}")) {
  154. schoolTeacher.name = $"{name}";
  155. schoolTeacher.picture = $"{picture}";
  156. await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(schoolTeacher, id, new PartitionKey($"Teacher-{sc.schoolId}"));
  157. }
  158. if (jsonDoc.RootElement.TryGetProperty("size", out JsonElement _size) && _size.ValueKind.Equals(JsonValueKind.Number))
  159. {
  160. total += _size.GetInt32();
  161. schoolExtobj.size = _size.GetInt32();
  162. }
  163. else { schoolExtobj.size = 0; }
  164. }
  165. else
  166. {
  167. schoolExtobj.size = 0;
  168. }
  169. //if (statusNow.Equals("join"))
  170. //{
  171. // await TmdUserService.JoinSchool(client, teacher.id, teacher.picture, teacher.name, sc.schoolId, sc.name);
  172. //}
  173. schools.Add(schoolExtobj);
  174. }
  175. }
  176. //如果包含任何申请,邀请,加入学校的记录 且个人空间未分配2G 则默认分配个人空间至2G.
  177. if (teacher.size < 2 && teacher.schools.Count > 0)
  178. {
  179. teacher.size = 2;
  180. }
  181. //如果未包含任何申请,邀请,加入学校的记录 且 个人空间没有分配1G 则默认赠送一个G
  182. if (teacher.schools.Count == 0 && teacher.size < 1)
  183. {
  184. teacher.size = 1;
  185. }
  186. }
  187. if (string.IsNullOrEmpty(teacher.defaultSchool) && teacher.schools.IsNotEmpty())
  188. {
  189. var tech = teacher.schools.FindAll(x => x.status.Equals("join"));
  190. if (tech.IsNotEmpty())
  191. {
  192. teacher.defaultSchool = teacher.schools[0].schoolId;
  193. }
  194. }
  195. await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, id, new PartitionKey("Base"));
  196. //預設學校ID
  197. defaultschool = teacher.defaultSchool;
  198. }
  199. catch (CosmosException ex)
  200. {
  201. if (ex.Status == 404 && teacher == null)
  202. {
  203. //如果沒有,則初始化Teacher基本資料到Cosmos
  204. teacher = new Teacher
  205. {
  206. id = id,
  207. pk = "Base",
  208. code = "Base",
  209. name = name?.ToString(),
  210. picture = picture?.ToString(),
  211. //创建账号并第一次登录IES5则默认赠送1G
  212. size = 1,
  213. defaultSchool = null,
  214. schools = new List<Teacher.TeacherSchool>(),
  215. };
  216. var container = _azureStorage.GetBlobContainerClient(id);
  217. await container.CreateIfNotExistsAsync(PublicAccessType.None); //嘗試創建Teacher私有容器,如存在則不做任何事,保障容器一定存在
  218. teacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
  219. total = teacher.size;
  220. tsize = teacher.size;
  221. }
  222. }
  223. catch (Exception ex)
  224. {
  225. throw new Exception($"{ex.Message}{ex.StackTrace}");
  226. }
  227. //私人課程
  228. List<object> courses = new List<object>();
  229. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{id}") }))
  230. {
  231. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  232. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  233. {
  234. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  235. {
  236. courses.Add(obj.ToObject<object>());
  237. }
  238. }
  239. }
  240. List<string> roles = new List<string>() { "teacher" };
  241. Area areaa = null;
  242. if (areas.Count > 0)
  243. {
  244. roles.Add("area");
  245. if (!string.IsNullOrEmpty($"{areas[0]}"))
  246. {
  247. areaa = areasDbs.Find(x => x.Equals(areas[0].areaId));
  248. }
  249. }
  250. //換取AuthToken,提供給前端
  251. var auth_token = JwtAuthExtension.CreateAuthToken(_option.HostName, id, name?.ToString(), picture?.ToString(), _option.JwtSecretKey, Website: "IES", scope: Constant.ScopeTeacher, standard: areaa != null ? areaa.standard : "", roles: roles.ToArray());
  252. //取得Teacher Blob 容器位置及SAS
  253. await _azureStorage.GetBlobContainerClient(id).CreateIfNotExistsAsync(PublicAccessType.None); //嘗試創建Teacher私有容器,如存在則不做任何事,保障容器一定存在
  254. var (blob_uri, blob_sas) = _azureStorage.GetBlobContainerSAS(id, BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete);
  255. var (osblob_uri, osblob_sas) = roles.Contains("area") ? _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete) : _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
  256. return new TeacherInfo
  257. {
  258. auth_token = auth_token,
  259. blob_uri = blob_uri,
  260. blob_sas = blob_sas,
  261. schools = schools,
  262. defaultschool = defaultschool,
  263. courses = courses,
  264. total = total,
  265. osblob_sas = osblob_sas,
  266. osblob_uri = osblob_uri,
  267. tsize = tsize,
  268. areas = areas,
  269. teacher = teacher
  270. };
  271. }
  272. public static async Task<TeacherInfo> GetTeacherInfo (AzureCosmosFactory _azureCosmos,Teacher teacher,string name,string picture,string id , AzureStorageFactory _azureStorage, Option _option)
  273. {
  274. List<object> schools = new List<object>();
  275. List<AreaDto> areas = new List<AreaDto>();
  276. List<Area> areasd = new List<Area>();
  277. string defaultschool = null;
  278. //TODO 取得Teacher 個人相關數據(課程清單、虛擬教室清單、歷史紀錄清單等),學校數據另外API處理,多校切換時不同
  279. var client = _azureCosmos.GetCosmosClient();
  280. int total = 0;
  281. int tsize = 0;
  282. try
  283. {
  284. if (teacher == null)
  285. {
  286. teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
  287. teacher.name = $"{name}";
  288. teacher.picture = $"{picture}";
  289. }
  290. else {
  291. name = teacher.name;
  292. picture = teacher.picture;
  293. id = teacher.id;
  294. }
  295. ///教师的个人空间
  296. tsize = teacher.size;
  297. ///教师的总空间 包含 个人空间和学校赠送的空间累加
  298. total = teacher.size;
  299. //areas = teacher.areas;
  300. if (teacher.areas.IsNotEmpty())
  301. {
  302. foreach (var areat in teacher.areas)
  303. {
  304. try
  305. {
  306. Area area = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<Area>($"{areat.areaId}", new PartitionKey("Base-Area"));
  307. areasd.Add(area);
  308. AreaSetting setting= null;
  309. try
  310. {
  311. setting= await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<AreaSetting>($"{areat.areaId}", new PartitionKey("AreaSetting"));
  312. } catch (CosmosException ex) {
  313. setting = null;
  314. }
  315. int access = 0;
  316. if (setting != null && !string.IsNullOrWhiteSpace(setting.accessConfig)) {
  317. access = 1;
  318. }
  319. if (setting != null) {
  320. setting.accessConfig = null;
  321. }
  322. areas.Add(new AreaDto { areaId = area.id, name = area.name,standard= area.standard,standardName= area.standardName,setting=setting, access= access });
  323. }
  324. catch (CosmosException)
  325. {
  326. //数据库捞不到数据
  327. continue;
  328. }
  329. }
  330. }
  331. //检查是否有加入学校,如果加入学校,则当个人空间size是0G的时候,则免费获得一个G空间,但无论加入多少个学校,只能获取一次 1G的免费空间。没有加入学校则默认0G空间,除非自己购买空间
  332. if (teacher.schools.IsNotEmpty())
  333. {
  334. foreach (var sc in teacher.schools)
  335. {
  336. string statusNow = sc.status != null ? sc.status : "";
  337. if (statusNow.Equals("join") || statusNow.Equals("invite") || statusNow.Equals("request"))
  338. {
  339. dynamic schoolExtobj = new ExpandoObject();
  340. // var schoolJson = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{sc.schoolId}", new PartitionKey("Base"));
  341. //var school = await JsonDocument.ParseAsync(schoolJson.ContentStream);
  342. schoolExtobj.schoolId = sc.schoolId;
  343. schoolExtobj.name = sc.name;
  344. schoolExtobj.status = sc.status;
  345. schoolExtobj.time = sc.time;
  346. schoolExtobj.picture = sc.picture;
  347. schoolExtobj.areaId = $"{sc.areaId}";
  348. Area area = null;
  349. int access = 0;
  350. if (!string.IsNullOrEmpty($"{sc.areaId}"))
  351. {
  352. try
  353. {
  354. area = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<Area>($"{sc.areaId}", new PartitionKey("Base-Area"));
  355. AreaSetting setting = null;
  356. try
  357. {
  358. setting = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<AreaSetting>($"{area.id}", new PartitionKey("AreaSetting"));
  359. }
  360. catch (CosmosException ex)
  361. {
  362. setting = null;
  363. }
  364. if (setting != null && !string.IsNullOrWhiteSpace(setting.accessConfig))
  365. {
  366. access = 1;
  367. }
  368. areasd.Add(area);
  369. }
  370. catch (CosmosException)
  371. {
  372. area = null;
  373. }
  374. }
  375. if (area != null)
  376. {
  377. schoolExtobj.area = new {area.name, area.id, area.institution, area.provName, area.code, area.cityCode, area.cityName, area.standard, area.provCode, area.pk, access };
  378. }
  379. else {
  380. schoolExtobj.area = area;
  381. }
  382. var sctch = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(id, new PartitionKey($"Teacher-{sc.schoolId}"));
  383. if (sctch.Status == 200)
  384. {
  385. var jsonDoc = await JsonDocument.ParseAsync(sctch.ContentStream);
  386. SchoolTeacher schoolTeacher = jsonDoc.RootElement.ToObject<SchoolTeacher>();
  387. schoolTeacher.name = $"{name}";
  388. schoolTeacher.picture = $"{picture}";
  389. await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(schoolTeacher, id, new PartitionKey($"Teacher-{sc.schoolId}"));
  390. if (jsonDoc.RootElement.TryGetProperty("size", out JsonElement _size) && _size.ValueKind.Equals(JsonValueKind.Number))
  391. {
  392. total += _size.GetInt32();
  393. schoolExtobj.size = _size.GetInt32();
  394. }
  395. else { schoolExtobj.size = 0; }
  396. }
  397. else
  398. {
  399. schoolExtobj.size = 0;
  400. }
  401. if (statusNow.Equals("join"))
  402. {
  403. //初始化
  404. await TmdUserService.JoinSchool(client, teacher.id, teacher.picture, teacher.name, sc.schoolId, sc.name);
  405. }
  406. schools.Add(schoolExtobj);
  407. }
  408. }
  409. //如果包含任何申请,邀请,加入学校的记录 且个人空间未分配2G 则默认分配个人空间至2G.
  410. if (teacher.size < 2 && teacher.schools.Count > 0)
  411. {
  412. teacher.size = 2;
  413. }
  414. //如果未包含任何申请,邀请,加入学校的记录 且 个人空间没有分配1G 则默认赠送一个G
  415. if (teacher.schools.Count == 0 && teacher.size < 1)
  416. {
  417. teacher.size = 1;
  418. }
  419. }
  420. if (string.IsNullOrEmpty(teacher.defaultSchool) && teacher.schools.IsNotEmpty())
  421. {
  422. var tech = teacher.schools.FindAll(x => x.status.Equals("join"));
  423. if (tech.IsNotEmpty())
  424. {
  425. teacher.defaultSchool = teacher.schools[0].schoolId;
  426. }
  427. }
  428. await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, id, new PartitionKey("Base"));
  429. //預設學校ID
  430. defaultschool = teacher.defaultSchool;
  431. }
  432. catch (CosmosException ex)
  433. {
  434. if (ex.Status == 404)
  435. {
  436. //如果沒有,則初始化Teacher基本資料到Cosmos
  437. teacher = new Teacher
  438. {
  439. id = id,
  440. pk = "Base",
  441. code = "Base",
  442. name = name?.ToString(),
  443. picture = picture?.ToString(),
  444. //创建账号并第一次登录IES5则默认赠送1G
  445. size = 1,
  446. defaultSchool = null,
  447. schools = new List<Teacher.TeacherSchool>(),
  448. };
  449. var container = _azureStorage.GetBlobContainerClient(id);
  450. await container.CreateIfNotExistsAsync(PublicAccessType.None); //嘗試創建Teacher私有容器,如存在則不做任何事,保障容器一定存在
  451. teacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
  452. total = teacher.size;
  453. tsize = teacher.size;
  454. }
  455. }
  456. //私人課程
  457. List<object> courses = new List<object>();
  458. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{id}") }))
  459. {
  460. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  461. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  462. {
  463. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  464. {
  465. courses.Add(obj.ToObject<object>());
  466. }
  467. }
  468. }
  469. List<string> roles = new List<string>() { "teacher" };
  470. Area areaa = null;
  471. if (areas.Count > 0)
  472. {
  473. roles.Add("area");
  474. if (!string.IsNullOrEmpty($"{areas[0]}"))
  475. {
  476. try
  477. {
  478. areaa = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<Area>($"{areas[0].areaId}", new PartitionKey("Base-Area"));
  479. }
  480. catch (CosmosException)
  481. {
  482. areaa = null;
  483. }
  484. }
  485. }
  486. //換取AuthToken,提供給前端
  487. var auth_token = JwtAuthExtension.CreateAuthToken(_option.HostName, id, name?.ToString(), picture?.ToString(), _option.JwtSecretKey, Website: "IES", scope: Constant.ScopeTeacher, standard: areaa != null ? areaa.standard : "", roles: roles.ToArray());
  488. //取得Teacher Blob 容器位置及SAS
  489. await _azureStorage.GetBlobContainerClient(id).CreateIfNotExistsAsync(PublicAccessType.None); //嘗試創建Teacher私有容器,如存在則不做任何事,保障容器一定存在
  490. var (blob_uri, blob_sas) = _azureStorage.GetBlobContainerSAS(id, BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete);
  491. var (osblob_uri, osblob_sas) = roles.Contains("area") ? _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete) : _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
  492. return new TeacherInfo {
  493. auth_token = auth_token,
  494. blob_uri = blob_uri,
  495. blob_sas = blob_sas,
  496. schools = schools,
  497. defaultschool = defaultschool,
  498. courses = courses,
  499. total=total,
  500. osblob_sas=osblob_sas,
  501. osblob_uri = osblob_uri,
  502. tsize=tsize,
  503. areas= areas,
  504. teacher=teacher
  505. };
  506. }
  507. }
  508. public record AreaDto
  509. {
  510. //areaId = area.id, name = area.name, area.standard, area.standardName
  511. public string areaId { get; set; }
  512. public string name { get; set; }
  513. public string standard { get; set; }
  514. public string standardName { get; set; }
  515. //public string accessConfig { get; set; }
  516. public AreaSetting setting { get; set; }
  517. public int access { get; set; } = 0;
  518. }
  519. public record TeacherInfo {
  520. public string auth_token { get; set; }
  521. public string blob_uri { get; set; }
  522. public string blob_sas { get; set; }
  523. public List<object> schools { get; set; }= new List<object> ();
  524. public string defaultschool { get; set; }
  525. public List<object> courses { get; set; }= new List<object>();
  526. public int total { get; set; }
  527. public string osblob_uri { get; set; }
  528. public string osblob_sas { get; set; }
  529. public int tsize { get; set; }
  530. public List<AreaDto> areas { get; set; } = new List<AreaDto>();
  531. public Teacher teacher { get; set; }
  532. }
  533. }