protected override void InitializeData(FormTemplateFieldDefinition fieldDef, object data = null, IHasLookup referenceDataRepo = null) { base.InitializeData(fieldDef, data, referenceDataRepo); if (data != null) { return; } if (fieldDef.Items != null && fieldDef.Items.Count > 0) { this.CopyCollection(this.Items, fieldDef.Items); return; } if (string.IsNullOrEmpty(fieldDef.Reference)) { return; } // Get the collection from the reference data repo IReferenceDataResolver referenceDataResolver = new ReferenceDataResolver(); object collection = referenceDataResolver.Resolve(fieldDef.Reference, referenceDataRepo); this.CopyCollection(this.Items, collection); }
protected override void InitializeValidations(FormTemplateFieldDefinition fieldDef) { // Set up the validations if (fieldDef.Validation.Required) { this.ValidationRules.Add(ValidatorFactory.Create("Required")); } if (fieldDef.Validation.Length.HasValue && fieldDef.Validation.Length != 0) { this.ValidationRules.Add(ValidatorFactory.Create("Length", fieldDef.Validation.Length.Value)); } if (fieldDef.Validation.MinLength.HasValue && fieldDef.Validation.MinLength != 0) { this.ValidationRules.Add(ValidatorFactory.Create("MinLength", fieldDef.Validation.MinLength.Value)); } if (fieldDef.Validation.MaxLength.HasValue && fieldDef.Validation.MaxLength != 0) { this.ValidationRules.Add(ValidatorFactory.Create("MaxLength", fieldDef.Validation.MaxLength.Value)); } if (!string.IsNullOrEmpty(fieldDef.Validation.RegEx)) { this.ValidationRules.Add(ValidatorFactory.Create("RegEx", fieldDef.Validation.RegEx)); } base.InitializeValidations(fieldDef); }
protected override void InitializeValidations(FormTemplateFieldDefinition fieldDef) { base.InitializeValidations(fieldDef); // Set up the validations this.ValidationRules.Add(ValidatorFactory.Create("RegEx", @"^(\+|-)?\d+$")); }
protected override void InitializeValidations(FormTemplateFieldDefinition fieldDef) { base.InitializeValidations(fieldDef); // Set up the validations // http://regexlib.com/REDetails.aspx?regexp_id=70 this.ValidationRules.Add(ValidatorFactory.Create("RegEx", @"^\$?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(.[0-9][0-9])?$")); }
protected override void InitializeData(FormTemplateFieldDefinition fieldDef, object data = null, IHasLookup referenceDataRepo = null) { this.GroupName = this.GetProp <string>("groupname") ?? IdGenerators.FieldId(); this.EndingFieldName = this.GetProp <string>("end"); this.FieldInstanceSuffix = this.GetProp <string>("suffix") ?? "${index}"; this.ContinueLoopValue = this.GetProp("continuevalue") ?? true; base.InitializeData(fieldDef, data, referenceDataRepo); }
protected override void InitializeValidations(FormTemplateFieldDefinition fieldDef) { // Set up the validations if (fieldDef.Validation.Required) { this.ValidationRules.Add(ValidatorFactory.Create("Required")); } base.InitializeValidations(fieldDef); }
protected override void InitializeValidations(FormTemplateFieldDefinition fieldDef) { base.InitializeValidations(fieldDef); // Set up the validations var validator = ValidatorFactory.Create("RegEx", @"^[\w-]+@([\w-]+\.)+[\w-]+$"); validator.ValidationFailedMessage = "This is not a valid email address"; this.ValidationRules.Add(validator); }
protected override void InitializeValidations(FormTemplateFieldDefinition fieldDef) { base.InitializeValidations(fieldDef); // Set up the validations // http://regexlib.com/REDetails.aspx?regexp_id=808 this.ValidationRules.Add(ValidatorFactory.Create("RegEx", @"^(?:(?:0?[13578]|1[02])|(?:0?[469]|11)(?!\/31)|(?:0?2)(?:(?!\/3[01]|\/29\/(?:(?:0[^48]|[13579][^26]|[2468][^048])00|(?:\d{2}(?:0[^48]|[13579][^26]|[2468][^048]))))))\/(?:0?[1-9]|[12][0-9]|3[01])\/\d{4}$")); if (this.GetProp <bool>("calendar")) { this.IsCalendar = true; } }
protected override void InitializeValidations(FormTemplateFieldDefinition fieldDef) { base.InitializeValidations(fieldDef); // Set up the validations // http://regexlib.com/REDetails.aspx?regexp_id=58 const string regex = @"^(\(?\d{3}\)?|\d{3})( |-)?(\d{3}( |-)?\d{4}|\d{7})$"; var validator = ValidatorFactory.Create("RegEx", regex); validator.ValidationFailedMessage = "This is not a valid phone number"; this.ValidationRules.Add(validator); }
private void AddFormTemplateField(FormTemplateFieldVM item, int formTemplateId, DateTime dateTime, int labelFieldCounter) { var dataTypeName = formTemplateFieldService.GetDataType(item.ControlType); FormTemplateFieldDefinition formTemplateFieldDefinition = new FormTemplateFieldDefinition(); formTemplateFieldDefinition.FormTemplateId = formTemplateId; formTemplateFieldDefinition.GUID = item.Guid; formTemplateFieldDefinition.ControlType = item.ControlType; formTemplateFieldDefinition.LabelFieldName = item.LabelFieldName; formTemplateFieldDefinition.SortOrder = item.SortOrder; formTemplateFieldDefinition.FieldName = "FlexField" + labelFieldCounter; formTemplateFieldDefinition.DateCreated = dateTime; formTemplateFieldDefinition.DataTypeId = dataTypeService.Load(x => x.Name == dataTypeName).Select(x => x.DataTypeId).FirstOrDefault(); formTemplateFieldService.Add(formTemplateFieldDefinition); }
public ActionResult Create(FormTemplateDetailsVM formTemplate) { JsonResult jsonResult = new JsonResult(); if (!formTemplateService.CheckDuplicate(formTemplate.Name, formTemplate.Guid)) { FormTemplate formTemplateDB = formTemplateService.Load(x => x.DateDeleted == null && x.GUID == formTemplate.Guid).FirstOrDefault(); if (formTemplateDB == null) { FormTemplate formTemplateNew = new FormTemplate(); formTemplateNew.Name = formTemplate.Name; formTemplateNew.GUID = formTemplate.Guid; formTemplateNew.DateCreated = DateTime.Now; formTemplateService.Add(formTemplateNew); formTemplateService.Save(); int newFormTemplateId = formTemplateNew.FormTemplateId; int labelFieldCounter = 0; foreach (var item in formTemplate.FormTemplateFields) { labelFieldCounter++; AddFormTemplateField(item, newFormTemplateId, formTemplateNew.DateCreated, labelFieldCounter); } formTemplateFieldService.Save(); jsonResult.Data = new { Success = "true", Message = "FormTemplate Created successfully" }; return(jsonResult); } else { DateTime currentDate = DateTime.Now; int formTemplateId = formTemplateService.Load(x => x.DateDeleted == null && x.GUID == formTemplate.Guid).Select(x => x.FormTemplateId).FirstOrDefault(); formTemplateDB.Name = formTemplate.Name; formTemplateDB.DateModfied = currentDate; //formTemplateService.Update(formTemplateDB); formTemplateService.Save(); List <int> existingIds = formTemplateFieldService.Load(x => x.DateDeleted == null && x.FormTemplateId == formTemplateId).Select(x => x.FormTemplateFieldDefinitionId).ToList(); List <string> guids = formTemplate.FormTemplateFields.Select(x => x.Guid).ToList(); List <int> updatedIds = formTemplateFieldService.Load(x => guids.Contains(x.GUID)).Select(x => x.FormTemplateFieldDefinitionId).ToList(); List <int> deletedIds = existingIds.Except(updatedIds).ToList(); int labelFieldCounter = formTemplateFieldService.Load(x => x.FormTemplateId == formTemplateId).Count(); foreach (var item in formTemplate.FormTemplateFields) { FormTemplateFieldDefinition formTemplateFieldDefinitionDB = formTemplateFieldService.Load(x => x.DateDeleted == null && x.GUID == item.Guid).FirstOrDefault(); if (formTemplateFieldDefinitionDB != null) { formTemplateFieldDefinitionDB.LabelFieldName = item.LabelFieldName; formTemplateFieldDefinitionDB.SortOrder = item.SortOrder; formTemplateFieldDefinitionDB.DateModfied = currentDate; //formTemplateFieldService.Update(formTemplateFieldDefinitionDB); } else { labelFieldCounter++; AddFormTemplateField(item, formTemplateId, currentDate, labelFieldCounter); } } foreach (var item in deletedIds) { FormTemplateFieldDefinition formTemplateFieldDefinitionDB = formTemplateFieldService.Load(x => x.DateDeleted == null && x.FormTemplateFieldDefinitionId == item).FirstOrDefault(); formTemplateFieldDefinitionDB.DateDeleted = currentDate; } formTemplateFieldService.Save(); jsonResult.Data = new { Success = "true", Message = "FormTemplate updated Successfully" }; return(jsonResult); } } else { jsonResult.Data = new { Success = "false", Message = "FormTemplate with given name already exists" }; return(jsonResult); } }