private void PopulateClassInfo(DataItemClass c) { if (IncludesEditingDetails) { c.Details = Details; } if (IsPartialSemesterClass) { if (StartDate != null) { c.StartDate = DateTime.SpecifyKind(StartDate.Value.Date, DateTimeKind.Utc); if (!SqlDate.IsValid(c.StartDate)) { c.StartDate = SqlDate.MinValue; } } else { c.StartDate = SqlDate.MinValue; } if (EndDate != null) { c.EndDate = DateTime.SpecifyKind(EndDate.Value.Date, DateTimeKind.Utc); if (!SqlDate.IsValid(c.EndDate)) { c.EndDate = SqlDate.MinValue; } } else { c.EndDate = SqlDate.MinValue; } if (StartDate != null || EndDate != null) { TelemetryExtension.Current?.TrackEvent("UsedClassStartEndDates"); } } else { c.StartDate = SqlDate.MinValue; c.EndDate = SqlDate.MinValue; } }
public async void Save() { try { string name = Name; if (string.IsNullOrWhiteSpace(name)) { await new PortableMessageDialog(PowerPlannerResources.GetStringNoNameMessageBody(), PowerPlannerResources.GetStringNoNameMessageHeader()).ShowAsync(); return; } DataItemMegaItem holiday; if (HolidayToEdit != null) { holiday = new DataItemMegaItem() { Identifier = HolidayToEdit.Identifier } } ; else if (AddParams != null) { holiday = new DataItemMegaItem() { Identifier = Guid.NewGuid(), UpperIdentifier = AddParams.SemesterIdentifier, MegaItemType = PowerPlannerSending.MegaItemType.Holiday } } ; else { throw new NullReferenceException("Either editing holiday or add holiday param must be initialized."); } holiday.Name = name; holiday.Date = DateTime.SpecifyKind(StartDate.Date, DateTimeKind.Utc); if (!SqlDate.IsValid(holiday.Date)) { holiday.Date = DateTime.Today; } holiday.EndTime = DateTime.SpecifyKind(EndDate.Date, DateTimeKind.Utc); holiday.EndTime = holiday.EndTime.AddDays(1).AddSeconds(-1); if (!SqlDate.IsValid(holiday.EndTime)) { holiday.EndTime = DateTime.Today; } if (holiday.Date > holiday.EndTime) { await new PortableMessageDialog(PowerPlannerResources.GetString("EditSemesterPage_String_StartDateGreaterThanEndExplanation"), PowerPlannerResources.GetString("EditSemesterPage_String_InvalidStartDate")).ShowAsync(); return; } DataChanges changes = new DataChanges(); changes.Add(holiday); TryStartDataOperationAndThenNavigate(async delegate { await PowerPlannerApp.Current.SaveChanges(changes); }, delegate { this.RemoveViewModel(); }); } catch (Exception ex) { TelemetryExtension.Current?.TrackException(ex); } }
public void Save() { TryStartDataOperationAndThenNavigate(async delegate { string name = Name; if (string.IsNullOrWhiteSpace(name)) { new PortableMessageDialog(PowerPlannerResources.GetStringNoNameMessageBody(), PowerPlannerResources.GetStringNoNameMessageHeader()).Show(); return; } DataItemSemester semester; if (SemesterToEdit != null) { semester = new DataItemSemester() { Identifier = SemesterToEdit.Identifier } } ; else if (AddParams != null) { semester = new DataItemSemester() { Identifier = Guid.NewGuid(), UpperIdentifier = AddParams.YearIdentifier } } ; else { throw new NullReferenceException("Either editing semester or add semester param must be initialized."); } semester.Name = name; if (SupportsStartEnd) { if (StartDate != null) { semester.Start = DateTime.SpecifyKind(StartDate.Value.Date, DateTimeKind.Utc); if (!SqlDate.IsValid(semester.Start)) { semester.Start = DateTime.Today; } } else { semester.Start = PowerPlannerSending.DateValues.UNASSIGNED; } if (EndDate != null) { semester.End = DateTime.SpecifyKind(EndDate.Value.Date, DateTimeKind.Utc); if (!SqlDate.IsValid(semester.End)) { semester.End = DateTime.Today; } } else { semester.End = PowerPlannerSending.DateValues.UNASSIGNED; } if (!PowerPlannerSending.DateValues.IsUnassigned(semester.Start) && !PowerPlannerSending.DateValues.IsUnassigned(semester.End) && semester.Start > semester.End) { new PortableMessageDialog(PowerPlannerResources.GetString("EditSemesterPage_String_StartDateGreaterThanEndExplanation"), PowerPlannerResources.GetString("EditSemesterPage_String_InvalidStartDate")).Show(); return; } } DataChanges changes = new DataChanges(); changes.Add(semester); await PowerPlannerApp.Current.SaveChanges(changes); }, delegate