public IViewModel Create(IViewModel item) { var viewItem = (TableViewModel)item; List <IEntity> attributeList; attributeList = new List <IEntity>(); var tableModel = ModelFactory.CreateTable(viewItem.Name); RepositoryFactory.CreateTableRepository().Create(ref tableModel); foreach (var viewItemAttribute in viewItem.Attributes) { var attributeModel = ModelFactory.CreateAttribute(viewItemAttribute); RepositoryFactory.CreateAttributeRepository().Create(ref attributeModel); var tableAttributeModel = ModelFactory.CreateTableAttribute(tableModel, attributeModel); RepositoryFactory.CreateTableAttributeRepository().Create(ref tableAttributeModel); attributeList.Add(attributeModel); } foreach (var dependencyViews in viewItem.Dependencies) { var functionalDependency = ModelFactory.CreateFunctionalDependency(); RepositoryFactory.CreateFunctionalDependencyRepository().Create(ref functionalDependency); var tableAttributesFrom = new List <IEntity>(); var tableAttributesTo = new List <IEntity>(); tableAttributesFrom.AddRange(dependencyViews.From.Select(attributeCollection => RepositoryFactory.CreateTableAttributeRepository().GetByNameAndTableId(attributeCollection, tableModel.Id))); tableAttributesTo.Add(RepositoryFactory.CreateTableAttributeRepository().GetByNameAndTableId(dependencyViews.To, tableModel.Id)); var attributeCollectionModel = ModelFactory.CreateAttributeCollection(); foreach (var entity in tableAttributesFrom) { RepositoryFactory.CreateAttributeCollectionRepository().Create(ref attributeCollectionModel); var tableAttributeCollectionFrom = (TableAttributeCollection)ModelFactory.CreateTableAttributeCollection(); tableAttributeCollectionFrom.TableAttribute = (TableAttribute)entity; tableAttributeCollectionFrom.AttributeCollection = (AttributeCollection)attributeCollectionModel; var tableAttributeCollectionFormIEntity = (IEntity)tableAttributeCollectionFrom; RepositoryFactory.CreateTableAttributeCollectionRepository().Create(ref tableAttributeCollectionFormIEntity); RepositoryFactory.CreateDependencyElementRepository() .CreateWithAttributeCollection(true, attributeCollectionModel, functionalDependency); } foreach (var entity in tableAttributesTo) { RepositoryFactory.CreateAttributeCollectionRepository().Create(ref attributeCollectionModel); var tableAttributeCollectionFrom = (TableAttributeCollection)ModelFactory.CreateTableAttributeCollection(); tableAttributeCollectionFrom.TableAttribute = (TableAttribute)entity; tableAttributeCollectionFrom.AttributeCollection = (AttributeCollection)attributeCollectionModel; var tableAttributeCollectionFormIEntity = (IEntity)tableAttributeCollectionFrom; RepositoryFactory.CreateTableAttributeCollectionRepository().Create(ref tableAttributeCollectionFormIEntity); RepositoryFactory.CreateDependencyElementRepository() .CreateWithAttributeCollection(false, attributeCollectionModel, functionalDependency); } } foreach (var keyGroupsView in viewItem.Keys) { var tableAttributeList = keyGroupsView.Select(keyGroupString => RepositoryFactory.CreateTableAttributeRepository().GetByNameAndTableId(keyGroupString, tableModel.Id)).ToList(); var keyGroupModel = (KeyGroup)ModelFactory.CreateKeyGroup(); var attributeCollectionModel = ModelFactory.CreateAttributeCollection(); RepositoryFactory.CreateAttributeCollectionRepository().Create(ref attributeCollectionModel); keyGroupModel.AttributeCollection = (AttributeCollection)attributeCollectionModel; var keyGroupIEntity = (IEntity)keyGroupModel; RepositoryFactory.CreateKeyGroupRepository().Create(ref keyGroupIEntity); foreach (var tableAttribute in tableAttributeList) { var tableAttributeCollectionModel = (TableAttributeCollection)ModelFactory.CreateTableAttributeCollection(); tableAttributeCollectionModel.AttributeCollection = (AttributeCollection)attributeCollectionModel; tableAttributeCollectionModel.TableAttribute = ((TableAttribute)tableAttribute); var tableAttributeCollectionModelIEntity = (IEntity)tableAttributeCollectionModel; RepositoryFactory.CreateTableAttributeCollectionRepository().Create(ref tableAttributeCollectionModelIEntity); } } return(ReadFromId(tableModel.Id)); }