public void Execute()
        {
            if (notify.ShowYesNo(
                    Program.LanguageManager.GetString(StringResources.Message_ComponentDeactivationQuestion),
                    Program.LanguageManager.GetString(StringResources.Message_ComponentDeactivationQuestionHeader)))
            {
                try
                {
                    viewModel.ComponentIsActive = false;

                    repos.BeginTransaction();
                    repos.ComponentRepo.SaveOrUpdate(viewModel.Component);
                    repos.Commit();

                    repos.ComponentRepo.Evict(viewModel.Component);

                    viewModel.ModifiableView.IsModified = false;
                    viewModel.ModifiableView.IsEditMode = false;
                    viewModel.ModifiableView.UpdateState();

                    notify.ShowSuccess(
                        string.Concat(Program.LanguageManager.GetString(
                                          StringResources.ComponentNewEdit_DeactivatedAction), viewModel.Number),
                        Program.LanguageManager.GetString(
                            StringResources.ComponentNewEdit_DeactivatedActionHeader));

                    log.Info(string.Format("The entity #{0}, id:{1} has been deactivated.",
                                           viewModel.Component.Number, viewModel.Component.Id));
                }
                catch (RepositoryException ex)
                {
                    log.Error(ex.Message);
                    notify.ShowFailure(ex.InnerException.Message, ex.Message);
                }
            }
            else
            {
                //Refresh property so that binded control become unchecked
                viewModel.ComponentIsActive = false;
                viewModel.ComponentIsActive = true;
            }
            RefreshVisualStateEvent();
        }
Example #2
0
        public void Execute()
        {
            if (!viewModel.ValidatableView.Validate())
            {
                return;
            }

            foreach (var result in viewModel.InspectionTestResults)
            {
                if (!result.Date.IsValid())
                {
                    notify.ShowInfo(Program.LanguageManager.GetString(StringResources.WrongDate),
                                    Program.LanguageManager.GetString(StringResources.Message_ErrorHeader));
                    log.Warn("Date limits not valid!");
                    return;
                }
            }

            var c = repos.ComponentRepo.GetActiveByNumber(viewModel.Component);

            foreach (var component in c)
            {
                repos.ComponentRepo.Evict(component);
            }
            var    duplicateNumber = repo.GetAllActiveDuplicateEntityByNumber(viewModel.Number, viewModel.Component.Id).Distinct(new DuplicateNumberEntityComparer()).ToList();
            String resultString    = string.Empty;

            if (duplicateNumber != null && duplicateNumber.Count > 0)
            {
                for (int i = 0; i <= duplicateNumber.Count - 1; i++)
                {
                    DuplicateNumberEntityType translate = (DuplicateNumberEntityType)Enum.Parse(typeof(DuplicateNumberEntityType),
                                                                                                duplicateNumber[i].EntityType);
                    resultString = resultString + viewModel.localizedAllType[(int)((object)translate) - 1] + (i < duplicateNumber.Count - 1 ? ", " : "");;
                }

                notify.ShowInfo(
                    string.Concat(Program.LanguageManager.GetString(StringResources.DuplicateEntity_Message) + resultString),
                    Program.LanguageManager.GetString(StringResources.DuplicateEntity_MessageHeader));
                viewModel.Number = string.Empty;
            }
            else
            {
                foreach (InspectionTestResult t in viewModel.InspectionTestResults)
                {
                    if (t.Status != PartInspectionStatus.Pending && t.Inspectors.Count <= 0)
                    {
                        numberOfOperationWithoutInspectors++;
                    }
                }
                if (numberOfOperationWithoutInspectors == 0)
                {
                    try
                    {
                        viewModel.Component.InspectionStatus = viewModel.Component.GetPartInspectionStatus();
                        viewModel.Component.ToExport         = true;
                        repos.BeginTransaction();
                        viewModel.Component.Number = viewModel.Component.Number.ToUpper();
                        repos.ComponentRepo.SaveOrUpdate(viewModel.Component);

                        var filesViewModel = viewModel.FilesFormViewModel;

                        //saving attached documents
                        bool fileCopySuccess = true;
                        if (null != filesViewModel)
                        {
                            filesViewModel.FileRepo           = repos.FileRepo;
                            viewModel.FilesFormViewModel.Item = viewModel.Component.Id;
                            if (!viewModel.FilesFormViewModel.TrySaveFiles(viewModel.Component))
                            {
                                fileCopySuccess = false;
                                repos.Rollback();
                            }
                        }

                        if (fileCopySuccess)
                        {
                            repos.Commit();
                        }

                        repos.ComponentRepo.Evict(viewModel.Component);
                        viewModel.ModifiableView.IsModified = false;
                        viewModel.ModifiableView.Id         = viewModel.Component.Id;
                        viewModel.ModifiableView.UpdateState();

                        if (fileCopySuccess)
                        {
                            if (null != filesViewModel)
                            {
                                filesViewModel.DetachFileEntities();
                            }

                            notify.ShowSuccess(
                                string.Concat(Program.LanguageManager.GetString(StringResources.ComponentNewEdit_Saved), viewModel.Number),
                                Program.LanguageManager.GetString(StringResources.ComponentNewEdit_SavedHeader));

                            log.Info(string.Format("The entity #{0}, id:{1} has been saved in DB.",
                                                   viewModel.Component.Number, viewModel.Component.Id));
                        }
                        else
                        {
                            notify.ShowError(Program.LanguageManager.GetString(StringResources.ExternalFiles_NotCopied),
                                             Program.LanguageManager.GetString(StringResources.ExternalFiles_NotCopied_Header));
                            log.Info(string.Format("File for entity #{0}, id:{1} hasn't been saved ",
                                                   viewModel.Component.Number, viewModel.Component.Id));
                        }
                    }
                    catch (RepositoryException ex)
                    {
                        log.Error(ex.Message);
                        notify.ShowFailure(ex.InnerException.Message, ex.Message);
                    }
                }
                else
                {
                    notify.ShowError(
                        Program.LanguageManager.GetString(StringResources.SelectInspectorsForTestResult),
                        Program.LanguageManager.GetString(StringResources.SelectInspectorsForTestResultHeader));
                    numberOfOperationWithoutInspectors = 0;
                }
            }
            RefreshVisualStateEvent();
        }
