예제 #1
0
        /// <summary>
        /// Maps the parent/child relationship
        /// </summary>
        /// <param name="model">Model that contains the relationship</param>
        public override void VisitBelongsTo(BelongsToModel model)
        {
            if (model.BelongsToAtt.Column == null)
            {
                string message = String.Format("BelongsTo missing column parameter in class {0} and property {1}",
                                               model.Property.DeclaringType.FullName, model.Property);

                throw new ArgumentException(message);
            }

            Type child = model.Property.ReflectedType;

            // Get the table and column that is mapped
            AptifyTableMetadata table = this.mappings.GetTableMetadata(child);

            AptifyColumnMetadata column;

            if (!table.Columns.TryGetValue(model.BelongsToAtt.Column, out column))
            {
                throw new InvalidOperationException(
                          String.Format("Could not find column {0} in {1}", model.BelongsToAtt.Column,
                                        model.Property.DeclaringType.FullName));
            }

            // Remove the old name
            table.Columns.Remove(column.Name);

            // Reinsert with the updated property name
            table.Columns[model.Property.Name] = column;

            base.VisitBelongsTo(model);
        }
예제 #2
0
        public String CreateControl(ActiveRecordModel model, BelongsToModel belongsToModel, object instance)
        {
            stringBuilder.Length = 0;

            PropertyInfo prop = belongsToModel.Property;

            ActiveRecordModel otherModel = ActiveRecordModel.GetModel(belongsToModel.BelongsToAtt.Type);

            PrimaryKeyModel keyModel = ObtainPKProperty(otherModel);

            if (otherModel == null || keyModel == null)
            {
                return("Model not found or PK not found");
            }

            object[] items = CommonOperationUtils.FindAll(otherModel.Type);

            String propName = String.Format("{0}.{1}", prop.Name, keyModel.Property.Name);

            object value = null;

            if (instance != null)
            {
                if (model.IsNestedType)
                {
                    instance = model2nestedInstance[model];
                }

                if (instance != null)
                {
                    value = prop.GetValue(instance, null);
                }
            }

            stringBuilder.Append(LabelFor(propName, prop.Name + ": &nbsp;"));

            stringBuilder.Append(Select(propName));

            if (!belongsToModel.BelongsToAtt.NotNull)
            {
                stringBuilder.Append(CreateOption("Empty", 0));
            }

            stringBuilder.Append(CreateOptionsFromArray(items, null, keyModel.Property.Name, value));

            stringBuilder.Append(EndSelect());

            return(stringBuilder.ToString());
        }
예제 #3
0
        public String CreateControl(ActiveRecordModel model, String prefix,
                                    BelongsToModel belongsToModel, object instance)
        {
            stringBuilder.Length = 0;

            var prop = belongsToModel.Property;

            prefix += "." + prop.Name;

            var otherModel = ActiveRecordModel.GetModel(belongsToModel.BelongsToAtt.Type);

            var keyModel = ObtainPKProperty(otherModel);

            if (otherModel == null || keyModel == null)
            {
                return("Model not found or PK not found");
            }

            var items = CommonOperationUtils.FindAll(otherModel.Type);

            var propName = CreatePropName(model, prefix, keyModel.Property.Name);

            stringBuilder.Append(LabelFor(propName, TextHelper.PascalCaseToWord(prop.Name) + ": &nbsp;"));

            IDictionary attrs = new HybridDictionary(true);

            attrs["value"] = keyModel.Property.Name;

            if (!belongsToModel.BelongsToAtt.NotNull)
            {
                attrs.Add("firstOption", "Empty");
                attrs.Add("firstOptionValue", "");
            }

            stringBuilder.Append(Select(propName, items, attrs));

            return(stringBuilder.ToString());
        }
예제 #4
0
 public bool CanHandle(BelongsToModel model)
 {
     return(CheckModelAndKeyAreAccessible(model.BelongsToAtt.Type));
 }