| | | 1 | | using Newtonsoft.Json.Linq; |
| | | 2 | | using OzonDomains.TecDocModels.Substitute; |
| | | 3 | | using Attribute = OzonDomains.TecDocModels.Substitute.Attribute; |
| | | 4 | | |
| | | 5 | | namespace Services.ParserServices |
| | | 6 | | { |
| | | 7 | | public class SubstituteResultCaster |
| | | 8 | | { |
| | | 9 | | public async Task<SubstituteResultSchema> ParseSubstituteResultSchemaAsync(JObject json) |
| | | 10 | | { |
| | 0 | 11 | | var result = new SubstituteResultSchema(); |
| | | 12 | | |
| | 0 | 13 | | if (json != null) |
| | | 14 | | { |
| | 0 | 15 | | result.SubstituteCount = json["SubstitutesCount"]?.ToObject<int>() ?? 0; |
| | | 16 | | |
| | 0 | 17 | | if (json["Substitutes"] is JArray substitutesArray) |
| | | 18 | | { |
| | 0 | 19 | | var substituteSchemas = new List<SubstituteSchema>(); |
| | | 20 | | |
| | 0 | 21 | | foreach (var substituteItem in substitutesArray) |
| | | 22 | | { |
| | 0 | 23 | | if (substituteSchemas.Count >= 100) |
| | | 24 | | { |
| | | 25 | | break; |
| | | 26 | | } |
| | 0 | 27 | | var substituteSchema = new SubstituteSchema |
| | 0 | 28 | | { |
| | 0 | 29 | | Type = substituteItem["Type"]?.ToString(), |
| | 0 | 30 | | Name = substituteItem["Name"]?.ToString(), |
| | 0 | 31 | | Modification = substituteItem["Modification"]?.ToObject<Modification>(), |
| | 0 | 32 | | Attributes = substituteItem["Attributes"]?.ToObject<List<Attribute>>() ?? new List<Attribute |
| | 0 | 33 | | }; |
| | | 34 | | |
| | 0 | 35 | | substituteSchemas.Add(substituteSchema); |
| | | 36 | | } |
| | | 37 | | |
| | 0 | 38 | | result.SubstituteSchema = substituteSchemas; |
| | | 39 | | } |
| | | 40 | | } |
| | | 41 | | |
| | 0 | 42 | | return await Task.FromResult(result); |
| | 0 | 43 | | } |
| | | 44 | | } |
| | | 45 | | } |