Example #1
0
        private void SetModel()
        {
            if (Entity != null && GenericManager != null)
            {
                GenericFormModel model = new GenericFormModel(string.Empty);
                foreach (var item in Entity.Attributes)
                {
                    var type         = GetTypeFromAttribute(item);
                    var defaultValue = InitialValues != null && InitialValues.ContainsKey(item.LogicalName)
                            ? InitialValues[item.LogicalName]
                            : null;

                    var attribute = new GenericFormInputModel()
                    {
                        Key          = item.LogicalName,
                        DisplayName  = item.DisplayName,
                        Description  = item.Description,
                        IsMandatory  = item.IsMandatory,
                        DefaultValue = defaultValue,
                        Type         = type,
                    };
                    if (type == GenericFormInputModel.TypeValue.EntityReference)
                    {
                        var relatedEntity = Relationships.First(k => k.RelatedEntity == Entity.LogicalName && k.RelatedAttribute == attribute.Key);
                        attribute.EntityReferenceSuggestionHandler =
                            new EntityReferenceHandler(relatedEntity.MainEntity, GenericManager.RetrieveAllHandler, GenericManager.RetrieveHandler);
                    }
                    else if (type == GenericFormInputModel.TypeValue.OptionSet)
                    {
                        attribute.OptionSetValueOptions = item.Options.Select(k => new DD.Lab.Wpf.Models.Inputs.OptionSetValue()
                        {
                            DisplayName = k.DisplayName,
                            Value       = k.Value
                        }).ToArray();
                    }
                    else if (type == GenericFormInputModel.TypeValue.State)
                    {
                        var options = new List <DD.Lab.Wpf.Models.Inputs.OptionSetValue>();
                        options.Add(new DD.Lab.Wpf.Models.Inputs.OptionSetValue()
                        {
                            DisplayName = "Enabled", Value = 1
                        });
                        options.Add(new DD.Lab.Wpf.Models.Inputs.OptionSetValue()
                        {
                            DisplayName = "Disabled", Value = 0
                        });
                        attribute.OptionSetValueOptions = options.ToArray();
                    }
                    model.Attributes.Add(attribute);
                }
                FormModel = model;
            }
        }