private void SaveChildContainer(EAV.Model.IModelChildContainer container) { HttpResponseMessage response; if (container.ObjectState == EAV.Model.ObjectState.New) { response = client.PostAsJsonAsync <EAV.Store.IStoreContainer>(String.Format("api/metadata/containers/{0}/containers", container.ParentContainerID.GetValueOrDefault()), container).Result; if (response.IsSuccessStatusCode) { EAVModelLibrary.ModelContainer newContainer = response.Content.ReadAsAsync <EAVModelLibrary.ModelChildContainer>().Result; container.ContainerID = newContainer.ContainerID; container.MarkUnmodified(); } else { throw (new ApplicationException("Attempt to create child container failed.")); } } else if (container.ObjectState == EAV.Model.ObjectState.Modified) { response = client.PatchAsJsonAsync <EAV.Store.IStoreContainer>("api/metadata/containers", container).Result; if (response.IsSuccessStatusCode) { } else { throw (new ApplicationException("Attempt to update child container failed.")); } } foreach (EAVModelLibrary.ModelAttribute attribute in container.Attributes) { SaveAttribute(attribute); } foreach (EAVModelLibrary.ModelChildContainer childContainer in container.ChildContainers) { SaveChildContainer(childContainer); } if (container.ObjectState == EAV.Model.ObjectState.Deleted) { response = client.DeleteAsync(String.Format("api/metadata/containers/{0}", container.ContainerID.GetValueOrDefault())).Result; if (response.IsSuccessStatusCode) { } else { throw (new ApplicationException("Attempt to delete child container failed.")); } } }
public static EAV.Model.IModelChildInstance Create(EAV.Model.IModelChildContainer container, EAV.Model.IModelSubject subject, EAV.Model.IModelInstance parentInstance) { ModelChildInstance instance = new ModelChildInstance() { ParentInstance = parentInstance, Container = container, }; foreach (ModelAttribute attribute in container.Attributes) { ModelValue.Create(attribute, instance); } foreach (ModelChildContainer childContainer in container.ChildContainers) { ModelChildInstance.Create(childContainer, subject, instance); } return(instance); }