public override XDocument SaveBusinessObject(IBusinessObject businessObject) { if (businessObject.BOType == BusinessObjectType.Container) { return(base.SaveBusinessObject(businessObject)); } DictionaryMapper.Instance.CheckForChanges(); if (!businessObject.IsNew && businessObject.AlternateVersion == null) { IBusinessObject alternateBusinessObject = this.Mapper.LoadBusinessObject(businessObject.BOType, businessObject.Id.Value); businessObject.SetAlternateVersion(alternateBusinessObject); } businessObject.UpdateStatus(true); if (businessObject.AlternateVersion != null) { businessObject.AlternateVersion.UpdateStatus(false); } businessObject.Validate(); SqlConnectionManager.Instance.BeginTransaction(); try { DictionaryMapper.Instance.CheckForChanges(); this.Mapper.CheckBusinessObjectVersion(businessObject); XDocument operations = XDocument.Parse("<root/>"); businessObject.SaveChanges(operations); if (businessObject.AlternateVersion != null) { businessObject.AlternateVersion.SaveChanges(operations); } if (operations.Root.HasElements) { XDocument headerOperation = XDocument.Parse("<root/>"); if (businessObject.Status == BusinessObjectStatus.New || businessObject.Status == BusinessObjectStatus.Modified) { headerOperation.Root.Add(operations.Root.Element("shiftTransaction")); //auto-cloning } //sprawdzamy czy sa jakies delety if (operations.Root.Element("shift") != null) { var deletes = operations.Root.Element("shift").Elements().Where(e => e.Attribute("action") != null && e.Attribute("action").Value == "delete"); if (deletes.Count() > 0) { headerOperation.Root.Add(new XElement("shift", deletes)); } } if (operations.Root.Element("shiftAttrValue") != null) { var deletes = operations.Root.Element("shiftAttrValue").Elements().Where(s => s.Attribute("action") != null && s.Attribute("action").Value == "delete"); if (deletes.Count() > 0) { headerOperation.Root.Add(new XElement("shiftAttrValue", deletes)); } } this.Mapper.ExecuteOperations(headerOperation); WarehouseMapper mapper = (WarehouseMapper)this.Mapper; XDocument createTransactionParam = XDocument.Parse("<root><shift/><containerShift/></root>"); if (operations.Root.Element("shift") != null) { createTransactionParam.Root.Element("shift").Add(operations.Root.Element("shift").Elements().Where(s => s.Attribute("action").Value == "insert")); } if (operations.Root.Element("containerShift") != null) { createTransactionParam.Root.Element("containerShift").Add(operations.Root.Element("containerShift").Elements().Where(s => s.Attribute("action").Value == "insert")); } if (createTransactionParam.Root.Element("shift").HasElements || createTransactionParam.Root.Element("containerShift").HasElements) { XElement result = mapper.CreateShiftTransaction(createTransactionParam); this.ProcessTransactionResult(result); } XDocument editTransactionParam = XDocument.Parse("<root><shift/><containerShift/></root>"); if (operations.Root.Element("shift") != null) { editTransactionParam.Root.Element("shift").Add(operations.Root.Element("shift").Elements().Where(s => s.Attribute("action").Value == "update")); } if (operations.Root.Element("containerShift") != null) { editTransactionParam.Root.Element("containerShift").Add(operations.Root.Element("containerShift").Elements().Where(s => s.Attribute("action").Value == "update")); } if (editTransactionParam.Root.Element("shift").HasElements || editTransactionParam.Root.Element("containerShift").HasElements) { XElement result = mapper.EditShiftTransaction(editTransactionParam); this.ProcessTransactionResult(result); } //insert or update attributes if (operations.Root.Element("shiftAttrValue") != null) { XDocument attributes = XDocument.Parse("<root><shiftAttrValue/></root>"); attributes.Root.Element("shiftAttrValue").Add(operations.Root.Element("shiftAttrValue").Elements().Where(entry => entry.Attribute("action") == null || entry.Attribute("action").Value != "delete")); this.Mapper.ExecuteOperations(attributes); } if (businessObject.IsNew) { ((WarehouseMapper)this.Mapper).DuplicateShiftAttributes(businessObject.Id.Value); } } Coordinator.LogSaveBusinessObjectOperation(); XDocument returnXml = XDocument.Parse(String.Format(CultureInfo.InvariantCulture, "<root><id>{0}</id></root>", businessObject.Id.ToUpperString())); if (this.CanCommitTransaction) { if (!ConfigurationMapper.Instance.ForceRollbackTransaction) { SqlConnectionManager.Instance.CommitTransaction(); } else { SqlConnectionManager.Instance.RollbackTransaction(); } } return(returnXml); } catch (SqlException sqle) { RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:98"); Coordinator.ProcessSqlException(sqle, businessObject.BOType, this.CanCommitTransaction); throw; } catch (Exception) { RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:99"); if (this.CanCommitTransaction) { SqlConnectionManager.Instance.RollbackTransaction(); } throw; } }