public void SaveWarehouseMap(XDocument xml)
        {
            SessionManager.VolatileElements.ClientRequest = xml;

            WarehouseMapper mapper = (WarehouseMapper)this.Mapper;
            MassiveBusinessObjectCollection <Container> modifiedCollection = new MassiveBusinessObjectCollection <Container>();
            MassiveBusinessObjectCollection <Container> originalCollection = mapper.GetAllContainers();

            int order = 1;

            foreach (XElement containerElement in xml.Root.Descendants("slot"))
            {
                Container c = modifiedCollection.CreateNew();
                c.ContainerTypeId = new Guid(containerElement.Attribute("containerTypeId").Value);
                c.Id     = new Guid(containerElement.Attribute("id").Value);
                c.Labels = XElement.Parse("<labels><label lang=\"pl\">" + containerElement.Attribute("label").Value + "</label></labels>");
                c.Order  = order++;
                c.Symbol = containerElement.Attribute("symbol").Value;

                var orig = originalCollection.Children.Where(cc => cc.Id.Value == c.Id.Value).FirstOrDefault();

                if (orig != null)
                {
                    c.Version = orig.Version.Value;
                }
            }

            modifiedCollection.SetAlternateVersion(originalCollection);

            DictionaryMapper.Instance.CheckForChanges();

            foreach (IVersionedBusinessObject businessObject in modifiedCollection.Children)
            {
                businessObject.Validate();
                businessObject.UpdateStatus(true);
            }

            foreach (IVersionedBusinessObject businessObject in originalCollection.Children)
            {
                businessObject.UpdateStatus(false);
            }

            SqlConnectionManager.Instance.BeginTransaction();

            try
            {
                DictionaryMapper.Instance.CheckForChanges();
                XDocument operations = XDocument.Parse("<root/>");

                foreach (IVersionedBusinessObject businessObject in modifiedCollection.Children)
                {
                    this.Mapper.CheckBusinessObjectVersion(businessObject);

                    #region Make operations list
                    businessObject.SaveChanges(operations);

                    if (businessObject.AlternateVersion != null)
                    {
                        businessObject.AlternateVersion.SaveChanges(operations);
                    }
                    #endregion
                }

                //sprawdzamy czy jakis kontener jest do usuniecia
                var containersToDelete = originalCollection.Children.Where(o => o.Status == BusinessObjectStatus.Deleted);

                if (containersToDelete.FirstOrDefault() != null)
                {
                    bool areEmpty = ((WarehouseMapper)this.Mapper).AreContainersEmpty(containersToDelete);

                    if (!areEmpty)
                    {
                        throw new ClientException(ClientExceptionId.NotEmptyContainerRemoval);
                    }

                    foreach (Container c in originalCollection.Children)
                    {
                        if (c.Status == BusinessObjectStatus.Deleted)
                        {
                            c.Status   = BusinessObjectStatus.Modified;
                            c.IsActive = false;
                            c.SaveChanges(operations);
                        }
                    }
                }

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

                //zapisujemy xml do konfiguracji
                using (var c = new ConfigurationCoordinator(false, false))
                {
                    var collection = ConfigurationMapper.Instance.GetConfiguration(SessionManager.User, "warehouse.warehouseMap");

                    Configuration conf = null;

                    if (collection.Count == 0)
                    {
                        conf     = (Configuration)c.CreateNewBusinessObject(BusinessObjectType.Configuration, null, null);
                        conf.Key = "warehouse.warehouseMap";
                    }
                    else
                    {
                        conf = collection.First();
                    }

                    conf.Value = xml.Root;
                    c.SaveBusinessObject(conf);
                }

                if (this.CanCommitTransaction)
                {
                    if (!ConfigurationMapper.Instance.ForceRollbackTransaction)
                    {
                        SqlConnectionManager.Instance.CommitTransaction();
                    }
                    else
                    {
                        SqlConnectionManager.Instance.RollbackTransaction();
                    }
                }
            }
            catch (SqlException sqle)
            {
                RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:96");
                Coordinator.ProcessSqlException(sqle, BusinessObjectType.Container, this.CanCommitTransaction);
                throw;
            }
            catch (Exception)
            {
                RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:97");
                if (this.CanCommitTransaction)
                {
                    SqlConnectionManager.Instance.RollbackTransaction();
                }
                throw;
            }
        }
        /// <summary>
        /// Saves the dictionary to the database. Supports massive modifications.
        /// </summary>
        /// <param name="requestXml">Client request xml containing multiple dictionary entries.</param>
        /// <returns>Xml containing operation result.</returns>
        public XDocument SaveDictionary(XDocument requestXml)
        {
            SessionManager.VolatileElements.ClientRequest = requestXml;
            XDocument modifiedXml = requestXml;

            BusinessObjectType boType = (BusinessObjectType)Enum.Parse(typeof(BusinessObjectType), ((XElement)modifiedXml.Root.FirstNode).Name.LocalName, true);

            if (boType == BusinessObjectType.ContractorField)
            {
                MassiveBusinessObjectCollection <ContractorField> modifiedCollection = new MassiveBusinessObjectCollection <ContractorField>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetContractorFields();
                MassiveBusinessObjectCollection <ContractorField> originalCollection = new MassiveBusinessObjectCollection <ContractorField>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <ContractorField>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.ContractorRelationType)
            {
                MassiveBusinessObjectCollection <ContractorRelationType> modifiedCollection = new MassiveBusinessObjectCollection <ContractorRelationType>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetContractorRelationTypes();
                MassiveBusinessObjectCollection <ContractorRelationType> originalCollection = new MassiveBusinessObjectCollection <ContractorRelationType>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <ContractorRelationType>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.Country)
            {
                MassiveBusinessObjectCollection <Country> modifiedCollection = new MassiveBusinessObjectCollection <Country>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetCountries();
                MassiveBusinessObjectCollection <Country> originalCollection = new MassiveBusinessObjectCollection <Country>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <Country>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.Currency)
            {
                MassiveBusinessObjectCollection <Currency> modifiedCollection = new MassiveBusinessObjectCollection <Currency>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetCurrencies();
                MassiveBusinessObjectCollection <Currency> originalCollection = new MassiveBusinessObjectCollection <Currency>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <Currency>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.DocumentField)
            {
                MassiveBusinessObjectCollection <DocumentField> modifiedCollection = new MassiveBusinessObjectCollection <DocumentField>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetDocumentFields();
                MassiveBusinessObjectCollection <DocumentField> originalCollection = new MassiveBusinessObjectCollection <DocumentField>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <DocumentField>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.DocumentFieldRelation)
            {
                MassiveBusinessObjectCollection <DocumentFieldRelation> modifiedCollection = new MassiveBusinessObjectCollection <DocumentFieldRelation>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetDocumentFieldRelations();
                MassiveBusinessObjectCollection <DocumentFieldRelation> originalCollection = new MassiveBusinessObjectCollection <DocumentFieldRelation>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <DocumentFieldRelation>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.DocumentNumberComponent)
            {
                MassiveBusinessObjectCollection <DocumentNumberComponent> modifiedCollection = new MassiveBusinessObjectCollection <DocumentNumberComponent>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetDocumentNumberComponents();
                MassiveBusinessObjectCollection <DocumentNumberComponent> originalCollection = new MassiveBusinessObjectCollection <DocumentNumberComponent>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <DocumentNumberComponent>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.DocumentType)
            {
                MassiveBusinessObjectCollection <DocumentType> modifiedCollection = new MassiveBusinessObjectCollection <DocumentType>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetDocumentTypes();
                MassiveBusinessObjectCollection <DocumentType> originalCollection = new MassiveBusinessObjectCollection <DocumentType>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <DocumentType>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.IssuePlace)
            {
                MassiveBusinessObjectCollection <IssuePlace> modifiedCollection = new MassiveBusinessObjectCollection <IssuePlace>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetIssuePlaces();
                MassiveBusinessObjectCollection <IssuePlace> originalCollection = new MassiveBusinessObjectCollection <IssuePlace>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <IssuePlace>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.ItemField)
            {
                MassiveBusinessObjectCollection <ItemField> modifiedCollection = new MassiveBusinessObjectCollection <ItemField>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetItemFields();
                MassiveBusinessObjectCollection <ItemField> originalCollection = new MassiveBusinessObjectCollection <ItemField>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <ItemField>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.ItemRelationAttrValueType)
            {
                MassiveBusinessObjectCollection <ItemRelationAttrValueType> modifiedCollection = new MassiveBusinessObjectCollection <ItemRelationAttrValueType>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetItemRelationAttrValueTypes();
                MassiveBusinessObjectCollection <ItemRelationAttrValueType> originalCollection = new MassiveBusinessObjectCollection <ItemRelationAttrValueType>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <ItemRelationAttrValueType>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.ItemRelationType)
            {
                MassiveBusinessObjectCollection <ItemRelationType> modifiedCollection = new MassiveBusinessObjectCollection <ItemRelationType>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetItemRelationTypes();
                MassiveBusinessObjectCollection <ItemRelationType> originalCollection = new MassiveBusinessObjectCollection <ItemRelationType>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <ItemRelationType>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.ItemType)
            {
                MassiveBusinessObjectCollection <ItemType> modifiedCollection = new MassiveBusinessObjectCollection <ItemType>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetItemTypes();
                MassiveBusinessObjectCollection <ItemType> originalCollection = new MassiveBusinessObjectCollection <ItemType>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <ItemType>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.JobPosition)
            {
                MassiveBusinessObjectCollection <JobPosition> modifiedCollection = new MassiveBusinessObjectCollection <JobPosition>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetJobPositions();
                MassiveBusinessObjectCollection <JobPosition> originalCollection = new MassiveBusinessObjectCollection <JobPosition>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <JobPosition>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.NumberSetting)
            {
                MassiveBusinessObjectCollection <NumberSetting> modifiedCollection = new MassiveBusinessObjectCollection <NumberSetting>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetNumberSettings();
                MassiveBusinessObjectCollection <NumberSetting> originalCollection = new MassiveBusinessObjectCollection <NumberSetting>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <NumberSetting>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.PaymentMethod)
            {
                MassiveBusinessObjectCollection <PaymentMethod> modifiedCollection = new MassiveBusinessObjectCollection <PaymentMethod>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetPaymentMethods();
                MassiveBusinessObjectCollection <PaymentMethod> originalCollection = new MassiveBusinessObjectCollection <PaymentMethod>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <PaymentMethod>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.Unit)
            {
                MassiveBusinessObjectCollection <Unit> modifiedCollection = new MassiveBusinessObjectCollection <Unit>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetUnits();
                MassiveBusinessObjectCollection <Unit> originalCollection = new MassiveBusinessObjectCollection <Unit>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <Unit>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.UnitType)
            {
                MassiveBusinessObjectCollection <UnitType> modifiedCollection = new MassiveBusinessObjectCollection <UnitType>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetUnitTypes();
                MassiveBusinessObjectCollection <UnitType> originalCollection = new MassiveBusinessObjectCollection <UnitType>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <UnitType>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.VatRate)
            {
                MassiveBusinessObjectCollection <VatRate> modifiedCollection = new MassiveBusinessObjectCollection <VatRate>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetVatRates();
                MassiveBusinessObjectCollection <VatRate> originalCollection = new MassiveBusinessObjectCollection <VatRate>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <VatRate>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.Warehouse)
            {
                MassiveBusinessObjectCollection <Warehouse> modifiedCollection = new MassiveBusinessObjectCollection <Warehouse>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetVatRates();
                MassiveBusinessObjectCollection <Warehouse> originalCollection = new MassiveBusinessObjectCollection <Warehouse>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <Warehouse>(modifiedCollection, originalCollection);
            }
            else if (boType == BusinessObjectType.ContainerType)
            {
                MassiveBusinessObjectCollection <ContainerType> modifiedCollection = new MassiveBusinessObjectCollection <ContainerType>();
                modifiedCollection.Deserialize((XElement)modifiedXml.Root.FirstNode);

                XDocument originalXml = DictionaryMapper.Instance.GetContainerTypes();
                MassiveBusinessObjectCollection <ContainerType> originalCollection = new MassiveBusinessObjectCollection <ContainerType>();
                originalCollection.Deserialize((XElement)originalXml.Root.FirstNode);

                modifiedCollection.SetAlternateVersion(originalCollection);

                this.SaveMassiveBusinessObjectCollection <ContainerType>(modifiedCollection, originalCollection);
            }
            else
            {
                throw new InvalidOperationException("Unknown dictionary object.");
            }

            return(XDocument.Parse("<root>ok</root>"));
        }