Пример #1
0
        private void LoadChildInstances(EAV.Model.IModelInstance parentInstance, IEnumerable <EAV.Model.IModelContainer> containers)
        {
            bool ifParentInstanceWasUnmodified             = parentInstance.ObjectState == EAV.Model.ObjectState.Unmodified;
            Dictionary <int?, bool> containerWasUnmodified = containers.ToDictionary(key => key.ContainerID, val => val.ObjectState == EAV.Model.ObjectState.Unmodified);

            HttpResponseMessage response = client.GetAsync(String.Format("api/data/instances/{0}/instances", parentInstance.InstanceID.GetValueOrDefault())).Result;

            if (response.IsSuccessStatusCode)
            {
                parentInstance.ChildInstances.Clear();

                var childInstances = response.Content.ReadAsAsync <IEnumerable <EAVModelLibrary.ModelChildInstance> >().Result;
                foreach (EAVModelLibrary.ModelChildInstance childInstance in childInstances)
                {
                    childInstance.MarkUnmodified();

                    EAV.Model.IModelContainer container = containers.Single(it => it.ContainerID == childInstance.ContainerID);

                    childInstance.Container = container;

                    if (container.Attributes.Any())
                    {
                        LoadValues(childInstance, container.Attributes);
                    }

                    if (container.ChildContainers.Any())
                    {
                        LoadChildInstances(childInstance, container.ChildContainers);
                    }

                    parentInstance.ChildInstances.Add(childInstance);

                    childInstance.MarkUnmodified();
                }

                if (ifParentInstanceWasUnmodified)
                {
                    parentInstance.MarkUnmodified();
                }

                foreach (var container in containers)
                {
                    if (containerWasUnmodified[container.ContainerID])
                    {
                        container.MarkUnmodified();
                    }
                }
            }
            else
            {
                throw (new ApplicationException("Attempt to get child instances failed."));
            }
        }
Пример #2
0
        private void LoadValues(EAV.Model.IModelInstance instance, IEnumerable <EAV.Model.IModelAttribute> attributes)
        {
            bool instanceWasUnmodified = instance.ObjectState == EAV.Model.ObjectState.Unmodified;
            Dictionary <int?, bool> attributeWasUnmodified = attributes.ToDictionary(key => key.AttributeID, val => val.ObjectState == EAV.Model.ObjectState.Unmodified);

            HttpResponseMessage response = client.GetAsync(String.Format("api/data/instances/{0}/values", instance.InstanceID.GetValueOrDefault())).Result;

            if (response.IsSuccessStatusCode)
            {
                instance.Values.Clear();

                var values = response.Content.ReadAsAsync <IEnumerable <EAVModelLibrary.ModelValue> >().Result;
                foreach (EAVModelLibrary.ModelValue value in values)
                {
                    //value.MarkUnmodified();

                    value.Attribute = attributes.Single(it => it.AttributeID == value.AttributeID);

                    if (value.UnitID != null)
                    {
                        LoadValueUnit(value);
                    }

                    instance.Values.Add(value);

                    value.MarkUnmodified();
                }

                if (instanceWasUnmodified)
                {
                    instance.MarkUnmodified();
                }

                foreach (var attribute in attributes)
                {
                    if (attributeWasUnmodified[attribute.AttributeID])
                    {
                        attribute.MarkUnmodified();
                    }
                }
            }
            else
            {
                throw (new ApplicationException("Attempt to get values failed."));
            }
        }
Пример #3
0
        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);
        }
Пример #4
0
        public static EAV.Model.IModelValue Create(EAV.Model.IModelAttribute attribute, EAV.Model.IModelInstance instance)
        {
            ModelValue value = new ModelValue()
            {
                Attribute = attribute,
                Instance  = instance,
            };

            return(value);
        }