Ejemplo n.º 1
0
 public static XElement Serialize(Homework h) {
     var e = new XElement("homework");
     e.Add(new XAttribute("name", h.Name));
     e.Add(new XAttribute("description", h.Description != null ? h.Description : "null"));
     e.Add(new XAttribute("status", h.Status));
     e.Add(new XAttribute("kind", h.Kind.ToString()));
     e.Add(new XAttribute("finalGrade", h.FinalGrade.HasValue ? h.FinalGrade.Value.ToString() : "null"));
     e.Add(new XAttribute("dueDate", h.DueDate.ToString()));
     e.Add(new XAttribute("turnedInDate", h.TurnedInDate.HasValue ? h.TurnedInDate.Value.ToString() : "null"));
     return e;
 }
Ejemplo n.º 2
0
 public static async Task<Homework> CreateAsync(string name, string desc, HomeworkKind k, DateTime due, Class o) {
     var hw = new Homework() {
         Owner = o,
         Name = name,
         Description = desc,
         Kind = k,
         Status = HomeworkStatus.Incomplete,
         FinalGrade = null,
         DueDate = due,
         TurnedInDate = null
     };
     hw.Owner.Homework.Add(hw);
     await hw.Owner.Commit();
     return hw;
 }
Ejemplo n.º 3
0
 public static Homework Deserialize(XElement e, Class o) {
     var hw = new Homework() {
         Owner = o,
         Name = e.Attribute("name").Value,
         Description = e.Attribute("description").Value != "null" ? e.Attribute("description").Value : null,
         Status = (HomeworkStatus)Enum.Parse(typeof(HomeworkStatus), e.Attribute("status").Value),
         Kind = (HomeworkKind)Enum.Parse(typeof(HomeworkKind), e.Attribute("kind").Value),
         DueDate = DateTime.Parse(e.Attribute("dueDate").Value),
         TurnedInDate = e.Attribute("turnedInDate").Value == "null" ? null : new DateTime?(DateTime.Parse(e.Attribute("turnedInDate").Value))
     };
     if (e.Attribute("finalGrade").Value == "null") hw.FinalGrade = null; else hw.FinalGrade = int.Parse(e.Attribute("finalGrade").Value);
     return hw;
 }