// Overload 2 public IdeaViewModel(Idea model, IdeasDataContext db) { _DB = db; _Model = model; // Populate the SystemRequirements and UseCases observable collections _SystemRequirements = new ObservableCollection<SystemRequirement>(_Model.SystemRequirements); //_UseCases = new ObservableCollection<UseCase>(SelectedIdea.UseCases); }
// Overload 1 public IdeaViewModel(IdeasDataContext db) { _DB = db; _Model = new Idea(); _SystemRequirements = new ObservableCollection<SystemRequirement>(_Model.SystemRequirements); //_UseCases = new ObservableCollection<UseCase>(SelectedIdea.UseCases); //_SelectedReq = null; //_SelectedUseCase = null; }
private void SaveItemAppBarButton_Click(object sender, EventArgs e) { // Confirm a title is provided if (titleTextBox.Text.Length == 0) { MessageBox.Show("Please give your idea a name."); return; } else { (DataContext as IdeaViewModel).SelectedIdea.Title = titleTextBox.Text; // Save title (DataContext as IdeaViewModel).SelectedIdea.Overview = overviewTextBox1.Text; // overview (DataContext as IdeaViewModel).SelectedIdea.Notes = notesTextBox.Text; // and notes //// If the system requirements textbox isn't empty, save that if (systemReqsTextBox.Text != "") { string reqTitle = systemReqsTextBox.Text; var req = new SystemRequirement() { Requirement = reqTitle }; (DataContext as IdeaViewModel).AddRequirement(req); } // same thing for use cases if (useCaseTextBox.Text != "") { string ucTitle = useCaseTextBox.Text; var uc = new UseCase() { UCase = ucTitle }; (DataContext as IdeaViewModel).AddUseCase(uc); } } lastSelectedIdea = (DataContext as IdeaViewModel).SelectedIdea; (DataContext as IdeaViewModel).SaveIdeasToDB(); NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); }
public void AddNewIdea() { var newIdea = new Idea(); // create the idea SelectedIdea = newIdea; // set to the relevant datacontext _DB.Ideas.InsertOnSubmit(newIdea); // Add to the database _DB.SubmitChanges(); // Save changes to the database Ideas.Add(newIdea); // Add to the observable collection }