Beispiel #1
0
        /// <summary>
        /// Validates the Ampla Field Mapping.
        /// </summary>
        /// <returns></returns>
        public IList <string> ValidateMapping(TModel model)
        {
            List <string> messages = new List <string>();

            IAmplaViewProperties <TModel> viewProperties = GetViewProperties(model);

            messages.AddRange(viewProperties.ValidateViewPermissions());

            IEnumerable <FieldMapping> fieldMappings = viewProperties.GetFieldMappings();
            List <string> missingFields = new List <string>(modelProperties.GetProperties());

            foreach (FieldMapping fieldMapping in fieldMappings)
            {
                string field = fieldMapping.Name;
                string message;

                if (!ModelProperties.CanMapField(fieldMapping, out message))
                {
                    messages.Add(message ?? "Error message");
                }

                if (missingFields.Contains(field))
                {
                    missingFields.Remove(field);
                }
            }

            if (missingFields.Count > 0)
            {
                messages.AddRange(missingFields.Select(modelField => string.Format("The property '{0}' is not mapped to an Ampla Field.", modelField)));
            }

            return(messages);
        }
        private List <FieldMapping> BuildFieldResolvers()
        {
            IModuleMapping moduleMapping = ModuleMapping.GetModuleMapping(modelProperties.Module);

            List <FieldMapping> fieldMappings = new List <FieldMapping>();
            List <string>       modelFields   = new List <string>(modelProperties.GetProperties());

            foreach (ViewField field in viewFieldsCollection.GetValues())
            {
                bool isModelProperty = modelFields.Contains(field.DisplayName);

                FieldMapping fieldMapping = moduleMapping.GetFieldMapping(field, isModelProperty);

                if (fieldMapping != null)
                {
                    fieldMappings.Add(fieldMapping);
                }
            }
            return(fieldMappings);
        }