public static bool SaveDialogElementsToModel(CalEvent t, List<Section> sections) { if (sections != null) { for(int i = 0; i < sections.Count; i++) { foreach (Element e in sections[i]) { if (e.Caption == "Type") { t.Type = TypeOptions[((RootElement)e).RadioSelected]; } else if (e.Caption == "Start Time") { var start = ((DateTimeElement)e).Value; t.StartTimeAsLong = Convert.ToDateTime(start).Ticks; } else if (e.Caption == "End Time") { var end = ((DateTimeElement)e).Value; t.EndTimeAsLong = Convert.ToDateTime(end).Ticks; } else if (e.Caption == "Subject") { t.Subject = ((EntryElement)e).Value; } else if (e.Caption == "Location") { t.Location = ((EntryElement)e).Value; } else if (e.Caption == "Priority") { t.Priority = PriorityOptions[((RootElement)e).RadioSelected]; } } } } return true; }
public static bool Add(List<CalEvent> events, CalEvent c) { //TODO: Replace with a post to a server bool added = false; if (events != null) { events.Add(c); added = true; } else { throw new ArgumentNullException("events", "CalEvent cannot be added to a null list"); } return added; }
public static List<Section> BuildDialogSections(CalEvent Model) { List<Section> sections = new List<Section>(); var section = new Section(); sections.Add(section); int typeOption; for (typeOption = 0; typeOption < TypeOptions.Length; typeOption++) { if (TypeOptions[typeOption] == Model.Type) { break; } } if (typeOption >= TypeOptions.Length) { typeOption = 0; } //set to default var details = new Section("Details"); sections.Add(details); details.Add(new EntryElement("Subject", "no subject entered", Model.Subject)); details.Add(new DateTimeElement("Start Time", Model.StartTime)); DateTime endTime = Model.EndTime; if (endTime.Ticks == 0) { endTime = Model.StartTime.AddHours(1); } details.Add(new DateTimeElement("End Time", endTime)); details.Add(new EntryElement("Location", "no location entered", Model.Location)); var additionalDetails = new Section("Additional Details"); sections.Add(additionalDetails); int priorityOption; for (priorityOption = 0; priorityOption < PriorityOptions.Length; priorityOption++) { if (PriorityOptions[priorityOption] == Model.Priority) { break; } } if (priorityOption >= PriorityOptions.Length) { priorityOption = 0; } //set to default var options = new List<Element>(PriorityOptions.Length); foreach (string o in PriorityOptions) { options.Add(new RadioBounceBackElement(o)); } var optionsSection = new Section(); optionsSection.Elements.AddRange(options); var priorityRoot = new RootElement("Priority", new RadioGroup(priorityOption)) { optionsSection }; additionalDetails.Add(priorityRoot); return sections; }
public static List<Section> CreateEventDetailsSection(CalEvent theEvent) { var sections = new List<Section>(); var section = new Section(); sections.Add(section); section.Add(new StringElement("Type", theEvent.Type)); var details = new Section("Details"); sections.Add(details); details.Add(new StringElement("Subject", theEvent.Subject)); string time = theEvent.StartTime.Ticks > 0 ? theEvent.StartTime.ToString("d") : "unknown"; details.Add(new StringElement("Start Time", time)); time = theEvent.EndTime.Ticks > 0 ? theEvent.EndTime.ToString("d") : "unknown"; details.Add(new StringElement("End Time", time)); details.Add(new StringElement("Location", theEvent.Location)); var additionalDetails = new Section("Additional Details"); sections.Add(additionalDetails); additionalDetails.Add(new StringElement("Priority", theEvent.Priority)); return sections; }
public static bool Update(IEnumerable<CalEvent> events, CalEvent calEvent) { bool updated = false; if (events != null) { foreach(CalEvent c in events) { if (c.Id == calEvent.Id) { c.Description = calEvent.Description; c.EndTimeAsLong = calEvent.EndTimeAsLong; c.Location = calEvent.Location; c.Priority = calEvent.Priority; c.StartTimeAsLong = calEvent.StartTimeAsLong; c.Subject = calEvent.Subject; updated = true; break; } } } else { throw new ArgumentNullException("tasks", "task cannot be updated in a null list"); } return updated; }
public void Add(CalEvent e) { Events.Add(e); }