void SaveChanges() { MessageBoxVM = new MessageBoxModel() { Message = "Выполнить сохранение всех внесённых изменений?", Caption = ProjectView.ProjName + ": Сотрудники", Buttons = MessageBoxButton.YesNo }; if (MessageBoxVM.Result == MessageBoxResult.Yes) { Project project = Mapper.Map <ProjectView, Project>(ProjectView); IEnumerable <ProjEmplView> projEmplViewsToAdd = ProjEmplViews.Where(pEV => pEV.IsChanged && pEV.IsChecked); IEnumerable <ProjEmplView> projEmplViewsToDelete = ProjEmplViews.Where(pEV => pEV.IsChanged && pEV.IsChecked == false); List <Employee> projsToAdd = Mapper.Map <IEnumerable <ProjEmplView>, List <Employee> >(projEmplViewsToAdd); List <Employee> projsToDelete = Mapper.Map <IEnumerable <ProjEmplView>, List <Employee> >(projEmplViewsToDelete); bool IsChangesSaved = false; try { IsChangesSaved = ProjEmplsLogic.SetEmployeesToProject(project, projsToAdd, projsToDelete); } catch (Exception ex) { MessageBoxVM = new MessageBoxModel() { Message = ErrorMessage.MakingMessageForMessageBox(ex), Caption = errCaption }; Log.WriteLogAsync(ex); } if (IsChangesSaved) { foreach (var projEmplView in projEmplViewsToAdd) { ProjectsViewModel.CurrentProjView.ProjEmplViews.Add(projEmplView); } foreach (var projEmplView in projEmplViewsToDelete) { ProjectsViewModel.CurrentProjView.ProjEmplViews.Remove(projEmplView); } foreach (var projEmplView in ProjEmplViews) { projEmplView.IsChanged = false; projEmplView.BackupClear(); } IsProjEmplViewsChanged = false; } } }
void DataLoading() { ProjEmplsLogic.Login = Credentials.Login; ProjEmplsLogic.Password = Credentials.Password; Title = ProjectView.ProjName + ": Сотрудники"; errCaption = "Сотрудники проекта: " + ProjectView.ProjName + " - Ошибка"; List <Employee> employees = new List <Employee>(); IEnumerable <ProjEmplView> projEmplViews; try { employees = ProjEmplsLogic.GetEmployees(); } catch (Exception ex) { MessageBoxVM = new MessageBoxModel() { Message = ErrorMessage.MakingMessageForMessageBox(ex), Caption = errCaption }; Log.WriteLogAsync(ex); projEmplViews = new List <ProjEmplView>(); } projEmplViews = Mapper.Map <IEnumerable <ProjEmplView> >(employees); foreach (var projEmplView in projEmplViews) { if (ProjectView.ProjEmplViews.FirstOrDefault(pEV => pEV.Id == projEmplView.Id) == null) { projEmplView.IsChecked = false; } } foreach (var projEmplView in projEmplViews) { projEmplView.PropertyChanged += (s, e) => OnProjEmplViewChanged(projEmplView, e.PropertyName); ProjEmplViews.Add(projEmplView); } }
void CancelChanges() { if (ProjEmplViews.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 ProjEmplViews) { if (pEV.IsChanged) { pEV.IsChecked = pEV.Backup.IsChecked; } } } } }