public ViewItemYear( DataItemYear dataItem, Func <DataItemSemester, ViewItemSemester> createSemesterMethod) : base(dataItem) { if (createSemesterMethod != null) { Semesters = new MyObservableList <ViewItemSemester>(); AddChildrenHelper(new ViewItemChildrenHelper <DataItemSemester, ViewItemSemester>( isChild: IsChild, addMethod: Add, removeMethod: Remove, createChildMethod: createSemesterMethod, children: Semesters)); } }
public static async System.Threading.Tasks.Task <AccountDataItem> CreateAndInitializeAccountAsync(string username, string localToken, string token, long accountId, int deviceId) { var account = await CreateAccountHelper.CreateAccountLocally(username, localToken, token, accountId, deviceId, needsInitialSync : false); if (account != null) { AccountsManager.SetLastLoginIdentifier(account.LocalAccountId); // Add the default year/semester try { DataItemYear year = new DataItemYear() { Identifier = Guid.NewGuid(), Name = PowerPlannerResources.GetString("DummyFirstYear") }; DataItemSemester semester = new DataItemSemester() { Identifier = Guid.NewGuid(), UpperIdentifier = year.Identifier, Name = PowerPlannerResources.GetString("DummyFirstSemester") }; DataChanges changes = new DataChanges(); changes.Add(year); changes.Add(semester); await PowerPlannerApp.Current.SaveChanges(account, changes); await account.SetCurrentSemesterAsync(semester.Identifier); NavigationManager.MainMenuSelection = NavigationManager.MainMenuSelections.Schedule; return(account); } catch (Exception ex) { TelemetryExtension.Current?.TrackException(ex); } } return(null); }
public void Save() { TryStartDataOperationAndThenNavigate(async delegate { string name = Name; if (string.IsNullOrWhiteSpace(name)) { new PortableMessageDialog(PowerPlannerResources.GetString("AddYearPage_MessageNoName_Body"), PowerPlannerResources.GetString("AddYearPage_MessageNoName_Title")).Show(); return; } DataItemYear year; if (YearToEdit != null) { year = new DataItemYear() { Identifier = YearToEdit.Identifier } } ; else { year = new DataItemYear() { Identifier = Guid.NewGuid() } }; year.Name = name; DataChanges changes = new DataChanges(); changes.Add(year); await PowerPlannerApp.Current.SaveChanges(changes); }, delegate
private static ViewItemYear CreateYear(DataItemYear dataYear) { return(new ViewItemYear(dataYear, createSemesterMethod: CreateSemester)); }
public async Task TestAddingYear() { ViewModelYearsAndSemesters viewModel = await ViewModelYearsAndSemesters.LoadAsync(LocalAccountId); var years = viewModel.School.Years; Assert.AreEqual(0, years.Count); DataItemYear year = new DataItemYear() { Identifier = Guid.NewGuid(), Name = "Freshman" }; DataChanges changes = new DataChanges(); changes.Add(year); await DataStore.ProcessLocalChanges(changes); Assert.AreEqual(1, DataStore.TableYears.Count(), "Database count of years incorrect"); Assert.AreEqual(1, years.Count, "View model didn't update"); ViewItemYear viewYear = years.First(); Assert.AreEqual("Freshman", viewYear.Name); Assert.AreEqual(year.Identifier, viewYear.Identifier); Assert.IsTrue((DateTime.UtcNow - viewYear.DateCreated).TotalSeconds < 2); changes = new DataChanges(); changes.Add(new DataItemYear() { Identifier = Guid.NewGuid(), Name = "Sophomore" }); await DataStore.ProcessLocalChanges(changes); Assert.AreEqual(2, DataStore.TableYears.Count(), "Database count of years incorrect"); Assert.AreEqual(2, years.Count); Assert.AreEqual("Sophomore", years.Last().Name); // Sleep so that updated time should be different than created time await Task.Delay(20); DateTime originalDateCreated = years.First().DateCreated; changes = new DataChanges(); changes.Add(new DataItemYear() { Identifier = years.First().Identifier, Name = "Freshman Edited" }); await DataStore.ProcessLocalChanges(changes); Assert.AreEqual(2, DataStore.TableYears.Count()); Assert.AreEqual(2, years.Count); viewYear = years.First(); Assert.AreEqual("Freshman Edited", viewYear.Name); Assert.AreEqual(originalDateCreated, viewYear.DateCreated); Assert.AreNotEqual(viewYear.DateCreated, viewYear.Updated); }