示例#1
0
        public XDocument SaveBusinessObject(ServiceDocument document)
        {
            DictionaryMapper.Instance.CheckForChanges();

            //load alternate version
            if (!document.IsNew)
            {
                IBusinessObject alternateBusinessObject = this.mapper.LoadBusinessObject(document.BOType, document.Id.Value);
                document.SetAlternateVersion(alternateBusinessObject);
            }

            //update status
            document.UpdateStatus(true);

            if (document.AlternateVersion != null)
            {
                document.AlternateVersion.UpdateStatus(false);
            }

            document.Validate();

            this.ExecuteCustomLogic(document);
            this.ExecuteDocumentOptions(document);

            //validate
            document.Validate();

            //update status
            document.UpdateStatus(true);

            if (document.AlternateVersion != null)
            {
                document.AlternateVersion.UpdateStatus(false);
            }

            SqlConnectionManager.Instance.BeginTransaction();

            try
            {
                DictionaryMapper.Instance.CheckForChanges();
                this.mapper.CheckBusinessObjectVersion(document);

                this.ExecuteCustomLogicDuringTransaction(document);

                DocumentLogicHelper.AssignNumber(document, this.mapper);

                //Make operations list
                XDocument operations = XDocument.Parse("<root/>");

                document.SaveChanges(operations);

                if (document.AlternateVersion != null)
                {
                    document.AlternateVersion.SaveChanges(operations);
                }

                if (operations.Root.HasElements)
                {
                    this.mapper.ExecuteOperations(operations);
                    this.mapper.UpdateDictionaryIndex(document);
                }

                Coordinator.LogSaveBusinessObjectOperation();

                document.SaveRelatedObjects();

                operations = XDocument.Parse("<root/>");

                document.SaveRelations(operations);

                if (document.AlternateVersion != null)
                {
                    ((Document)document.AlternateVersion).SaveRelations(operations);
                }

                if (operations.Root.HasElements)
                {
                    this.mapper.ExecuteOperations(operations);
                }

                if (ProcessManager.Instance.IsServiceReservationEnabled(document))
                {
                    this.ValidateServiceReservation(document);
                    this.mapper.UpdateReservationAndOrderStock(document);
                }

                XDocument returnXml = XDocument.Parse(String.Format(CultureInfo.InvariantCulture, "<root><id>{0}</id></root>", document.Id.ToUpperString()));

                //Custom validation
                this.mapper.ExecuteOnCommitValidationCustomProcedure(document);

                if (this.coordinator.CanCommitTransaction)
                {
                    if (!ConfigurationMapper.Instance.ForceRollbackTransaction)
                    {
                        SqlConnectionManager.Instance.CommitTransaction();
                    }
                    else
                    {
                        SqlConnectionManager.Instance.RollbackTransaction();
                    }
                }

                return(returnXml);
            }
            catch (SqlException sqle)
            {
                RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:89");
                Coordinator.ProcessSqlException(sqle, document.BOType, this.coordinator.CanCommitTransaction);
                throw;
            }
            catch (Exception)
            {
                RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:90");
                if (this.coordinator.CanCommitTransaction)
                {
                    SqlConnectionManager.Instance.RollbackTransaction();
                }
                throw;
            }
        }