Exemplo n.º 1
0
        public void SaveSurvey()
        {
            Video video = new Video {
                VideoName = NextVideo,
                Answers   = this.Answers
            };

            string filePath = System.IO.Path.Combine(CurrentPath, "Survey.txt");

            if (File.Exists(filePath))
            {   //Load Json File
                VideosCollection = JsonConvert.DeserializeObject <VideosCollection>
                                       (File.ReadAllText(filePath));

                VideosCollection.Videos.Add(video);
                //Save Jsn File
                File.WriteAllText(filePath, JsonConvert.SerializeObject
                                      (VideosCollection, Formatting.Indented));
            }
            else
            {
                ICollection <Video> ts = new List <Video>();
                ts.Add(video);
                VideosCollection = new VideosCollection {
                    Videos = ts
                };
                //Save Jsn File
                File.WriteAllText(filePath,
                                  JsonConvert.SerializeObject(VideosCollection, Formatting.Indented));
            }
            this.Answers.Clear();
        }
Exemplo n.º 2
0
        public void PrintSurvey(string json)
        {
            VideosCollection videosCollection = JsonConvert.DeserializeObject <VideosCollection>
                                                    (File.ReadAllText(json));

            foreach (var video in videosCollection.Videos)
            {
                Console.WriteLine(video.VideoName);
                foreach (var answers in video.Answers)
                {
                    Console.WriteLine("Q" + answers.Id + ": " + answers.Answer);
                }
            }
        }