Esempio n. 1
0
 /// <summary>
 /// Generates the import parameters.
 /// </summary>
 /// <param name="formData">The form data.</param>
 /// <returns>The import parameters.</returns>
 public override ImportParameters GenerateParameters(EntitySchema entitySchema)
 {
     if (FormData == null)
     {
         throw new ArgumentNullException("formData");
     }
     if (FormData.formFieldsData == null)
     {
         throw new ArgumentNullException("formFieldsData");
     }
     Success        = true;
     WebFormId      = GetWebFormId(FormData);
     FormFieldsData = FormData.formFieldsData.ToList();
     if (entitySchema == null)
     {
         Success      = false;
         ErrorMessage = GeneratedWebFormLczUtilities.GetLczStringValue("SchemaNotFoundError",
                                                                       "WebFormImportParamsGenerator", _userConnection);
         return(null);
     }
     ValidateWebForm();
     if (!Success)
     {
         return(null);
     }
     SetDefaultValues();
     return(GenerateParameters(entitySchema, CastFormFieldsDataToDictionary()));
 }
        /// <summary>
        /// Creates entity from landing.
        /// </summary>
        /// <param name="formData">Data from landing.</param>
        /// <param name="entity">Entity onto which data from landing is mapped.</param>
        public void Map(FormData formData, Entity entity)
        {
            Guid webFormId;

            if (!Guid.TryParse(formData.formId, out webFormId))
            {
                Message = GeneratedWebFormLczUtilities
                          .GetLczStringValue("UnknownWebFormIdentifierMessage", "GeneratedWebFormService", UserConnection);
                Success = false;
                return;
            }
            FormFieldsData[] formFieldsData = formData.formFieldsData;
            var formItemValidationResult    = GeneratedWebFormValidator.Validate(webFormId);

            if (!formItemValidationResult.Succes)
            {
                Message = formItemValidationResult.Message;
                Success = false;
                return;
            }
            entity.SetDefColumnValues();
            Dictionary <string, object> defaultValues = DefaultValueManager.GetValues(webFormId, UserConnection);

            foreach (string columnName in defaultValues.Keys)
            {
                entity.SetColumnValue(columnName, defaultValues[columnName]);
            }
            Message += SetColumnsFromFormFieldsData(formFieldsData, entity);
            Success  = true;
        }
        private WebFormSavingResult GetSuccessSavingResult()
        {
            var resultObject = new WebFormSavingResult();

            resultObject.resultMessage = GeneratedWebFormLczUtilities
                                         .GetLczStringValue("DataIsSavedSuccessfullyMessage", "GeneratedObjectWebFormService", UserConnection);
            resultObject.resultCode = 0;
            return(resultObject);
        }
        /// <summary>
        /// Validates landing entity.
        /// </summary>
        /// <param name="webFormId">Identifier of landing.</param>
        /// <returns>Instance of ValidationResult</returns>
        public ValidationResult Validate(Guid webFormId)
        {
            var result = new ValidationResult()
            {
                Succes = true
            };
            EntitySchemaManager entitySchemaManager = UserConnection.EntitySchemaManager;
            EntitySchemaQuery   formESQ             = GetEntityESQ(entitySchemaManager);
            Entity enity = formESQ.GetEntity(UserConnection, webFormId);

            if (enity == null)
            {
                result.Message = GeneratedWebFormLczUtilities
                                 .GetLczStringValue("UnknownWebFormIdentifierMessage", "GeneratedWebFormService", UserConnection);
                result.Succes = false;
                return(result);
            }
            EntitySchemaColumn landingStateColumn = enity.Schema.Columns.GetByName("State");
            Guid landingStateColumnValue          = enity.GetTypedColumnValue <Guid>(landingStateColumn.ColumnValueName);

            if (landingStateColumnValue != EnabledLandingStateCode)
            {
                result.Message = GeneratedWebFormLczUtilities
                                 .GetLczStringValue("LandingDisabledMessage", "GeneratedWebFormService", UserConnection);
                result.Succes = false;
                return(result);
            }
            EntitySchemaColumn externalURLColumn      = enity.Schema.Columns.GetByName("ExternalURL");
            string             externalURLColumnValue = enity.GetTypedColumnValue <string>(externalURLColumn.ColumnValueName);

            if (!CheckExternalURLContainsRequest(externalURLColumnValue))
            {
                result.Message = GeneratedWebFormLczUtilities
                                 .GetLczStringValue("NotAllowedURLMessage", "GeneratedWebFormService", UserConnection);
                result.Succes = false;
                return(result);
            }
            return(result);
        }
        private string SetColumnsFromFormFieldsData(FormFieldsData[] formFieldsData, Entity entity)
        {
            string resultMessage = string.Empty;

            if (formFieldsData != null)
            {
                foreach (FormFieldsData formField in formFieldsData)
                {
                    KeyValuePair <string, string> columnNameValue
                        = NameValueCorrector.GetCorrectNameValue(formField.name, formField.value);
                    string columnName  = columnNameValue.Key;
                    string columnValue = columnNameValue.Value;
                    if (string.IsNullOrEmpty(columnValue))
                    {
                        continue;
                    }
                    EntitySchemaColumn column = entity.Schema.Columns.GetByName(columnName);
                    Type columnType           = column.DataValueType.ValueType;
                    if (column.IsLookupType)
                    {
                        SetLookupColumn(column, columnValue, entity);
                    }
                    else
                    {
                        try {
                            if (WebFormHelper.IsGeographicalColumn(columnName))
                            {
                                KeyValuePair <string, string> geogColumn =
                                    WebFormHelper.GetGeographicalUnitColumn(columnName, columnValue, UserConnection);
                                entity.SetColumnValue(geogColumn.Key, geogColumn.Value);
                            }
                            else
                            {
                                object value = DataTypeUtilities.ValueAsType(columnValue, columnType);
                                entity.SetColumnValue(column, value);
                            }
                        } catch (Exception ex) {
                            resultMessage += Environment.NewLine;
                            string errorMessage;
                            if (ex is FormatException)
                            {
                                errorMessage = GeneratedWebFormLczUtilities.GetLczStringValue(
                                    "FormatExceptionMessage", "GeneratedWebFormService", UserConnection);
                            }
                            else if (ex is OverflowException)
                            {
                                errorMessage = GeneratedWebFormLczUtilities.GetLczStringValue(
                                    "OverflowExceptionMessage", "GeneratedWebFormService", UserConnection);
                            }
                            else
                            {
                                errorMessage = GeneratedWebFormLczUtilities.GetLczStringValue(
                                    "ConversionExceptionMessage", "GeneratedWebFormService", UserConnection);
                            }
                            resultMessage += string.Format(errorMessage, formField.value, columnType);
                        }
                    }
                }
            }
            return(resultMessage);
        }