Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Actuaal
- {
- class JsonFileModel {
- public int Id { get; set; }
- public string Name { get; set; }
- public string Description { get; set; }
- public string RefType { get; set; }
- public int? ParentId { get; set; }
- public int? Level { get; set; }
- }
- class Program
- {
- static void WriteJsonToFile(string fileName, JObject json) {
- File.Create($@"c:\JsonTest\{fileName}.json").Close();
- using (StreamWriter file = File.CreateText($@"c:\JsonTest\{fileName}.json"))
- using (JsonTextWriter writer = new JsonTextWriter(file))
- {
- json.WriteTo(writer);
- }
- Debug.WriteLine($@"Successfully parsed and created c:\JsonTest\{fileName}.json");
- }
- static void Main(string[] args)
- {
- using (var mws = new MyWorkSearch()) {
- var lh = mws.WA_LearningProgrammes_LearningHierarchy
- .Where(x => x.RefType == "LearningFramework").ToList();
- foreach (var i in lh) {
- JObject rootLevel = new JObject(
- new JProperty("Id", i.Id),
- new JProperty("Name", i.Name),
- new JProperty("Description", i.Description),
- new JProperty("RefType", i.RefType),
- new JProperty("Level", i.Level)
- );
- var children = FindById(i.Id);
- rootLevel.Add("Children", JsonConvert.SerializeObject(children));
- WriteJsonToFile("1test", rootLevel);
- }
- }
- }
- //find children
- static List<WA_LearningProgrammes_LearningHierarchy> FindById(int? Id) {
- List<WA_LearningProgrammes_LearningHierarchy> retValue = null;
- using (var mws = new MyWorkSearch()) {
- var children = mws.WA_LearningProgrammes_LearningHierarchy
- .Where(x => x.ParentId == Id)
- .ToList();
- retValue = children;
- }
- return retValue;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement