private bool CanDocumentsClose(IEnumerable <IDocument> documentsToClose) { var modifiedDocuments = documentsToClose.Where(d => d.Modified).ToArray(); if (!modifiedDocuments.Any()) { return(true); } // Show the save changes view to the user SaveChangesViewModel saveChangesViewModel = saveChangesViewModelFactory.CreateExport().Value; saveChangesViewModel.Documents = modifiedDocuments; bool?dialogResult = saveChangesViewModel.ShowDialog(shellService.ShellView); if (dialogResult == true) { foreach (IDocument document in modifiedDocuments) { Save(document); } } return(dialogResult != null); }
public void SaveChangesViewModelCloseTest() { var documentType = new MockDocumentType("Mock Document", ".mock"); var documents = new[] { documentType.New(), documentType.New(), documentType.New() }; var view = new MockSaveChangesView(); var viewModel = new SaveChangesViewModel(view) { Documents = documents }; // In this case it tries to get the title of the unit test framework which is "" Assert.AreEqual("", viewModel.Title); Assert.AreEqual(documents, viewModel.Documents); object owner = new object(); Assert.IsFalse(view.IsVisible); MockSaveChangesView.ShowDialogAction = v => { Assert.AreEqual(owner, v.Owner); Assert.IsTrue(v.IsVisible); }; bool?dialogResult = viewModel.ShowDialog(owner); Assert.IsNull(dialogResult); Assert.IsFalse(view.IsVisible); MockSaveChangesView.ShowDialogAction = v => { viewModel.YesCommand.Execute(null); }; dialogResult = viewModel.ShowDialog(owner); Assert.AreEqual(true, dialogResult); MockSaveChangesView.ShowDialogAction = v => { viewModel.NoCommand.Execute(null); }; dialogResult = viewModel.ShowDialog(owner); Assert.AreEqual(false, dialogResult); MockSaveChangesView.ShowDialogAction = null; }
public void SaveChangesViewModelCloseTest() { var documentType = new MockRichTextDocumentType(); var documents = new[] { documentType.New(), documentType.New(), documentType.New() }; var view = new MockSaveChangesView(); var viewModel = new SaveChangesViewModel(view) { Documents = documents }; Assert.AreEqual(documents, viewModel.Documents); var owner = new object(); Assert.IsFalse(view.IsVisible); MockSaveChangesView.ShowDialogAction = v => { Assert.AreEqual(owner, v.Owner); Assert.IsTrue(v.IsVisible); }; var dialogResult = viewModel.ShowDialog(owner); Assert.IsNull(dialogResult); Assert.IsFalse(view.IsVisible); MockSaveChangesView.ShowDialogAction = _ => { viewModel.YesCommand.Execute(null); }; dialogResult = viewModel.ShowDialog(owner); Assert.AreEqual(true, dialogResult); MockSaveChangesView.ShowDialogAction = _ => { viewModel.NoCommand.Execute(null); }; dialogResult = viewModel.ShowDialog(owner); Assert.AreEqual(false, dialogResult); MockSaveChangesView.ShowDialogAction = null; }
public ActionResult SaveChanges(SaveChangesViewModel model) { if (ModelState.IsValid) { var CurrentUserId = User.Identity.GetUserId(); Employee employee = db.Employees.Find(CurrentUserId); employee.FirstName = model.FirstName; employee.LastName = model.LastName; employee.Age = model.Age; employee.Position = model.Position; employee.Score = model.Score; employee.ProfilePicture = model.ProfilePicture; this.db.SaveChanges(); } return(RedirectToAction("EmployeeInfoEdit")); }
public void SaveChangesViewModelCloseTest() { MockDocumentType documentType = new MockDocumentType("Mock Document", ".mock"); var documents = new[] { documentType.New(), documentType.New(), documentType.New() }; MockSaveChangesView view = new MockSaveChangesView(); SaveChangesViewModel viewModel = new SaveChangesViewModel(view) { Documents = documents }; // In this case it tries to get the title of the unit test framework which is "" Assert.AreEqual("", SaveChangesViewModel.Title); Assert.AreEqual(documents, viewModel.Documents); object owner = new object(); Assert.IsFalse(view.IsVisible); MockSaveChangesView.ShowDialogAction = v => { Assert.AreEqual(owner, v.Owner); Assert.IsTrue(v.IsVisible); }; bool? dialogResult = viewModel.ShowDialog(owner); Assert.IsNull(dialogResult); Assert.IsFalse(view.IsVisible); MockSaveChangesView.ShowDialogAction = v => { viewModel.YesCommand.Execute(null); }; dialogResult = viewModel.ShowDialog(owner); Assert.AreEqual(true, dialogResult); MockSaveChangesView.ShowDialogAction = v => { viewModel.NoCommand.Execute(null); }; dialogResult = viewModel.ShowDialog(owner); Assert.AreEqual(false, dialogResult); MockSaveChangesView.ShowDialogAction = null; }
private bool PrepareToClose(IEnumerable <DocumentFile> documentsToClose) { var modifiedDocuments = documentsToClose.Where(d => d.Modified).ToArray(); if (!modifiedDocuments.Any()) { return(true); } SaveChangesViewModel saveChangesViewModel = saveChangesViewModelFactory.CreateExport().Value; saveChangesViewModel.DocumentFiles = modifiedDocuments; bool?dialogResult = saveChangesViewModel.ShowDialog(shellService.ShellView); if (dialogResult == true) { foreach (var document in modifiedDocuments) { Save(document); } } return(dialogResult != null); }
private bool CanDocumentsClose(IEnumerable<IDocument> documentsToClose) { IEnumerable<IDocument> modifiedDocuments = documentsToClose.Where(d => d.Modified).ToList(); if (!modifiedDocuments.Any()) { return true; } // Show the save changes view to the user ISaveChangesView saveChangesView = container.GetExportedValue<ISaveChangesView>(); SaveChangesViewModel saveChangesViewModel = new SaveChangesViewModel(saveChangesView, modifiedDocuments); bool? dialogResult = saveChangesViewModel.ShowDialog(shellService.ShellView); if (dialogResult == true) { foreach (IDocument document in modifiedDocuments) { Save(document); } } return dialogResult != null; }