Пример #1
0
        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;
                }
            }
        }
Пример #2
0
 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;
                 }
             }
         }
     }
 }