Ejemplo n.º 1
0
        public AnswerData GetSchedule(DateTime date)
        {
            HttpWebResponse response = _getSchedule(date);
            StreamReader sr = new StreamReader(response.GetResponseStream());
            string data = sr.ReadToEnd();
            sr.Close();
            response.Close();

            //Deserialize data to anser object
            JObject jsonObj = JObject.Parse(data);

            AnswerData answer = new AnswerData(
                (Status)Enum.Parse(typeof(Status), jsonObj.Value<string>("status"), true),
                jsonObj["data"].Value<int>("week_number"),
                jsonObj["data"].Value<string>("day")
            );

            if (answer.Status == Status.Success)
            {
                foreach (JToken tLesson in jsonObj["data"].Value<JArray>("lessons").Children())
                {
                    Lesson lesson = new Lesson(
                        tLesson.Value<string>("time"),
                        tLesson.Value<string>("place"),
                        tLesson.Value<string>("subject"),
                        tLesson.Value<string>("person_name")
                    );
                    answer.Lessons.Add(lesson);
                }
            }
            return answer;
        }
 private void _renderSchedule(AnswerData schedule)
 {
     _clearLessons();
     foreach (Lesson lesson in schedule.Lessons)
     {
         _renderLesson(lesson);
     }
     _showForm();
 }