void SaveChanges() { MessageBoxVM = new MessageBoxModel() { Message = "Выполнить сохранение всех внесённых изменений?", Caption = EmployeeView.Surname + " " + EmployeeView.Name + " " + EmployeeView.MiddleName + ": Проекты", Buttons = MessageBoxButton.YesNo }; if (MessageBoxVM.Result == MessageBoxResult.Yes) { Employee employee = Mapper.Map <EmployeeView, Employee>(EmployeeView); IEnumerable <EmplProjView> emplProjViewsToAdd = EmplProjViews.Where(ePV => ePV.IsChanged && ePV.IsChecked); IEnumerable <EmplProjView> emplProjViewsToDelete = EmplProjViews.Where(ePV => ePV.IsChanged && ePV.IsChecked == false); List <Project> projsToAdd = Mapper.Map <IEnumerable <EmplProjView>, List <Project> >(emplProjViewsToAdd); List <Project> projsToDelete = Mapper.Map <IEnumerable <EmplProjView>, List <Project> >(emplProjViewsToDelete); bool IsChangesSaved = false; try { IsChangesSaved = EmplProjsLogic.SetProjectsToEmployee(employee, projsToAdd, projsToDelete); } catch (Exception ex) { MessageBoxVM = new MessageBoxModel() { Message = ErrorMessage.MakingMessageForMessageBox(ex), Caption = errCaption }; Log.WriteLogAsync(ex); } if (IsChangesSaved) { foreach (var emplProjView in emplProjViewsToAdd) { EmployeesViewModel.CurrentEmplView .EmplProjViews .Add(emplProjView); } foreach (var emplProjView in emplProjViewsToDelete) { EmployeesViewModel.CurrentEmplView .EmplProjViews .Remove(emplProjView); } foreach (var emplProjView in EmplProjViews) { emplProjView.IsChanged = false; emplProjView.BackupClear(); } IsEmplProjViewsChanged = false; } } }
void DataLoading() { EmplProjsLogic.Login = Credentials.Login; EmplProjsLogic.Password = Credentials.Password; Title = EmployeeView.Surname + " " + EmployeeView.Name + " " + EmployeeView.MiddleName + ": Проекты"; errCaption = EmployeeView.Surname + " " + EmployeeView.Name + " " + EmployeeView.MiddleName + ": Проекты - Ошибка"; List <Project> projects = new List <Project>(); IEnumerable <EmplProjView> emplProjViews; try { projects = EmplProjsLogic.GetProjects(); } catch (Exception ex) { MessageBoxVM = new MessageBoxModel() { Message = ErrorMessage.MakingMessageForMessageBox(ex), Caption = errCaption }; Log.WriteLogAsync(ex); emplProjViews = new List <EmplProjView>(); } emplProjViews = Mapper.Map <IEnumerable <EmplProjView> >(projects); foreach (var emplProjView in emplProjViews) { if (EmployeeView.EmplProjViews.FirstOrDefault(ePV => ePV.Id == emplProjView.Id) == null) { emplProjView.IsChecked = false; } } foreach (var emplProjView in emplProjViews) { emplProjView.PropertyChanged += (s, e) => OnEmplProjViewChanged(emplProjView, e.PropertyName); EmplProjViews.Add(emplProjView); } }
void CancelChanges() { if (EmplProjViews.Where(v => v.IsChanged == true).Count() > 0) { MessageBoxVM = new MessageBoxModel() { Message = "Все внесённые изменения будут удалены. Продолжить?", Caption = EmployeeView.Surname + " " + EmployeeView.Name + " " + EmployeeView.MiddleName + ": Проекты", Buttons = MessageBoxButton.YesNo }; if (MessageBoxVM.Result == MessageBoxResult.Yes) { foreach (var ePV in EmplProjViews) { if (ePV.IsChanged) { ePV.IsChecked = ePV.Backup.IsChecked; } } } } }