Example #1
0
        public void Execute()
        {
            try
            {
                foreach (JointTestResult t in viewModel.JointTestResults)
                {
                    if (t.Inspectors.Count <= 0)
                    {
                        numberOfOperationWithoutInspectors++;
                    }
                }
                if (numberOfOperationWithoutInspectors == 0)
                {
                    try
                    {
                        var    duplicateNumber = duplicateNumberRepo.GetAllActiveDuplicateEntityByNumber(viewModel.Number, viewModel.Joint.Id).Distinct(new DuplicateNumberEntityComparer()).ToList();
                        String result          = 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);
                                result = result + ", " + viewModel.localizedAllType[(int)((object)translate) - 1];
                            }

                            notify.ShowInfo(
                                string.Concat(Program.LanguageManager.GetString(StringResources.DuplicateEntity_Message) + result),
                                Program.LanguageManager.GetString(StringResources.DuplicateEntity_MessageHeader));
                            viewModel.Number = string.Empty;
                        }
                        else
                        {
                            viewModel.Joint.Number   = viewModel.Joint.Number.ToUpper();
                            viewModel.Joint.ToExport = true;
                            repo.BeginTransaction();
                            repo.RepoJoint.SaveOrUpdate(viewModel.Joint);

                            var filesViewModel = viewModel.FilesFormViewModel;


                            bool fileCopySuccess = true;
                            if (null != filesViewModel)
                            {
                                filesViewModel.FileRepo           = repo.FileRepo;
                                viewModel.FilesFormViewModel.Item = viewModel.Joint.Id;
                                if (!viewModel.FilesFormViewModel.TrySaveFiles(viewModel.Joint))
                                {
                                    fileCopySuccess = false;
                                    repo.Rollback();
                                }
                            }

                            if (fileCopySuccess)
                            {
                                repo.Commit();
                            }
                            repo.RepoJoint.Evict(viewModel.Joint);

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

                                notify.ShowSuccess(
                                    string.Concat(Program.LanguageManager.GetString(StringResources.Joint_Saved), viewModel.Number),
                                    Program.LanguageManager.GetString(StringResources.Joint_SavedHeader));

                                log.Info(string.Format("The entity #{0}, id:{1} has been saved in DB.",
                                                       viewModel.Joint.Number,
                                                       viewModel.Joint.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.Joint.Number,
                                                       viewModel.Joint.Id));
                            }

                            viewModel.ModifiableView.IsModified = false;
                            viewModel.ModifiableView.Id         = viewModel.Joint.Id;
                            viewModel.ModifiableView.UpdateState();
                        }
                    }
                    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));
                }
            }
            catch (RepositoryException ex)
            {
                log.Warn(this.GetType().Name + " | " + ex.ToString());
                notify.ShowWarning(Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Message),
                                   Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Header));
            }
        }
Example #2
0
        public void Execute()
        {
            foreach (JointTestResult t in viewModel.JointTestResults)
            {
                if (t.Inspectors.Count <= 0)
                {
                    numberOfOperationWithoutInspectors++;
                }
            }
            if (numberOfOperationWithoutInspectors == 0)
            {
                try
                {
                    viewModel.Joint.Number = viewModel.Joint.Number.ToUpper();
                    repo.BeginTransaction();
                    repo.RepoJoint.SaveOrUpdate(viewModel.Joint);

                    var filesViewModel = viewModel.FilesFormViewModel;


                    bool fileCopySuccess = true;
                    if (null != filesViewModel)
                    {
                        filesViewModel.FileRepo           = repo.FileRepo;
                        viewModel.FilesFormViewModel.Item = viewModel.Joint.Id;
                        if (!viewModel.FilesFormViewModel.TrySaveFiles(viewModel.Joint))
                        {
                            fileCopySuccess = false;
                            repo.Rollback();
                        }
                    }

                    repo.Commit();
                    repo.RepoJoint.Evict(viewModel.Joint);

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

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

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

                    notify.ShowNotify(
                        string.Concat(Program.LanguageManager.GetString(StringResources.Joint_Saved), viewModel.Number),
                        Program.LanguageManager.GetString(StringResources.Joint_SavedHeader));

                    log.Info(string.Format("The entity #{0}, id:{1} has been saved in DB.",
                                           viewModel.Joint.Number,
                                           viewModel.Joint.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));
            }
        }