private void LoadAttributeUnits(EAV.Model.IModelAttribute attribute) { bool attributeWasUnmodified = attribute.ObjectState == EAV.Model.ObjectState.Unmodified; HttpResponseMessage response = client.GetAsync(String.Format("api/metadata/attributes/{0}/units", attribute.AttributeID)).Result; if (response.IsSuccessStatusCode) { attribute.Units.Clear(); var units = response.Content.ReadAsAsync <IEnumerable <EAVModelLibrary.ModelUnit> >().Result; foreach (EAVModelLibrary.ModelUnit unit in units) { unit.MarkUnmodified(); attribute.Units.Add(unit); unit.MarkUnmodified(); } if (attributeWasUnmodified) { attribute.MarkUnmodified(); } } else { throw (new ApplicationException("Attempt to get attribute units failed.")); } }
public static EAV.Model.IModelValue Create(EAV.Model.IModelAttribute attribute, EAV.Model.IModelInstance instance) { ModelValue value = new ModelValue() { Attribute = attribute, Instance = instance, }; return(value); }
private void SaveAttribute(EAV.Model.IModelAttribute attribute) { HttpResponseMessage response; if (attribute.ObjectState == EAV.Model.ObjectState.New) { response = client.PostAsJsonAsync <EAV.Store.IStoreAttribute>(String.Format("api/metadata/containers/{0}/attributes", attribute.ContainerID.GetValueOrDefault()), attribute).Result; if (response.IsSuccessStatusCode) { EAVModelLibrary.ModelAttribute newAttribute = response.Content.ReadAsAsync <EAVModelLibrary.ModelAttribute>().Result; attribute.AttributeID = newAttribute.AttributeID; if (!attribute.VariableUnits.GetValueOrDefault(true)) { SaveAttributeUnits(attribute.AttributeID.Value, attribute.Units); } attribute.MarkUnmodified(); } else { throw (new ApplicationException("Attempt to create attribute failed.")); } } else if (attribute.ObjectState == EAV.Model.ObjectState.Modified) { response = client.PatchAsJsonAsync <EAV.Store.IStoreAttribute>("api/metadata/attributes", attribute).Result; if (response.IsSuccessStatusCode) { if (!attribute.VariableUnits.GetValueOrDefault(true)) { SaveAttributeUnits(attribute.AttributeID.Value, attribute.Units); } attribute.MarkUnmodified(); } else { throw (new ApplicationException("Attempt to update attribute failed.")); } } if (attribute.ObjectState == EAV.Model.ObjectState.Deleted) { response = client.DeleteAsync(String.Format("api/metadata/attributes/{0}", attribute.AttributeID.GetValueOrDefault())).Result; if (response.IsSuccessStatusCode) { } else { throw (new ApplicationException("Attempt to delete attribute failed.")); } } }