void SaveChanges() { MessageBoxVM = new MessageBoxModel() { Message = "Выполнить сохранение всех внесённых изменений?", Caption = ProjectView.ProjName + ": Выбор руководителя", Buttons = MessageBoxButton.YesNo }; if (MessageBoxVM.Result == MessageBoxResult.Yes) { Project project = Mapper.Map <ProjectView, Project>(ProjectView); ProjLeadView selectedProjLeadView = ProjLeadViews.FirstOrDefault(pLV => pLV.IsChanged && pLV.IsChecked); ProjLeadView previousProjLeadView = ProjLeadViews.FirstOrDefault(pLV => pLV.IsChanged && !pLV.IsChecked); Employee selectedLeader = Mapper.Map <ProjLeadView, Employee>(selectedProjLeadView); bool IsChangesSaved = false; try { IsChangesSaved = ProjLeadLogic.SetLeaderToProject(project, selectedLeader); } catch (Exception ex) { MessageBoxVM = new MessageBoxModel() { Message = ErrorMessage.MakingMessageForMessageBox(ex), Caption = errCaption }; Log.WriteLogAsync(ex); } if (IsChangesSaved) { if (ViewModelsContainer.EmployeesViewModel != null) { ViewModelsContainer.EmployeesViewModel.IsEmployeeViewsChangedByProjectsViewModel = true; if (previousProjLeadView != null) { ViewModelsContainer.EmployeesViewModel .EmployeeViews .First(eV => eV.Id == previousProjLeadView.Id) .LeadProjViews.Remove(Mapper.Map <EmplProjs.EmplProjView>(ProjectsViewModel.CurrentProjView)); } ViewModelsContainer.EmployeesViewModel.IsEmployeeViewsChangedByProjectsViewModel = false; } ProjectsViewModel.CurrentProjView.ProjLeadView = selectedProjLeadView; foreach (var projLeadView in ProjLeadViews) { projLeadView.IsChanged = false; } IsProjLeadViewsChanged = false; } } }
void OnProjLeadViewChanged(ProjLeadView projLeadView, string propertyName) { if (propertyName == "IsChecked") { if (projLeadView.IsChecked == projLeadView.Backup.IsChecked) { projLeadView.IsChanged = false; if (ViewModelsContainer.ProjLeadViewModel.ProjLeadViews.FirstOrDefault(pLV => pLV.IsChanged) == null) { ViewModelsContainer.ProjLeadViewModel.IsProjLeadViewsChanged = false; } projLeadView.Backup = null; } else { projLeadView.IsChanged = true; if (ViewModelsContainer.ProjLeadViewModel.ProjLeadViews.FirstOrDefault(pLV => pLV.IsChanged) != null) { ViewModelsContainer.ProjLeadViewModel.IsProjLeadViewsChanged = true; } } } }