Example #3
0
        public void Execute()
        {
            if (!viewModel.ValidatableView.Validate())
            {
                return;
            }

            foreach (var result in viewModel.InspectionTestResults)
            {
                if (!result.Date.IsValid())
                {
                    notify.ShowInfo(Program.LanguageManager.GetString(StringResources.WrongDate),
                                    Program.LanguageManager.GetString(StringResources.Message_ErrorHeader));
                    log.Warn("Date limits not valid!");
                    return;
                }
            }

            var c = repos.ComponentRepo.GetActiveByNumber(viewModel.Component);

            foreach (var component in c)
            {
                repos.ComponentRepo.Evict(component);
            }

            if (c != null && c.Count > 0)
            {
                notify.ShowInfo(
                    string.Concat(Program.LanguageManager.GetString(StringResources.ComponentNewEdit_Duplicate), " ", viewModel.Number),
                    Program.LanguageManager.GetString(StringResources.ComponentNewEdit_DuplicateHeader));
                viewModel.Number = string.Empty;
            }
            else
            {
                foreach (InspectionTestResult t in viewModel.InspectionTestResults)
                {
                    if (t.Status != PartInspectionStatus.Pending && t.Inspectors.Count <= 0)
                    {
                        numberOfOperationWithoutInspectors++;
                    }
                }
                if (numberOfOperationWithoutInspectors == 0)
                {
                    try
                    {
                        viewModel.Component.InspectionStatus = viewModel.Component.GetPartInspectionStatus();
                        repos.BeginTransaction();
                        viewModel.Component.Number = viewModel.Component.Number.ToUpper();
                        repos.ComponentRepo.SaveOrUpdate(viewModel.Component);

                        var filesViewModel = viewModel.FilesFormViewModel;

                        //saving attached documents
                        bool fileCopySuccess = true;
                        if (null != filesViewModel)
                        {
                            filesViewModel.FileRepo           = repos.FileRepo;
                            viewModel.FilesFormViewModel.Item = viewModel.Component.Id;
                            if (!viewModel.FilesFormViewModel.TrySaveFiles(viewModel.Component))
                            {
                                fileCopySuccess = false;
                                repos.Rollback();
                            }
                        }

                        repos.Commit();
                        repos.ComponentRepo.Evict(viewModel.Component);
                        viewModel.ModifiableView.IsModified = false;
                        viewModel.ModifiableView.UpdateState();

                        if (fileCopySuccess)
                        {
                            if (null != filesViewModel)
                            {
                                filesViewModel.DetachFileEntities();
                            }

                            notify.ShowSuccess(
                                string.Concat(Program.LanguageManager.GetString(StringResources.ComponentNewEdit_Saved), viewModel.Number),
                                Program.LanguageManager.GetString(StringResources.ComponentNewEdit_SavedHeader));
                        }
                        else
                        {
                            notify.ShowError(Program.LanguageManager.GetString(StringResources.ExternalFiles_NotCopied),
                                             Program.LanguageManager.GetString(StringResources.ExternalFiles_NotCopied_Header));
                        }

                        log.Info(string.Format("The entity #{0}, id:{1} has been saved in DB.",
                                               viewModel.Component.Number, viewModel.Component.Id));
                    }
                    catch (RepositoryException ex)
                    {
                        log.Error(ex.Message);
                        notify.ShowFailure(ex.InnerException.Message, ex.Message);
                    }
                }
                else
                {
                    notify.ShowError(
                        Program.LanguageManager.GetString(StringResources.SelectInspectorsForTestResult),
                        Program.LanguageManager.GetString(StringResources.SelectInspectorsForTestResultHeader));
                    numberOfOperationWithoutInspectors = 0;
                }
            }
            RefreshVisualStateEvent();
        }