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 DataLoading() { ProjLeadLogic.Login = Credentials.Login; ProjLeadLogic.Password = Credentials.Password; Title = ProjectView.ProjName + ": Выбор руководителя"; errCaption = "Выбор руководителя: " + ProjectView.ProjName + " - Ошибка"; List <Employee> employees = new List <Employee>(); IEnumerable <ProjLeadView> projLeadViews; try { employees = ProjLeadLogic.GetEmployees(); } catch (Exception ex) { MessageBoxVM = new MessageBoxModel() { Message = ErrorMessage.MakingMessageForMessageBox(ex), Caption = errCaption }; Log.WriteLogAsync(ex); projLeadViews = new List <ProjLeadView>(); } projLeadViews = Mapper.Map <IEnumerable <ProjLeadView> >(employees); foreach (var projLeadView in projLeadViews) { if (ProjectView.ProjLeadView == null || ProjectView.ProjLeadView.Id != projLeadView.Id) { projLeadView.IsChecked = false; } projLeadView.ProjLeadVM = this; } foreach (var projLeadView in projLeadViews) { projLeadView.PropertyChanged += (s, e) => OnProjLeadViewChanged(projLeadView, e.PropertyName); ProjLeadViews.Add(projLeadView); } }
void CancelChanges() { if (ProjLeadViews.Where(v => v.IsChanged == true).Count() > 0) { MessageBoxVM = new MessageBoxModel() { Message = "Все внесённые изменения будут удалены. Продолжить?", Caption = ProjectView.ProjName + ": Выбор руководителя", Buttons = MessageBoxButton.YesNo }; if (MessageBoxVM.Result == MessageBoxResult.Yes) { foreach (var pEV in ProjLeadViews) { if (pEV.Backup != null) { pEV.IsChecked = pEV.Backup.IsChecked; } } } } }