public MemberViewModel Build(Member member, Object @object, int? objectId = null)
        {
            IEnumerable<RelationViewModel> relations = null;
              PropertyViewModel property = null;

              if (member.RelationClassId != null)
              {
            if (@object == null && objectId == null)
              relations = new RelationViewModel[] { };

            else if (@object == null && objectId != null)
              relations = new RelationViewModel[] { new RelationViewModel() { PrimaryId = (int)objectId } };

            else relations = this.handler.Storage.GetRepository<IRelationRepository>().FilteredByMemberIdAndForeignId(member.Id, @object.Id).Select(
              r => new RelationViewModelBuilder(this.handler).Build(r)
            );
              }

              else if (member.PropertyDataTypeId != null)
              {
            if (@object == null)
              property = new PropertyViewModelBuilder(this.handler).Build(
            new Property() { ObjectId = @object == null ? (int?)null : @object.Id  }
              );

            else
            {
              Property p = this.handler.Storage.GetRepository<IPropertyRepository>().WithObjectIdAndMemberId(@object.Id, member.Id);

              property = new PropertyViewModelBuilder(this.handler).Build(
            p == null ? new Property() { ObjectId = @object == null ? (int?)null : @object.Id } : p
              );
            }
              }

              return new MemberViewModel()
              {
            Id = member.Id,
            RelationClass = member.RelationClassId == null ? null : new ClassViewModelBuilder(this.handler).Build(
              this.handler.Storage.GetRepository<IClassRepository>().WithKey((int)member.RelationClassId)
            ),
            IsRelationSingleParent = member.IsRelationSingleParent == true,
            Relations = relations,
            PropertyDataType = member.PropertyDataTypeId == null ? null : new DataTypeViewModelBuilder(this.handler).Build(
              this.handler.Storage.GetRepository<IDataTypeRepository>().WithKey((int)member.PropertyDataTypeId)
            ),
            Property = property,
            Name = member.Name,
            Position = member.Position
              };
        }
Example #2
0
        public MemberViewModel Build(Member member, Object @object, int?objectId = null)
        {
            IEnumerable <RelationViewModel> relations = null;
            PropertyViewModel property = null;

            if (member.RelationClassId != null)
            {
                if (@object == null && objectId == null)
                {
                    relations = new RelationViewModel[] { }
                }
                ;

                else if (@object == null && objectId != null)
                {
                    relations = new RelationViewModel[] { new RelationViewModel()
                                                          {
                                                              PrimaryId = (int)objectId
                                                          } }
                }
                ;

                else
                {
                    relations = this.handler.Storage.GetRepository <IRelationRepository>().FilteredByMemberIdAndForeignId(member.Id, @object.Id).Select(
                        r => new RelationViewModelBuilder(this.handler).Build(r)
                        );
                }
            }

            else if (member.PropertyDataTypeId != null)
            {
                if (@object == null)
                {
                    property = new PropertyViewModelBuilder(this.handler).Build(
                        new Property()
                    {
                        ObjectId = @object == null ? (int?)null : @object.Id
                    }
                        );
                }

                else
                {
                    Property p = this.handler.Storage.GetRepository <IPropertyRepository>().WithObjectIdAndMemberId(@object.Id, member.Id);

                    property = new PropertyViewModelBuilder(this.handler).Build(
                        p == null ? new Property()
                    {
                        ObjectId = @object == null ? (int?)null : @object.Id
                    } : p
                        );
                }
            }

            return(new MemberViewModel()
            {
                Id = member.Id,
                RelationClass = member.RelationClassId == null ? null : new ClassViewModelBuilder(this.handler).Build(
                    this.handler.Storage.GetRepository <IClassRepository>().WithKey((int)member.RelationClassId)
                    ),
                IsRelationSingleParent = member.IsRelationSingleParent == true,
                Relations = relations,
                PropertyDataType = member.PropertyDataTypeId == null ? null : new DataTypeViewModelBuilder(this.handler).Build(
                    this.handler.Storage.GetRepository <IDataTypeRepository>().WithKey((int)member.PropertyDataTypeId)
                    ),
                Property = property,
                Name = member.Name,
                Position = member.Position
            });
        }