Example #1
0
 public bool CanHandle(HasAndBelongsToManyModel model)
 {
     if (!model.HasManyAtt.Inverse)
     {
         return(CheckModelAndKeyAreAccessible(model.HasManyAtt.MapType));
     }
     return(false);
 }
        public String CreateControl(ActiveRecordModel model, String prefix,
                                    HasAndBelongsToManyModel hasAndBelongsModel, object instance)
        {
            stringBuilder.Length = 0;

            var prop = hasAndBelongsModel.Property;

            prefix += "." + prop.Name;

            var otherModel = ActiveRecordModel.GetModel(hasAndBelongsModel.HasManyAtt.MapType);

            var keyModel = ObtainPKProperty(otherModel);

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

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

            stringBuilder.Append(prop.Name + ":  ");
            stringBuilder.Append("<br/>\r\n");

            IDictionary attrs = new HybridDictionary(true);

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

            var list = CreateCheckboxList(prefix, source, attrs);

            foreach (var item in list)
            {
                stringBuilder.Append(list.Item());

                stringBuilder.Append(item.ToString());

                stringBuilder.Append("<br/>\r\n");
            }

            return(stringBuilder.ToString());
        }
Example #3
0
        public String CreateControl(ActiveRecordModel model, HasAndBelongsToManyModel hasAndBelongsModel, object instance)
        {
            stringBuilder.Length = 0;

            PropertyInfo prop = hasAndBelongsModel.Property;

            ActiveRecordModel otherModel = ActiveRecordModel.GetModel(hasAndBelongsModel.HasManyAtt.MapType);

            PrimaryKeyModel keyModel = ObtainPKProperty(otherModel);

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

            object container = InitializeRelationPropertyIfNull(instance, prop);

            object value = null;

            if (container != null)
            {
                value = CreateArrayFromExistingIds(keyModel, container as ICollection);
            }

            object[] items = CommonOperationUtils.FindAll(otherModel.Type, hasAndBelongsModel.HasManyAtt.Where);

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

            stringBuilder.Append(LabelFor(propName, prop.Name + ": &nbsp;"));
            stringBuilder.Append("<br/>");
            stringBuilder.Append(Select(propName, new DictHelper().CreateDict("size=6", "multiple")));
            stringBuilder.Append(CreateOptionsFromArray(items, null, keyModel.Property.Name, value));
            stringBuilder.Append(EndSelect());

            return(stringBuilder.ToString());
        }