示例#1
0
        public static ViewModelInstance Create(IModelContainer container, IModelSubject subject, IModelInstance instance, ViewModelInstance parentInstance, ref int nextInstanceID)
        {
            ViewModelInstance viewInstance = new ViewModelInstance()
            {
                ObjectState = instance != null ? instance.ObjectState : ObjectState.New, ContainerID = container.ContainerID, SubjectID = subject != null ? subject.SubjectID : 0, InstanceID = instance != null ? instance.InstanceID : nextInstanceID--, ParentInstanceID = parentInstance != null ? parentInstance.InstanceID : null
            };

            foreach (EAV.Model.IModelAttribute attribute in container.Attributes.OrderBy(it => it.Sequence))
            {
                viewInstance.Values.Add(ViewModelAttributeValue.Create(attribute, instance != null ? instance.Values.SingleOrDefault(it => it.AttributeID == attribute.AttributeID) : null));
            }

            foreach (IModelChildContainer childContainer in container.ChildContainers.OrderBy(it => it.Sequence))
            {
                viewInstance.ChildContainers.Add(ViewModelContainer.Create(childContainer, subject, viewInstance, ref nextInstanceID));
            }

            return(viewInstance);
        }
示例#2
0
        public static ViewModelContainer Create(IModelChildContainer container, IModelSubject subject, ViewModelInstance parentInstance, ref int nextInstanceID)
        {
            ViewModelContainer viewContainer = new ViewModelContainer()
            {
                ContainerID = container.ContainerID, ParentContainerID = container.ParentContainerID, DisplayText = container.DisplayText, IsRepeating = container.IsRepeating
            };

            foreach (IModelInstance instance in container.Instances.Where(it => it.ParentInstanceID == parentInstance.InstanceID))
            {
                ViewModelInstance viewInstance = ViewModelInstance.Create(container, subject, instance, parentInstance, ref nextInstanceID);

                viewContainer.Instances.Add(viewInstance);
            }

            if (container.IsRepeating || !viewContainer.Instances.Any())
            {
                ViewModelInstance viewInstance = ViewModelInstance.Create(container, subject, null, parentInstance, ref nextInstanceID);

                viewContainer.Instances.Add(viewInstance);
            }

            return(viewContainer);
        }