public static void Run() { // ExStart:1 PdfApi pdfApi = new PdfApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH); StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH); String fileName = "sample-field.pdf"; String fieldName = "textbox1"; String storage = ""; String folder = ""; try { // Upload source file to aspose cloud storage storageApi.PutCreate(fileName, "", "", System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName)); // Invoke Aspose.PDF Cloud SDK API to get particular field FieldResponse apiResponse = pdfApi.GetField(fileName, fieldName, storage, folder); if (apiResponse != null && apiResponse.Status.Equals("OK")) { Field field = apiResponse.Field; Console.WriteLine("Name" + field.Name); Console.WriteLine("Value" + field.Values[0]); Console.ReadKey(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace); } // ExEnd:1 }
public void Pdf_Fields_Tests() { try { #region Create and single update field storageService.File.CopyFile(Utils.CloudStorage_Input_Folder + "/pdf-sample1.pdf", Utils.CloudStorage_Output_Folder + "/pdf-fields.pdf"); Field field = new Field(); field.Name = "checkBoxField2"; field.Type = "Boolean"; field.Values.Add("Signature22"); field.Rect = new Rectangle(50, 50, 100, 100); pdfService.Fields.CreateField("pdf-fields.pdf", 1, field, Utils.CloudStorage_Output_Folder); FieldResponse fieldResponse = pdfService.Fields.GetDocumentFieldByName("pdf-fields.pdf", "checkBoxField2", Utils.CloudStorage_Output_Folder); fieldResponse.Field.Values.RemoveAt(0); fieldResponse.Field.Values.Add("1"); pdfService.Fields.UpdateField("pdf-fields.pdf", "checkBoxField2", fieldResponse.Field, Utils.CloudStorage_Output_Folder); #endregion Create and update field storageService.File.CopyFile(Utils.CloudStorage_Input_Folder + "/pdf-sample1.pdf", Utils.CloudStorage_Output_Folder + "/pdf-fields.pdf"); Field field2 = new Field(); field2.Name = "checkBoxField1"; field2.Type = "Boolean"; field2.Values.Add("0"); field2.Rect = new Rectangle(200, 200, 50, 50); pdfService.Fields.CreateField("pdf-fields.pdf", 1, field2, Utils.CloudStorage_Output_Folder); field2.Name = "text1"; field2.Type = "text"; field2.Rect = new Rectangle(300, 300, 200, 25); pdfService.Fields.CreateField("pdf-fields.pdf", 1, field2, Utils.CloudStorage_Output_Folder); FieldsResponse fieldsResponse = pdfService.Fields.GetDocumentFields("pdf-fields.pdf", Utils.CloudStorage_Output_Folder); fieldsResponse.Fields.List[0].Values.RemoveAt(0); fieldsResponse.Fields.List[1].Values.RemoveAt(0); fieldsResponse.Fields.List[0].Values.Add("1"); fieldsResponse.Fields.List[1].Values.Add("some dummy text"); pdfService.Fields.UpdateFields("pdf-fields.pdf", fieldsResponse.Fields, Utils.CloudStorage_Output_Folder); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public IActionResult OnPost() { if (!ModelState.IsValid) { throw new Exception("Antiforgery check failed."); } var initResult = Init(); if (initResult != null) { return(initResult); } InitPage(); if (ErpEntity == null || Field == null) { return(NotFound()); } if (String.IsNullOrWhiteSpace(ReturnUrl)) { ReturnUrl = $"/sdk/objects/entity/r/{ErpEntity.Id}/rl/fields/l"; } var entMan = new EntityManager(); try { var response = new FieldResponse(); response = entMan.DeleteField(ErpEntity.Id, Field.Id); if (!response.Success) { var exception = new ValidationException(response.Message); exception.Errors = response.Errors.MapTo <ValidationError>(); throw exception; } return(Redirect(ReturnUrl)); } catch (ValidationException ex) { Validation.Message = ex.Message; Validation.Errors = ex.Errors; } catch (Exception ex) { Validation.Message = ex.Message; Validation.Errors.Add(new ValidationError("", ex.Message, isSystem: true)); } HeaderToolbar.AddRange(AdminPageUtils.GetEntityAdminSubNav(ErpEntity, "fields")); ErpRequestContext.PageContext = PageContext; BeforeRender(); return(Page()); }
public IActionResult PatchField(string Id, string FieldId, [FromBody]JObject submitObj) { FieldResponse response = new FieldResponse(); Entity entity = new Entity(); InputField field = new InputGuidField(); try { Guid entityId; if (!Guid.TryParse(Id, out entityId)) { response.Errors.Add(new ErrorModel("Id", Id, "id parameter is not valid Guid value")); return DoBadRequestResponse(response, "Field was not updated!"); } Guid fieldId; if (!Guid.TryParse(FieldId, out fieldId)) { response.Errors.Add(new ErrorModel("FieldId", FieldId, "FieldId parameter is not valid Guid value")); return DoBadRequestResponse(response, "Field was not updated!"); } DbEntity storageEntity = DbContext.Current.EntityRepository.Read(entityId); if (storageEntity == null) { response.Errors.Add(new ErrorModel("Id", Id, "Entity with such Id does not exist!")); return DoBadRequestResponse(response, "Field was not updated!"); } entity = storageEntity.MapTo<Entity>(); Field updatedField = entity.Fields.FirstOrDefault(f => f.Id == fieldId); if (updatedField == null) { response.Errors.Add(new ErrorModel("FieldId", FieldId, "Field with such Id does not exist!")); return DoBadRequestResponse(response, "Field was not updated!"); } FieldType fieldType = FieldType.GuidField; var fieldTypeProp = submitObj.Properties().SingleOrDefault(k => k.Name.ToLower() == "fieldtype"); if (fieldTypeProp != null) { fieldType = (FieldType)Enum.ToObject(typeof(FieldType), fieldTypeProp.Value.ToObject<int>()); } else { response.Errors.Add(new ErrorModel("fieldType", null, "fieldType is required!")); return DoBadRequestResponse(response, "Field was not updated!"); } Type inputFieldType = InputField.GetFieldType(fieldType); foreach (var prop in submitObj.Properties()) { int count = inputFieldType.GetProperties().Where(n => n.Name.ToLower() == prop.Name.ToLower()).Count(); if (count < 1) response.Errors.Add(new ErrorModel(prop.Name, prop.Value.ToString(), "Input object contains property that is not part of the object model.")); } if (response.Errors.Count > 0) return DoBadRequestResponse(response); InputField inputField = InputField.ConvertField(submitObj); foreach (var prop in submitObj.Properties()) { switch (fieldType) { case FieldType.AutoNumberField: { field = new InputAutoNumberField(); if (prop.Name.ToLower() == "defaultvalue") ((InputAutoNumberField)field).DefaultValue = ((InputAutoNumberField)inputField).DefaultValue; if (prop.Name.ToLower() == "U") ((InputAutoNumberField)field).DisplayFormat = ((InputAutoNumberField)inputField).DisplayFormat; if (prop.Name.ToLower() == "startingnumber") ((InputAutoNumberField)field).StartingNumber = ((InputAutoNumberField)inputField).StartingNumber; } break; case FieldType.CheckboxField: { field = new InputCheckboxField(); if (prop.Name.ToLower() == "defaultvalue") ((InputCheckboxField)field).DefaultValue = ((InputCheckboxField)inputField).DefaultValue; } break; case FieldType.CurrencyField: { field = new InputCurrencyField(); if (prop.Name.ToLower() == "defaultvalue") ((InputCurrencyField)field).DefaultValue = ((InputCurrencyField)inputField).DefaultValue; if (prop.Name.ToLower() == "minvalue") ((InputCurrencyField)field).MinValue = ((InputCurrencyField)inputField).MinValue; if (prop.Name.ToLower() == "maxvalue") ((InputCurrencyField)field).MaxValue = ((InputCurrencyField)inputField).MaxValue; if (prop.Name.ToLower() == "currency") ((InputCurrencyField)field).Currency = ((InputCurrencyField)inputField).Currency; } break; case FieldType.DateField: { field = new InputDateField(); if (prop.Name.ToLower() == "defaultvalue") ((InputDateField)field).DefaultValue = ((InputDateField)inputField).DefaultValue; if (prop.Name.ToLower() == "format") ((InputDateField)field).Format = ((InputDateField)inputField).Format; if (prop.Name.ToLower() == "usecurrenttimeasdefaultvalue") ((InputDateField)field).UseCurrentTimeAsDefaultValue = ((InputDateField)inputField).UseCurrentTimeAsDefaultValue; } break; case FieldType.DateTimeField: { field = new InputDateTimeField(); if (prop.Name.ToLower() == "defaultvalue") ((InputDateTimeField)field).DefaultValue = ((InputDateTimeField)inputField).DefaultValue; if (prop.Name.ToLower() == "format") ((InputDateTimeField)field).Format = ((InputDateTimeField)inputField).Format; if (prop.Name.ToLower() == "usecurrenttimeasdefaultvalue") ((InputDateTimeField)field).UseCurrentTimeAsDefaultValue = ((InputDateTimeField)inputField).UseCurrentTimeAsDefaultValue; } break; case FieldType.EmailField: { field = new InputEmailField(); if (prop.Name.ToLower() == "defaultvalue") ((InputEmailField)field).DefaultValue = ((InputEmailField)inputField).DefaultValue; if (prop.Name.ToLower() == "maxlength") ((InputEmailField)field).MaxLength = ((InputEmailField)inputField).MaxLength; } break; case FieldType.FileField: { field = new InputFileField(); if (prop.Name.ToLower() == "defaultvalue") ((InputFileField)field).DefaultValue = ((InputFileField)inputField).DefaultValue; } break; case FieldType.HtmlField: { field = new InputHtmlField(); if (prop.Name.ToLower() == "defaultvalue") ((InputHtmlField)field).DefaultValue = ((InputHtmlField)inputField).DefaultValue; } break; case FieldType.ImageField: { field = new InputImageField(); if (prop.Name.ToLower() == "defaultvalue") ((InputImageField)field).DefaultValue = ((InputImageField)inputField).DefaultValue; } break; case FieldType.MultiLineTextField: { field = new InputMultiLineTextField(); if (prop.Name.ToLower() == "defaultvalue") ((InputMultiLineTextField)field).DefaultValue = ((InputMultiLineTextField)inputField).DefaultValue; if (prop.Name.ToLower() == "maxlength") ((InputMultiLineTextField)field).MaxLength = ((InputMultiLineTextField)inputField).MaxLength; if (prop.Name.ToLower() == "visiblelinenumber") ((InputMultiLineTextField)field).VisibleLineNumber = ((InputMultiLineTextField)inputField).VisibleLineNumber; } break; case FieldType.MultiSelectField: { field = new InputMultiSelectField(); if (prop.Name.ToLower() == "defaultvalue") ((InputMultiSelectField)field).DefaultValue = ((InputMultiSelectField)inputField).DefaultValue; if (prop.Name.ToLower() == "options") ((InputMultiSelectField)field).Options = ((InputMultiSelectField)inputField).Options; } break; case FieldType.NumberField: { field = new InputNumberField(); if (prop.Name.ToLower() == "defaultvalue") ((InputNumberField)field).DefaultValue = ((InputNumberField)inputField).DefaultValue; if (prop.Name.ToLower() == "minvalue") ((InputNumberField)field).MinValue = ((InputNumberField)inputField).MinValue; if (prop.Name.ToLower() == "maxvalue") ((InputNumberField)field).MaxValue = ((InputNumberField)inputField).MaxValue; if (prop.Name.ToLower() == "decimalplaces") ((InputNumberField)field).DecimalPlaces = ((InputNumberField)inputField).DecimalPlaces; } break; case FieldType.PasswordField: { field = new InputPasswordField(); if (prop.Name.ToLower() == "maxlength") ((InputPasswordField)field).MaxLength = ((InputPasswordField)inputField).MaxLength; if (prop.Name.ToLower() == "minlength") ((InputPasswordField)field).MinLength = ((InputPasswordField)inputField).MinLength; if (prop.Name.ToLower() == "encrypted") ((InputPasswordField)field).Encrypted = ((InputPasswordField)inputField).Encrypted; } break; case FieldType.PercentField: { field = new InputPercentField(); if (prop.Name.ToLower() == "defaultvalue") ((InputPercentField)field).DefaultValue = ((InputPercentField)inputField).DefaultValue; if (prop.Name.ToLower() == "minvalue") ((InputPercentField)field).MinValue = ((InputPercentField)inputField).MinValue; if (prop.Name.ToLower() == "maxvalue") ((InputPercentField)field).MaxValue = ((InputPercentField)inputField).MaxValue; if (prop.Name.ToLower() == "decimalplaces") ((InputPercentField)field).DecimalPlaces = ((InputPercentField)inputField).DecimalPlaces; } break; case FieldType.PhoneField: { field = new InputPhoneField(); if (prop.Name.ToLower() == "defaultvalue") ((InputPhoneField)field).DefaultValue = ((InputPhoneField)inputField).DefaultValue; if (prop.Name.ToLower() == "format") ((InputPhoneField)field).Format = ((InputPhoneField)inputField).Format; if (prop.Name.ToLower() == "maxlength") ((InputPhoneField)field).MaxLength = ((InputPhoneField)inputField).MaxLength; } break; case FieldType.GuidField: { field = new InputGuidField(); if (prop.Name.ToLower() == "defaultvalue") ((InputGuidField)field).DefaultValue = ((InputGuidField)inputField).DefaultValue; if (prop.Name.ToLower() == "generatenewid") ((InputGuidField)field).GenerateNewId = ((InputGuidField)inputField).GenerateNewId; } break; case FieldType.SelectField: { field = new InputSelectField(); if (prop.Name.ToLower() == "defaultvalue") ((InputSelectField)field).DefaultValue = ((InputSelectField)inputField).DefaultValue; if (prop.Name.ToLower() == "options") ((InputSelectField)field).Options = ((InputSelectField)inputField).Options; } break; case FieldType.TextField: { field = new InputTextField(); if (prop.Name.ToLower() == "defaultvalue") ((InputTextField)field).DefaultValue = ((InputTextField)inputField).DefaultValue; if (prop.Name.ToLower() == "maxlength") ((InputTextField)field).MaxLength = ((InputTextField)inputField).MaxLength; } break; case FieldType.UrlField: { field = new InputUrlField(); if (prop.Name.ToLower() == "defaultvalue") ((InputUrlField)field).DefaultValue = ((InputUrlField)inputField).DefaultValue; if (prop.Name.ToLower() == "maxlength") ((InputUrlField)field).MaxLength = ((InputUrlField)inputField).MaxLength; if (prop.Name.ToLower() == "opentargetinnewwindow") ((InputUrlField)field).OpenTargetInNewWindow = ((InputUrlField)inputField).OpenTargetInNewWindow; } break; } if (prop.Name.ToLower() == "label") field.Label = inputField.Label; else if (prop.Name.ToLower() == "placeholdertext") field.PlaceholderText = inputField.PlaceholderText; else if (prop.Name.ToLower() == "description") field.Description = inputField.Description; else if (prop.Name.ToLower() == "helptext") field.HelpText = inputField.HelpText; else if (prop.Name.ToLower() == "required") field.Required = inputField.Required; else if (prop.Name.ToLower() == "unique") field.Unique = inputField.Unique; else if (prop.Name.ToLower() == "searchable") field.Searchable = inputField.Searchable; else if (prop.Name.ToLower() == "auditable") field.Auditable = inputField.Auditable; else if (prop.Name.ToLower() == "system") field.System = inputField.System; } } catch (Exception e) { return DoBadRequestResponse(response, "Input object is not in valid format! It cannot be converted.", e); } return DoResponse(entMan.UpdateField(entity, field)); }
public IActionResult PatchEntity(string StringId, [FromBody]JObject submitObj) { FieldResponse response = new FieldResponse(); InputEntity entity = new InputEntity(); try { Guid entityId; if (!Guid.TryParse(StringId, out entityId)) { response.Errors.Add(new ErrorModel("id", StringId, "id parameter is not valid Guid value")); return DoResponse(response); } DbEntity storageEntity = DbContext.Current.EntityRepository.Read(entityId); if (storageEntity == null) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "Entity with such Name does not exist!"; return DoBadRequestResponse(response); } entity = storageEntity.MapTo<Entity>().MapTo<InputEntity>(); Type inputEntityType = entity.GetType(); foreach (var prop in submitObj.Properties()) { int count = inputEntityType.GetProperties().Where(n => n.Name.ToLower() == prop.Name.ToLower()).Count(); if (count < 1) response.Errors.Add(new ErrorModel(prop.Name, prop.Value.ToString(), "Input object contains property that is not part of the object model.")); } if (response.Errors.Count > 0) return DoBadRequestResponse(response); InputEntity inputEntity = submitObj.ToObject<InputEntity>(); foreach (var prop in submitObj.Properties()) { if (prop.Name.ToLower() == "label") entity.Label = inputEntity.Label; if (prop.Name.ToLower() == "labelplural") entity.LabelPlural = inputEntity.LabelPlural; if (prop.Name.ToLower() == "system") entity.System = inputEntity.System; if (prop.Name.ToLower() == "iconname") entity.IconName = inputEntity.IconName; if (prop.Name.ToLower() == "weight") entity.Weight = inputEntity.Weight; if (prop.Name.ToLower() == "recordpermissions") entity.RecordPermissions = inputEntity.RecordPermissions; } } catch (Exception e) { return DoBadRequestResponse(response, "Input object is not in valid format! It cannot be converted.", e); } return DoResponse(entMan.UpdateEntity(entity)); }
public IActionResult OnPost() { if (!ModelState.IsValid) { throw new Exception("Antiforgery check failed."); } InitPage(); if (ErpEntity == null) { return(NotFound()); } if (String.IsNullOrWhiteSpace(ReturnUrl)) { ReturnUrl = $"/sdk/objects/entity/r/{RecordId}/rl/fields/c/select"; } //empty html input is not posted, so we init it with string.empty if (DefaultValue == null) { DefaultValue = string.Empty; } var entMan = new EntityManager(); try { var newFieldId = Guid.NewGuid(); if (Id != null) { newFieldId = Id.Value; } var response = new FieldResponse(); InputField input = null; switch (Type) { case FieldType.AutoNumberField: { decimal defaultDecimal = 1; if (Decimal.TryParse(DefaultValue, out decimal result)) { defaultDecimal = result; } input = new InputAutoNumberField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, DefaultValue = defaultDecimal, StartingNumber = StartingNumber, DisplayFormat = DisplayFormat, EnableSecurity = EnableSecurity }; } break; case FieldType.CheckboxField: { bool?defaultValue = null; if (Boolean.TryParse(DefaultValue, out bool result)) { defaultValue = result; } input = new InputCheckboxField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, DefaultValue = defaultValue, EnableSecurity = EnableSecurity }; } break; case FieldType.CurrencyField: { decimal?defaultDecimal = null; if (Decimal.TryParse(DefaultValue, out decimal result)) { defaultDecimal = result; } input = new InputCurrencyField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, DefaultValue = defaultDecimal, EnableSecurity = EnableSecurity, MinValue = MinValue, MaxValue = MaxValue, Currency = Helpers.GetCurrencyType(CurrencyCode) }; } break; case FieldType.DateField: { DateTime?defaultValue = null; if (DateTime.TryParse(DefaultValue, out DateTime result)) { defaultValue = result; } input = new InputDateField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, DefaultValue = defaultValue, EnableSecurity = EnableSecurity, Format = Format, UseCurrentTimeAsDefaultValue = UseCurrentTimeAsDefaultValue }; } break; case FieldType.DateTimeField: { DateTime?defaultValue = null; if (DateTime.TryParse(DefaultValue, out DateTime result)) { defaultValue = result; } input = new InputDateTimeField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, DefaultValue = defaultValue, EnableSecurity = EnableSecurity, Format = Format, UseCurrentTimeAsDefaultValue = UseCurrentTimeAsDefaultValue }; } break; case FieldType.EmailField: { string defaultValue = null; if (DefaultValue.ToLowerInvariant() != "null") { defaultValue = DefaultValue; } input = new InputEmailField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, DefaultValue = defaultValue, EnableSecurity = EnableSecurity, MaxLength = MaxLength }; } break; case FieldType.FileField: { string defaultValue = null; if (DefaultValue.ToLowerInvariant() != "null") { defaultValue = DefaultValue; } input = new InputFileField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, DefaultValue = defaultValue, EnableSecurity = EnableSecurity }; } break; case FieldType.HtmlField: { string defaultValue = null; if (DefaultValue.ToLowerInvariant() != "null") { defaultValue = DefaultValue; } input = new InputHtmlField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, DefaultValue = defaultValue, EnableSecurity = EnableSecurity }; } break; case FieldType.ImageField: { string defaultValue = null; if (DefaultValue.ToLowerInvariant() != "null") { defaultValue = DefaultValue; } input = new InputImageField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, DefaultValue = defaultValue, EnableSecurity = EnableSecurity }; } break; case FieldType.MultiLineTextField: { string defaultValue = null; if (DefaultValue.ToLowerInvariant() != "null") { defaultValue = DefaultValue; } input = new InputMultiLineTextField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, DefaultValue = defaultValue, EnableSecurity = EnableSecurity, MaxLength = MaxLength }; } break; case FieldType.MultiSelectField: { var selectOptions = (SelectOptions ?? string.Empty).Split(Environment.NewLine); var defaultOptions = (DefaultValue ?? string.Empty).Split(Environment.NewLine); var multiSelectOptions = new List <SelectOption>(); var defaultValues = new List <string>(); foreach (var option in selectOptions) { if (!String.IsNullOrWhiteSpace(option)) { var optionArray = option.Split(','); var key = ""; var value = ""; var iconClass = ""; var color = ""; if (optionArray.Length > 0 && !String.IsNullOrWhiteSpace(optionArray[0])) { key = optionArray[0].Trim().ToLowerInvariant(); } if (optionArray.Length > 1 && !String.IsNullOrWhiteSpace(optionArray[1])) { value = optionArray[1].Trim(); } else if (optionArray.Length > 0 && !String.IsNullOrWhiteSpace(optionArray[0])) { value = key; } if (optionArray.Length > 2 && !String.IsNullOrWhiteSpace(optionArray[2])) { iconClass = optionArray[2].Trim(); } if (optionArray.Length > 3 && !String.IsNullOrWhiteSpace(optionArray[3])) { color = optionArray[3].Trim(); } if (!String.IsNullOrWhiteSpace(key) && !String.IsNullOrWhiteSpace(value)) { multiSelectOptions.Add(new SelectOption() { Value = key, Label = value, IconClass = iconClass, Color = color }); } } } foreach (var option in defaultOptions) { var fixedOption = option.Trim().ToLowerInvariant(); if (!String.IsNullOrWhiteSpace(option) && multiSelectOptions.Any(x => x.Value == fixedOption)) { defaultValues.Add(fixedOption); } else if (!String.IsNullOrWhiteSpace(option) && !multiSelectOptions.Any(x => x.Value == fixedOption)) { Validation.Errors.Add(new ValidationError("DefaultValue", "one or more of the default values are not found as select options")); throw Validation; } } input = new InputMultiSelectField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, EnableSecurity = EnableSecurity, Options = multiSelectOptions, DefaultValue = defaultValues }; } break; case FieldType.NumberField: { decimal?defaultDecimal = null; if (Decimal.TryParse(DefaultValue, out decimal result)) { defaultDecimal = result; } input = new InputNumberField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, DefaultValue = defaultDecimal, EnableSecurity = EnableSecurity, MinValue = MinValue, MaxValue = MaxValue, DecimalPlaces = DecimalPlaces }; } break; case FieldType.PasswordField: { input = new InputPasswordField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, MinLength = MinLength, Encrypted = Encrypted, EnableSecurity = EnableSecurity, MaxLength = MaxLength }; } break; case FieldType.PercentField: { decimal?defaultDecimal = null; if (Decimal.TryParse(DefaultValue, out decimal result)) { defaultDecimal = result; } input = new InputNumberField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, DefaultValue = defaultDecimal, EnableSecurity = EnableSecurity, MinValue = MinValue, MaxValue = MaxValue, DecimalPlaces = DecimalPlaces }; } break; case FieldType.PhoneField: { string defaultValue = null; if (DefaultValue.ToLowerInvariant() != "null") { defaultValue = DefaultValue; } input = new InputPhoneField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, DefaultValue = defaultValue, EnableSecurity = EnableSecurity, MaxLength = MaxLength }; } break; case FieldType.GuidField: { Guid?defaultGuid = null; if (Guid.TryParse(DefaultValue, out Guid result)) { defaultGuid = result; } input = new InputGuidField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, DefaultValue = defaultGuid, EnableSecurity = EnableSecurity, GenerateNewId = GenerateNewId }; } break; case FieldType.SelectField: { var selectOptions = SelectOptions.Split(Environment.NewLine); var modelSelectOptions = new List <SelectOption>(); foreach (var option in selectOptions) { if (!String.IsNullOrWhiteSpace(option)) { var optionArray = option.Split(','); var key = ""; var value = ""; var iconClass = ""; var color = ""; if (optionArray.Length > 0 && !String.IsNullOrWhiteSpace(optionArray[0])) { key = optionArray[0].Trim().ToLowerInvariant(); } if (optionArray.Length > 1 && !String.IsNullOrWhiteSpace(optionArray[1])) { value = optionArray[1].Trim(); } else if (optionArray.Length > 0 && !String.IsNullOrWhiteSpace(optionArray[0])) { value = key; } if (optionArray.Length > 2 && !String.IsNullOrWhiteSpace(optionArray[2])) { iconClass = optionArray[2].Trim(); } if (optionArray.Length > 3 && !String.IsNullOrWhiteSpace(optionArray[3])) { color = optionArray[3].Trim(); } if (!String.IsNullOrWhiteSpace(key) && !String.IsNullOrWhiteSpace(value)) { modelSelectOptions.Add(new SelectOption() { Value = key, Label = value, IconClass = iconClass, Color = color }); } } } DefaultValue = DefaultValue.Trim().ToLowerInvariant(); if (!String.IsNullOrWhiteSpace(DefaultValue) && !modelSelectOptions.Any(x => x.Value == DefaultValue)) { Validation.Errors.Add(new ValidationError("DefaultValue", "one or more of the default values are not found as select options")); throw Validation; } input = new InputSelectField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, DefaultValue = DefaultValue, EnableSecurity = EnableSecurity, Options = modelSelectOptions }; } break; case FieldType.UrlField: { string defaultValue = null; if (DefaultValue.ToLowerInvariant() != "null") { defaultValue = DefaultValue; } input = new InputUrlField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, DefaultValue = defaultValue, EnableSecurity = EnableSecurity, MaxLength = MaxLength, OpenTargetInNewWindow = OpenTargetInNewWindow }; } break; case FieldType.TextField: { string defaultValue = null; if (DefaultValue.ToLowerInvariant() != "null") { defaultValue = DefaultValue; } input = new InputTextField() { Id = newFieldId, Name = Name, Label = Label, Required = Required, Description = Description, Unique = Unique, HelpText = HelpText, System = System, PlaceholderText = PlaceholderText, Searchable = Searchable, DefaultValue = defaultValue, EnableSecurity = EnableSecurity, MaxLength = MaxLength }; } break; default: throw new Exception("Field Type not recognized"); } var recordPermissionsKeyValues = JsonConvert.DeserializeObject <List <KeyStringList> >(FieldPermissions); input.Permissions = new FieldPermissions(); input.Permissions.CanRead = new List <Guid>(); input.Permissions.CanUpdate = new List <Guid>(); foreach (var role in recordPermissionsKeyValues) { var roleId = Guid.Empty; if (Guid.TryParse(role.Key, out Guid result)) { roleId = result; } if (roleId != Guid.Empty) { if (role.Values.Contains("read")) { input.Permissions.CanRead.Add(roleId); } if (role.Values.Contains("update")) { input.Permissions.CanUpdate.Add(roleId); } } } response = entMan.CreateField(ErpEntity.Id, input); if (!response.Success) { var exception = new ValidationException(response.Message); exception.Errors = response.Errors.MapTo <ValidationError>(); throw exception; } // because of https://github.com/aspnet/Mvc/issues/6711, i added TempDataExtensions int // WebVella.Erp.Web.Utils and using Put and Get<> instead of // TempData["ScreenMessage"] = new ScreenMessage() { Message = "Field created successfully" }; TempData.Put("ScreenMessage", new ScreenMessage() { Message = "Field created successfully" }); return(Redirect($"/sdk/objects/entity/r/{ErpEntity.Id}/rl/fields/l")); } catch (ValidationException ex) { Validation.Message = ex.Message; Validation.Errors = ex.Errors; } catch (Exception ex) { Validation.Message = ex.Message; Validation.Errors.Add(new ValidationError("", ex.Message, isSystem: true)); } HeaderToolbar.AddRange(AdminPageUtils.GetEntityAdminSubNav(ErpEntity, "fields")); ErpRequestContext.PageContext = PageContext; BeforeRender(); return(Page()); }
// public FieldResponse PartialUpdateField(Guid entityId, Guid id, InputField inputField) // { // FieldResponse response = new FieldResponse // { // Success = true, // Message = "The field was successfully updated!", // }; // Field updatedField = null; // try // { // IStorageEntity storageEntity = EntityRepository.Read(entityId); // if (storageEntity == null) // { // response.Timestamp = DateTime.UtcNow; // response.Success = false; // response.Message = "Entity with such Id does not exist!"; // return response; // } // Entity entity = storageEntity.MapTo<Entity>(); // updatedField = entity.Fields.FirstOrDefault(f => f.Id == id); // if (updatedField == null) // { // response.Timestamp = DateTime.UtcNow; // response.Success = false; // response.Message = "Field with such Id does not exist!"; // return response; // } // if (updatedField is AutoNumberField) // { // if (((InputAutoNumberField)inputField).DefaultValue != null) // ((AutoNumberField)updatedField).DefaultValue = ((InputAutoNumberField)inputField).DefaultValue; // if (((InputAutoNumberField)inputField).DisplayFormat != null) // ((AutoNumberField)updatedField).DisplayFormat = ((InputAutoNumberField)inputField).DisplayFormat; // if (((InputAutoNumberField)inputField).StartingNumber != null) // ((AutoNumberField)updatedField).StartingNumber = ((InputAutoNumberField)inputField).StartingNumber; // } // else if (updatedField is CheckboxField) // { // if (((InputCheckboxField)inputField).DefaultValue != null) // ((CheckboxField)updatedField).DefaultValue = ((InputCheckboxField)inputField).DefaultValue; // } // else if (updatedField is CurrencyField) // { // if (((InputCurrencyField)inputField).DefaultValue != null) // ((CurrencyField)updatedField).DefaultValue = ((InputCurrencyField)inputField).DefaultValue; // if (((InputCurrencyField)inputField).MinValue != null) // ((CurrencyField)updatedField).MinValue = ((InputCurrencyField)inputField).MinValue; // if (((InputCurrencyField)inputField).MaxValue != null) // ((CurrencyField)updatedField).MaxValue = ((InputCurrencyField)inputField).MaxValue; // if (((InputCurrencyField)inputField).Currency != null) // ((CurrencyField)updatedField).Currency = ((InputCurrencyField)inputField).Currency; // } // else if (updatedField is DateField) // { // if (((InputDateField)inputField).DefaultValue != null) // ((DateField)updatedField).DefaultValue = ((InputDateField)inputField).DefaultValue; // if (((InputDateField)inputField).Format != null) // ((DateField)updatedField).Format = ((InputDateField)inputField).Format; // if (((InputDateField)inputField).UseCurrentTimeAsDefaultValue != null) // ((DateField)updatedField).UseCurrentTimeAsDefaultValue = ((InputDateField)inputField).UseCurrentTimeAsDefaultValue; // } // else if (updatedField is DateTimeField) // { // if (((InputDateTimeField)inputField).DefaultValue != null) // ((DateTimeField)updatedField).DefaultValue = ((InputDateTimeField)inputField).DefaultValue; // if (((InputDateTimeField)inputField).Format != null) // ((DateTimeField)updatedField).Format = ((InputDateTimeField)inputField).Format; // if (((InputDateTimeField)inputField).UseCurrentTimeAsDefaultValue != null) // ((DateTimeField)updatedField).UseCurrentTimeAsDefaultValue = ((InputDateTimeField)inputField).UseCurrentTimeAsDefaultValue; // } // else if (updatedField is EmailField) // { // if (((InputEmailField)inputField).DefaultValue != null) // ((EmailField)updatedField).DefaultValue = ((InputEmailField)inputField).DefaultValue; // if (((InputEmailField)inputField).MaxLength != null) // ((EmailField)updatedField).MaxLength = ((InputEmailField)inputField).MaxLength; // } // else if (updatedField is FileField) // { // if (((InputFileField)inputField).DefaultValue != null) // ((FileField)updatedField).DefaultValue = ((InputFileField)inputField).DefaultValue; // } // else if (updatedField is HtmlField) // { // if (((InputHtmlField)inputField).DefaultValue != null) // ((HtmlField)updatedField).DefaultValue = ((InputHtmlField)inputField).DefaultValue; // } // else if (updatedField is ImageField) // { // if (((InputImageField)inputField).DefaultValue != null) // ((ImageField)updatedField).DefaultValue = ((InputImageField)inputField).DefaultValue; // } // else if (updatedField is MultiLineTextField) // { // if (((InputMultiLineTextField)inputField).DefaultValue != null) // ((MultiLineTextField)updatedField).DefaultValue = ((InputMultiLineTextField)inputField).DefaultValue; // if (((InputMultiLineTextField)inputField).MaxLength != null) // ((MultiLineTextField)updatedField).MaxLength = ((InputMultiLineTextField)inputField).MaxLength; // if (((InputMultiLineTextField)inputField).VisibleLineNumber != null) // ((MultiLineTextField)updatedField).VisibleLineNumber = ((InputMultiLineTextField)inputField).VisibleLineNumber; // } // else if (updatedField is MultiSelectField) // { // if (((InputMultiSelectField)inputField).DefaultValue != null) // ((MultiSelectField)updatedField).DefaultValue = ((InputMultiSelectField)inputField).DefaultValue; // if (((InputMultiSelectField)inputField).Options != null) // ((MultiSelectField)updatedField).Options = ((InputMultiSelectField)inputField).Options; // } // else if (updatedField is NumberField) // { // if (((InputNumberField)inputField).DefaultValue != null) // ((NumberField)updatedField).DefaultValue = ((InputNumberField)inputField).DefaultValue; // if (((InputNumberField)inputField).MinValue != null) // ((NumberField)updatedField).MinValue = ((InputNumberField)inputField).MinValue; // if (((InputNumberField)inputField).MaxValue != null) // ((NumberField)updatedField).MaxValue = ((InputNumberField)inputField).MaxValue; // if (((InputNumberField)inputField).DecimalPlaces != null) // ((NumberField)updatedField).DecimalPlaces = ((InputNumberField)inputField).DecimalPlaces; // } // else if (updatedField is PasswordField) // { // if (((InputPasswordField)inputField).MaxLength != null) // ((PasswordField)updatedField).MaxLength = ((InputPasswordField)inputField).MaxLength; // if (((InputPasswordField)inputField).MinLength != null) // ((PasswordField)updatedField).MinLength = ((InputPasswordField)inputField).MinLength; // if (((InputPasswordField)inputField).Encrypted != null) // ((PasswordField)updatedField).Encrypted = ((InputPasswordField)inputField).Encrypted; // } // else if (updatedField is PercentField) // { // if (((InputPercentField)inputField).DefaultValue != null) // ((PercentField)updatedField).DefaultValue = ((InputPercentField)inputField).DefaultValue; // if (((InputPercentField)inputField).MinValue != null) // ((PercentField)updatedField).MinValue = ((InputPercentField)inputField).MinValue; // if (((InputPercentField)inputField).MaxValue != null) // ((PercentField)updatedField).MaxValue = ((InputPercentField)inputField).MaxValue; // if (((InputPercentField)inputField).DecimalPlaces != null) // ((PercentField)updatedField).DecimalPlaces = ((InputPercentField)inputField).DecimalPlaces; // } // else if (updatedField is PhoneField) // { // if (((InputPhoneField)inputField).DefaultValue != null) // ((PhoneField)updatedField).DefaultValue = ((InputPhoneField)inputField).DefaultValue; // if (((InputPhoneField)inputField).Format != null) // ((PhoneField)updatedField).Format = ((InputPhoneField)inputField).Format; // if (((InputPhoneField)inputField).MaxLength != null) // ((PhoneField)updatedField).MaxLength = ((InputPhoneField)inputField).MaxLength; // } // else if (updatedField is GuidField) // { // if (((InputGuidField)inputField).DefaultValue != null) // ((GuidField)updatedField).DefaultValue = ((InputGuidField)inputField).DefaultValue; // if (((InputGuidField)inputField).GenerateNewId != null) // ((GuidField)updatedField).GenerateNewId = ((InputGuidField)inputField).GenerateNewId; // } // else if (updatedField is SelectField) // { // if (((InputSelectField)inputField).DefaultValue != null) // ((SelectField)updatedField).DefaultValue = ((InputSelectField)inputField).DefaultValue; // if (((InputSelectField)inputField).Options != null) // ((SelectField)updatedField).Options = ((InputSelectField)inputField).Options; // } // else if (updatedField is TextField) // { // if (((InputTextField)inputField).DefaultValue != null) // ((TextField)updatedField).DefaultValue = ((InputTextField)inputField).DefaultValue; // if (((InputTextField)inputField).MaxLength != null) // ((TextField)updatedField).MaxLength = ((InputTextField)inputField).MaxLength; // } // else if (updatedField is UrlField) // { // if (((InputUrlField)inputField).DefaultValue != null) // ((UrlField)updatedField).DefaultValue = ((InputUrlField)inputField).DefaultValue; // if (((InputUrlField)inputField).MaxLength != null) // ((UrlField)updatedField).MaxLength = ((InputUrlField)inputField).MaxLength; // if (((InputUrlField)inputField).OpenTargetInNewWindow != null) // ((UrlField)updatedField).OpenTargetInNewWindow = ((InputUrlField)inputField).OpenTargetInNewWindow; // } // if (inputField.Label != null) // updatedField.Label = inputField.Label; // else if (inputField.PlaceholderText != null) // updatedField.PlaceholderText = inputField.PlaceholderText; // else if (inputField.Description != null) // updatedField.Description = inputField.Description; // else if (inputField.HelpText != null) // updatedField.HelpText = inputField.HelpText; // else if (inputField.Required != null) // updatedField.Required = inputField.Required.Value; // else if (inputField.Unique != null) // updatedField.Unique = inputField.Unique.Value; // else if (inputField.Searchable != null) // updatedField.Searchable = inputField.Searchable.Value; // else if (inputField.Auditable != null) // updatedField.Auditable = inputField.Auditable.Value; // else if (inputField.System != null) // updatedField.System = inputField.System.Value; // response.Object = updatedField; // response.Errors = ValidateField(entity, updatedField.MapTo<InputField>(), true); // if (response.Errors.Count > 0) // { // response.Timestamp = DateTime.UtcNow; // response.Success = false; // response.Message = "The field was not updated. Validation error occurred!"; // return response; // } // IStorageEntity updatedEntity = entity.MapTo<IStorageEntity>(); // bool result = EntityRepository.Update(updatedEntity); // if (!result) // { // response.Timestamp = DateTime.UtcNow; // response.Success = false; // response.Message = "The field was not updated! An internal error occurred!"; // return response; // } // } // catch (Exception e) // { // response.Success = false; // response.Object = updatedField; // response.Timestamp = DateTime.UtcNow; //#if DEBUG // response.Message = e.Message + e.StackTrace; //#else // response.Message = "The field was not updated. An internal error occurred!"; //#endif // return response; // } // response.Object = updatedField; // response.Timestamp = DateTime.UtcNow; // return response; // } public FieldResponse DeleteField(Guid entityId, Guid id, bool transactional = true) { FieldResponse response = new FieldResponse { Success = true, Message = "The field was successfully deleted!", }; try { IStorageEntity storageEntity = EntityRepository.Read(entityId); if (storageEntity == null) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "Entity with such Id does not exist!"; return response; } Entity entity = storageEntity.MapTo<Entity>(); Field field = entity.Fields.FirstOrDefault(f => f.Id == id); if (field == null) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "The field was not deleted. Validation error occurred!"; response.Errors.Add(new ErrorModel("id", id.ToString(), "Field with such Id does not exist!")); return response; } entity.Fields.Remove(field); var recRep = Storage.GetRecordRepository(); var transaction = recRep.CreateTransaction(); try { if (transactional) transaction.Begin(); recRep.RemoveRecordField(entity.Name, field.Name); IStorageEntity updatedEntity = entity.MapTo<IStorageEntity>(); bool result = EntityRepository.Update(updatedEntity); if (!result) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "The field was not updated! An internal error occurred!"; return response; } if (transactional) transaction.Commit(); } catch { if (transactional) transaction.Rollback(); throw; } } catch (Exception e) { response.Timestamp = DateTime.UtcNow; response.Success = false; #if DEBUG response.Message = e.Message + e.StackTrace; #else response.Message = "The field was not deleted. An internal error occurred!"; #endif return response; } response.Timestamp = DateTime.UtcNow; return response; }
public FieldResponse UpdateField(Entity entity, InputField inputField) { FieldResponse response = new FieldResponse { Success = true, Message = "The field was successfully updated!", }; Field field = null; try { response.Errors = ValidateField(entity, inputField, true); field = inputField.MapTo<Field>(); if (response.Errors.Count > 0) { response.Object = field; response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "The field was not updated. Validation error occurred!"; return response; } Field fieldForDelete = entity.Fields.FirstOrDefault(f => f.Id == field.Id); if (fieldForDelete.Id == field.Id) entity.Fields.Remove(fieldForDelete); entity.Fields.Add(field); IStorageEntity updatedEntity = entity.MapTo<IStorageEntity>(); bool result = EntityRepository.Update(updatedEntity); if (!result) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "The field was not updated! An internal error occurred!"; return response; } } catch (Exception e) { response.Success = false; response.Object = field; response.Timestamp = DateTime.UtcNow; #if DEBUG response.Message = e.Message + e.StackTrace; #else response.Message = "The field was not updated. An internal error occurred!"; #endif return response; } response.Object = field; response.Timestamp = DateTime.UtcNow; return response; }
public IActionResult UpdateField(string Id, string FieldId, [FromBody]JObject submitObj) { FieldResponse response = new FieldResponse(); Guid entityId; if (!Guid.TryParse(Id, out entityId)) { response.Errors.Add(new ErrorModel("id", Id, "id parameter is not valid Guid value")); return DoResponse(response); } Guid fieldId; if (!Guid.TryParse(FieldId, out fieldId)) { response.Errors.Add(new ErrorModel("id", FieldId, "FieldId parameter is not valid Guid value")); return DoResponse(response); } InputField field = new InputGuidField(); FieldType fieldType = FieldType.GuidField; var fieldTypeProp = submitObj.Properties().SingleOrDefault(k => k.Name.ToLower() == "fieldtype"); if (fieldTypeProp != null) { fieldType = (FieldType)Enum.ToObject(typeof(FieldType), fieldTypeProp.Value.ToObject<int>()); } Type inputFieldType = InputField.GetFieldType(fieldType); foreach (var prop in submitObj.Properties()) { int count = inputFieldType.GetProperties().Where(n => n.Name.ToLower() == prop.Name.ToLower()).Count(); if (count < 1) response.Errors.Add(new ErrorModel(prop.Name, prop.Value.ToString(), "Input object contains property that is not part of the object model.")); } if (response.Errors.Count > 0) return DoBadRequestResponse(response); try { field = InputField.ConvertField(submitObj); } catch (Exception e) { return DoBadRequestResponse(response, "Input object is not in valid format! It cannot be converted.", e); } return DoResponse(entMan.UpdateField(entityId, field)); }
public FieldResponse ReadField(Guid entityId, Guid id) { FieldResponse response = new FieldResponse { Success = true, Message = "The field was successfully returned!", }; try { IStorageEntity storageEntity = EntityRepository.Read(entityId); if (storageEntity == null) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "Entity with such Id does not exist!"; return response; } IStorageField storageField = storageEntity.Fields.FirstOrDefault(f => f.Id == id); if (storageField == null) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "Validation error occurred!"; response.Errors.Add(new ErrorModel("id", id.ToString(), "Field with such Id does not exist!")); return response; } Field field = storageField.MapTo<Field>(); response.Object = field; } catch (Exception e) { response.Timestamp = DateTime.UtcNow; response.Success = false; #if DEBUG response.Message = e.Message + e.StackTrace; #else response.Message = "An internal error occurred!"; #endif return response; } response.Timestamp = DateTime.Now; return response; }
public FieldResponse CreateField(Guid entityId, InputField inputField, bool transactional = true) { FieldResponse response = new FieldResponse { Success = true, Message = "The field was successfully created!", }; Field field = null; try { IStorageEntity storageEntity = EntityRepository.Read(entityId); if (storageEntity == null) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "Entity with such Id does not exist!"; return response; } if (inputField.Id == null || inputField.Id == Guid.Empty) inputField.Id = Guid.NewGuid(); Entity entity = storageEntity.MapTo<Entity>(); response.Errors = ValidateField(entity, inputField, false); field = inputField.MapTo<Field>(); if (response.Errors.Count > 0) { response.Object = field; response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "The field was not created. Validation error occurred!"; return response; } entity.Fields.Add(field); IStorageEntity editedEntity = entity.MapTo<IStorageEntity>(); var recRep = Storage.GetRecordRepository(); var transaction = recRep.CreateTransaction(); try { if (transactional) transaction.Begin(); recRep.CreateRecordField(entity.Name, field.Name, field.GetDefaultValue()); bool result = EntityRepository.Update(editedEntity); if (!result) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "The field was not created! An internal error occurred!"; return response; } if (transactional) transaction.Commit(); } catch { if (transactional) transaction.Rollback(); throw; } } catch (Exception e) { response.Success = false; response.Object = field; response.Timestamp = DateTime.UtcNow; #if DEBUG response.Message = e.Message + e.StackTrace; #else response.Message = "The field was not created. An internal error occurred!"; #endif return response; } response.Object = field; response.Timestamp = DateTime.UtcNow; return response; }
// public FieldResponse PartialUpdateField(Guid entityId, Guid id, InputField inputField) // { // FieldResponse response = new FieldResponse // { // Success = true, // Message = "The field was successfully updated!", // }; // Field updatedField = null; // try // { // IStorageEntity storageEntity = EntityRepository.Read(entityId); // if (storageEntity == null) // { // response.Timestamp = DateTime.UtcNow; // response.Success = false; // response.Message = "Entity with such Id does not exist!"; // return response; // } // Entity entity = storageEntity.MapTo<Entity>(); // updatedField = entity.Fields.FirstOrDefault(f => f.Id == id); // if (updatedField == null) // { // response.Timestamp = DateTime.UtcNow; // response.Success = false; // response.Message = "Field with such Id does not exist!"; // return response; // } // if (updatedField is AutoNumberField) // { // if (((InputAutoNumberField)inputField).DefaultValue != null) // ((AutoNumberField)updatedField).DefaultValue = ((InputAutoNumberField)inputField).DefaultValue; // if (((InputAutoNumberField)inputField).DisplayFormat != null) // ((AutoNumberField)updatedField).DisplayFormat = ((InputAutoNumberField)inputField).DisplayFormat; // if (((InputAutoNumberField)inputField).StartingNumber != null) // ((AutoNumberField)updatedField).StartingNumber = ((InputAutoNumberField)inputField).StartingNumber; // } // else if (updatedField is CheckboxField) // { // if (((InputCheckboxField)inputField).DefaultValue != null) // ((CheckboxField)updatedField).DefaultValue = ((InputCheckboxField)inputField).DefaultValue; // } // else if (updatedField is CurrencyField) // { // if (((InputCurrencyField)inputField).DefaultValue != null) // ((CurrencyField)updatedField).DefaultValue = ((InputCurrencyField)inputField).DefaultValue; // if (((InputCurrencyField)inputField).MinValue != null) // ((CurrencyField)updatedField).MinValue = ((InputCurrencyField)inputField).MinValue; // if (((InputCurrencyField)inputField).MaxValue != null) // ((CurrencyField)updatedField).MaxValue = ((InputCurrencyField)inputField).MaxValue; // if (((InputCurrencyField)inputField).Currency != null) // ((CurrencyField)updatedField).Currency = ((InputCurrencyField)inputField).Currency; // } // else if (updatedField is DateField) // { // if (((InputDateField)inputField).DefaultValue != null) // ((DateField)updatedField).DefaultValue = ((InputDateField)inputField).DefaultValue; // if (((InputDateField)inputField).Format != null) // ((DateField)updatedField).Format = ((InputDateField)inputField).Format; // if (((InputDateField)inputField).UseCurrentTimeAsDefaultValue != null) // ((DateField)updatedField).UseCurrentTimeAsDefaultValue = ((InputDateField)inputField).UseCurrentTimeAsDefaultValue; // } // else if (updatedField is DateTimeField) // { // if (((InputDateTimeField)inputField).DefaultValue != null) // ((DateTimeField)updatedField).DefaultValue = ((InputDateTimeField)inputField).DefaultValue; // if (((InputDateTimeField)inputField).Format != null) // ((DateTimeField)updatedField).Format = ((InputDateTimeField)inputField).Format; // if (((InputDateTimeField)inputField).UseCurrentTimeAsDefaultValue != null) // ((DateTimeField)updatedField).UseCurrentTimeAsDefaultValue = ((InputDateTimeField)inputField).UseCurrentTimeAsDefaultValue; // } // else if (updatedField is EmailField) // { // if (((InputEmailField)inputField).DefaultValue != null) // ((EmailField)updatedField).DefaultValue = ((InputEmailField)inputField).DefaultValue; // if (((InputEmailField)inputField).MaxLength != null) // ((EmailField)updatedField).MaxLength = ((InputEmailField)inputField).MaxLength; // } // else if (updatedField is FileField) // { // if (((InputFileField)inputField).DefaultValue != null) // ((FileField)updatedField).DefaultValue = ((InputFileField)inputField).DefaultValue; // } // else if (updatedField is HtmlField) // { // if (((InputHtmlField)inputField).DefaultValue != null) // ((HtmlField)updatedField).DefaultValue = ((InputHtmlField)inputField).DefaultValue; // } // else if (updatedField is ImageField) // { // if (((InputImageField)inputField).DefaultValue != null) // ((ImageField)updatedField).DefaultValue = ((InputImageField)inputField).DefaultValue; // } // else if (updatedField is MultiLineTextField) // { // if (((InputMultiLineTextField)inputField).DefaultValue != null) // ((MultiLineTextField)updatedField).DefaultValue = ((InputMultiLineTextField)inputField).DefaultValue; // if (((InputMultiLineTextField)inputField).MaxLength != null) // ((MultiLineTextField)updatedField).MaxLength = ((InputMultiLineTextField)inputField).MaxLength; // if (((InputMultiLineTextField)inputField).VisibleLineNumber != null) // ((MultiLineTextField)updatedField).VisibleLineNumber = ((InputMultiLineTextField)inputField).VisibleLineNumber; // } // else if (updatedField is MultiSelectField) // { // if (((InputMultiSelectField)inputField).DefaultValue != null) // ((MultiSelectField)updatedField).DefaultValue = ((InputMultiSelectField)inputField).DefaultValue; // if (((InputMultiSelectField)inputField).Options != null) // ((MultiSelectField)updatedField).Options = ((InputMultiSelectField)inputField).Options; // } // else if (updatedField is NumberField) // { // if (((InputNumberField)inputField).DefaultValue != null) // ((NumberField)updatedField).DefaultValue = ((InputNumberField)inputField).DefaultValue; // if (((InputNumberField)inputField).MinValue != null) // ((NumberField)updatedField).MinValue = ((InputNumberField)inputField).MinValue; // if (((InputNumberField)inputField).MaxValue != null) // ((NumberField)updatedField).MaxValue = ((InputNumberField)inputField).MaxValue; // if (((InputNumberField)inputField).DecimalPlaces != null) // ((NumberField)updatedField).DecimalPlaces = ((InputNumberField)inputField).DecimalPlaces; // } // else if (updatedField is PasswordField) // { // if (((InputPasswordField)inputField).MaxLength != null) // ((PasswordField)updatedField).MaxLength = ((InputPasswordField)inputField).MaxLength; // if (((InputPasswordField)inputField).MinLength != null) // ((PasswordField)updatedField).MinLength = ((InputPasswordField)inputField).MinLength; // if (((InputPasswordField)inputField).Encrypted != null) // ((PasswordField)updatedField).Encrypted = ((InputPasswordField)inputField).Encrypted; // } // else if (updatedField is PercentField) // { // if (((InputPercentField)inputField).DefaultValue != null) // ((PercentField)updatedField).DefaultValue = ((InputPercentField)inputField).DefaultValue; // if (((InputPercentField)inputField).MinValue != null) // ((PercentField)updatedField).MinValue = ((InputPercentField)inputField).MinValue; // if (((InputPercentField)inputField).MaxValue != null) // ((PercentField)updatedField).MaxValue = ((InputPercentField)inputField).MaxValue; // if (((InputPercentField)inputField).DecimalPlaces != null) // ((PercentField)updatedField).DecimalPlaces = ((InputPercentField)inputField).DecimalPlaces; // } // else if (updatedField is PhoneField) // { // if (((InputPhoneField)inputField).DefaultValue != null) // ((PhoneField)updatedField).DefaultValue = ((InputPhoneField)inputField).DefaultValue; // if (((InputPhoneField)inputField).Format != null) // ((PhoneField)updatedField).Format = ((InputPhoneField)inputField).Format; // if (((InputPhoneField)inputField).MaxLength != null) // ((PhoneField)updatedField).MaxLength = ((InputPhoneField)inputField).MaxLength; // } // else if (updatedField is GuidField) // { // if (((InputGuidField)inputField).DefaultValue != null) // ((GuidField)updatedField).DefaultValue = ((InputGuidField)inputField).DefaultValue; // if (((InputGuidField)inputField).GenerateNewId != null) // ((GuidField)updatedField).GenerateNewId = ((InputGuidField)inputField).GenerateNewId; // } // else if (updatedField is SelectField) // { // if (((InputSelectField)inputField).DefaultValue != null) // ((SelectField)updatedField).DefaultValue = ((InputSelectField)inputField).DefaultValue; // if (((InputSelectField)inputField).Options != null) // ((SelectField)updatedField).Options = ((InputSelectField)inputField).Options; // } // else if (updatedField is TextField) // { // if (((InputTextField)inputField).DefaultValue != null) // ((TextField)updatedField).DefaultValue = ((InputTextField)inputField).DefaultValue; // if (((InputTextField)inputField).MaxLength != null) // ((TextField)updatedField).MaxLength = ((InputTextField)inputField).MaxLength; // } // else if (updatedField is UrlField) // { // if (((InputUrlField)inputField).DefaultValue != null) // ((UrlField)updatedField).DefaultValue = ((InputUrlField)inputField).DefaultValue; // if (((InputUrlField)inputField).MaxLength != null) // ((UrlField)updatedField).MaxLength = ((InputUrlField)inputField).MaxLength; // if (((InputUrlField)inputField).OpenTargetInNewWindow != null) // ((UrlField)updatedField).OpenTargetInNewWindow = ((InputUrlField)inputField).OpenTargetInNewWindow; // } // if (inputField.Label != null) // updatedField.Label = inputField.Label; // else if (inputField.PlaceholderText != null) // updatedField.PlaceholderText = inputField.PlaceholderText; // else if (inputField.Description != null) // updatedField.Description = inputField.Description; // else if (inputField.HelpText != null) // updatedField.HelpText = inputField.HelpText; // else if (inputField.Required != null) // updatedField.Required = inputField.Required.Value; // else if (inputField.Unique != null) // updatedField.Unique = inputField.Unique.Value; // else if (inputField.Searchable != null) // updatedField.Searchable = inputField.Searchable.Value; // else if (inputField.Auditable != null) // updatedField.Auditable = inputField.Auditable.Value; // else if (inputField.System != null) // updatedField.System = inputField.System.Value; // response.Object = updatedField; // response.Errors = ValidateField(entity, updatedField.MapTo<InputField>(), true); // if (response.Errors.Count > 0) // { // response.Timestamp = DateTime.UtcNow; // response.Success = false; // response.Message = "The field was not updated. Validation error occurred!"; // return response; // } // IStorageEntity updatedEntity = entity.MapTo<IStorageEntity>(); // bool result = EntityRepository.Update(updatedEntity); // if (!result) // { // response.Timestamp = DateTime.UtcNow; // response.Success = false; // response.Message = "The field was not updated! An internal error occurred!"; // return response; // } // } // catch (Exception e) // { // response.Success = false; // response.Object = updatedField; // response.Timestamp = DateTime.UtcNow; //#if DEBUG // response.Message = e.Message + e.StackTrace; //#else // response.Message = "The field was not updated. An internal error occurred!"; //#endif // return response; // } // response.Object = updatedField; // response.Timestamp = DateTime.UtcNow; // return response; // } public FieldResponse DeleteField(Guid entityId, Guid id, bool transactional = true) { FieldResponse response = new FieldResponse { Success = true, Message = "The field was successfully deleted!", }; try { var entityResponse = ReadEntity(entityId); if (!entityResponse.Success) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = entityResponse.Message; return response; } else if (entityResponse.Object == null) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "Entity with such Id does not exist!"; return response; } Entity entity = entityResponse.Object; Field field = entity.Fields.FirstOrDefault(f => f.Id == id); if (field == null) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "The field was not deleted. Validation error occurred!"; response.Errors.Add(new ErrorModel("id", id.ToString(), "Field with such Id does not exist!")); return response; } entity.Fields.Remove(field); using (DbConnection con = DbContext.Current.CreateConnection()) { con.BeginTransaction(); try { DbContext.Current.RecordRepository.RemoveRecordField(entity.Name, field); DbEntity updatedEntity = entity.MapTo<DbEntity>(); bool result = DbContext.Current.EntityRepository.Update(updatedEntity); if (!result) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "The field was not updated! An internal error occurred!"; return response; } con.CommitTransaction(); } catch { con.RollbackTransaction(); throw; } } } catch (Exception e) { Cache.ClearEntities(); response.Timestamp = DateTime.UtcNow; response.Success = false; #if DEBUG response.Message = e.Message + e.StackTrace; #else response.Message = "The field was not deleted. An internal error occurred!"; #endif return response; } Cache.ClearEntities(); response.Timestamp = DateTime.UtcNow; return response; }
public FieldResponse UpdateField(Guid entityId, InputField inputField) { FieldResponse response = new FieldResponse(); var entityResponse = ReadEntity(entityId); if (!entityResponse.Success) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = entityResponse.Message; return response; } else if (entityResponse.Object == null) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "Entity with such Id does not exist!"; return response; } Entity entity = entityResponse.Object; return UpdateField(entity, inputField); }
public FieldResponse CreateField(Guid entityId, InputField inputField, bool transactional = true) { FieldResponse response = new FieldResponse { Success = true, Message = "The field was successfully created!", }; Field field = null; try { var entityResponse = ReadEntity(entityId); if (!entityResponse.Success) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = entityResponse.Message; return response; } else if (entityResponse.Object == null) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "Entity with such Id does not exist!"; return response; } Entity entity = entityResponse.Object; if (inputField.Id == null || inputField.Id == Guid.Empty) inputField.Id = Guid.NewGuid(); response.Errors = ValidateField(entity, inputField, false); field = inputField.MapTo<Field>(); if (response.Errors.Count > 0) { response.Object = field; response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "The field was not created. Validation error occurred!"; return response; } entity.Fields.Add(field); DbEntity editedEntity = entity.MapTo<DbEntity>(); using (DbConnection con = DbContext.Current.CreateConnection()) { con.BeginTransaction(); try { bool result = DbContext.Current.EntityRepository.Update(editedEntity); if (!result) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "The field was not created! An internal error occurred!"; return response; } DbContext.Current.RecordRepository.CreateRecordField(entity.Name, field); con.CommitTransaction(); } catch { con.RollbackTransaction(); throw; } } } catch (Exception e) { Cache.ClearEntities(); response.Success = false; response.Object = field; response.Timestamp = DateTime.UtcNow; #if DEBUG response.Message = e.Message + e.StackTrace; #else response.Message = "The field was not created. An internal error occurred!"; #endif return response; } Cache.ClearEntities(); response.Object = field; response.Timestamp = DateTime.UtcNow; return response; }
/// <summary> /// Initializes a new instance of the <see cref="UpdateFieldOnlineResponse"/> class. /// </summary> /// <param name="model">The response model.</param> /// <param name="document">The document after modification.</param> public UpdateFieldOnlineResponse(FieldResponse model, System.IO.Stream document) { this.Model = model; this.Document = document; }
public IActionResult CreateField(string Id, [FromBody]JObject submitObj) { FieldResponse response = new FieldResponse(); Guid entityId; if (!Guid.TryParse(Id, out entityId)) { response.Errors.Add(new ErrorModel("id", Id, "id parameter is not valid Guid value")); return DoResponse(response); } InputField field = new InputGuidField(); try { field = InputField.ConvertField(submitObj); } catch (Exception e) { return DoBadRequestResponse(response, "Input object is not in valid format! It cannot be converted.", e); } return DoResponse(entMan.CreateField(entityId, field)); }
public IActionResult UpdateEntityRelation(string RelationIdString, [FromBody]JObject submitObj) { FieldResponse response = new FieldResponse(); Guid relationId; if (!Guid.TryParse(RelationIdString, out relationId)) { response.Errors.Add(new ErrorModel("id", RelationIdString, "id parameter is not valid Guid value")); return DoResponse(response); } try { var relation = submitObj.ToObject<EntityRelation>(); return DoResponse(new EntityRelationManager().Update(relation)); } catch (Exception e) { return DoBadRequestResponse(new EntityRelationResponse(), null, e); } }
public FieldResponse CreateField(Guid entityId, FieldType type, Expando data, string name, string label, Guid? id = null, string placeholderText = "", string helpText = "", string description = "", bool system = false, bool required = false, bool unique = false, bool searchable = false, bool auditable = false) { Field field = null; if (data == null) data = new Expando(); switch (type) { case FieldType.AutoNumberField: field = new AutoNumberField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((AutoNumberField)field).DefaultValue = (decimal?)data["defaultValue"]; if (HasKey(data, "startingNumber") && data["startingNumber"] != null) ((AutoNumberField)field).StartingNumber = (decimal?)data["startingNumber"]; if (HasKey(data, "displayFormat") && data["displayFormat"] != null) ((AutoNumberField)field).DisplayFormat = (string)data["displayFormat"]; break; case FieldType.CheckboxField: field = new CheckboxField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((CheckboxField)field).DefaultValue = (bool?)data["defaultValue"] ?? false; break; case FieldType.CurrencyField: field = new CurrencyField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((CurrencyField)field).DefaultValue = (decimal?)data["defaultValue"]; if (HasKey(data, "minValue") && data["minValue"] != null) ((CurrencyField)field).MinValue = (decimal?)data["minValue"]; if (HasKey(data, "maxValue") && data["maxValue"] != null) ((CurrencyField)field).MaxValue = (decimal?)data["maxValue"]; if (HasKey(data, "currency") && data["currency"] != null) { ((CurrencyField)field).Currency = (CurrencyType)data["currency"]; } else { ((CurrencyField)field).Currency = new CurrencyType(); ((CurrencyField)field).Currency.Code = "USD"; ((CurrencyField)field).Currency.DecimalDigits = 2; ((CurrencyField)field).Currency.Name = "US dollar"; ((CurrencyField)field).Currency.NamePlural = "US dollars"; ((CurrencyField)field).Currency.Rounding = 0; ((CurrencyField)field).Currency.Symbol = "$"; ((CurrencyField)field).Currency.SymbolNative = "$"; ((CurrencyField)field).Currency.SymbolPlacement = CurrencySymbolPlacement.Before; ((CurrencyField)field).DefaultValue = 1; } break; case FieldType.DateField: field = new DateField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((DateField)field).DefaultValue = (DateTime?)data["defaultValue"]; if (HasKey(data, "format") && data["format"] != null) ((DateField)field).Format = (string)data["format"]; if (HasKey(data, "useCurrentTimeAsDefaultValue") && data["useCurrentTimeAsDefaultValue"] != null) ((DateField)field).UseCurrentTimeAsDefaultValue = (bool?)data["useCurrentTimeAsDefaultValue"]; break; case FieldType.DateTimeField: field = new DateTimeField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((DateTimeField)field).DefaultValue = (DateTime?)data["defaultValue"]; if (HasKey(data, "format") && data["format"] != null) ((DateTimeField)field).Format = (string)data["format"]; if (HasKey(data, "useCurrentTimeAsDefaultValue") && data["useCurrentTimeAsDefaultValue"] != null) ((DateTimeField)field).UseCurrentTimeAsDefaultValue = (bool?)data["useCurrentTimeAsDefaultValue"]; break; case FieldType.EmailField: field = new EmailField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((EmailField)field).DefaultValue = (string)data["defaultValue"]; if (HasKey(data, "maxLength") && data["maxLength"] != null) ((EmailField)field).MaxLength = (int?)data["maxLength"]; break; case FieldType.FileField: field = new FileField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((FileField)field).DefaultValue = (string)data["defaultValue"]; break; case FieldType.GuidField: field = new GuidField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((GuidField)field).DefaultValue = (Guid?)data["defaultValue"]; if (HasKey(data, "generateNewId") && data["generateNewId"] != null) ((GuidField)field).GenerateNewId = (bool?)data["generateNewId"]; break; case FieldType.HtmlField: field = new HtmlField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((HtmlField)field).DefaultValue = (string)data["defaultValue"]; break; case FieldType.ImageField: field = new ImageField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((ImageField)field).DefaultValue = (string)data["defaultValue"]; break; case FieldType.MultiLineTextField: field = new MultiLineTextField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((MultiLineTextField)field).DefaultValue = (string)data["defaultValue"]; if (HasKey(data, "maxLength") && data["maxLength"] != null) ((MultiLineTextField)field).MaxLength = (int?)data["maxLength"]; if (HasKey(data, "visibleLineNumber") && data["visibleLineNumber"] != null) ((MultiLineTextField)field).VisibleLineNumber = (int?)data["visibleLineNumber"]; break; case FieldType.MultiSelectField: field = new MultiSelectField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((MultiSelectField)field).DefaultValue = (IEnumerable<string>)data["defaultValue"]; if (HasKey(data, "options") && data["options"] != null) ((MultiSelectField)field).Options = (List<MultiSelectFieldOption>)data["options"]; break; case FieldType.NumberField: field = new NumberField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((NumberField)field).DefaultValue = (int?)data["defaultValue"]; if (HasKey(data, "minValue") && data["minValue"] != null) ((NumberField)field).MinValue = (decimal?)data["minValue"]; if (HasKey(data, "maxValue") && data["maxValue"] != null) ((NumberField)field).MaxValue = (decimal?)data["maxValue"]; if (HasKey(data, "decimalPlaces") && data["decimalPlaces"] != null) ((NumberField)field).DecimalPlaces = (byte?)data["decimalPlaces"]; break; case FieldType.PasswordField: field = new PasswordField(); if (HasKey(data, "maxLength") && data["maxLength"] != null) ((PasswordField)field).MaxLength = (int?)data["maxLength"]; if (HasKey(data, "minLength") && data["minLength"] != null) ((PasswordField)field).MinLength = (int?)data["minLength"]; if (HasKey(data, "encrypted") && data["encrypted"] != null) ((PasswordField)field).Encrypted = (bool?)data["encrypted"]; break; case FieldType.PercentField: field = new PercentField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((PercentField)field).DefaultValue = (decimal?)data["defaultValue"]; //0.01m; if (HasKey(data, "minValue") && data["minValue"] != null) ((PercentField)field).MinValue = (decimal?)data["minValue"]; if (HasKey(data, "maxValue") && data["maxValue"] != null) ((PercentField)field).MaxValue = (decimal?)data["maxValue"]; if (HasKey(data, "decimalPlaces") && data["decimalPlaces"] != null) ((PercentField)field).DecimalPlaces = (byte?)data["decimalPlaces"]; break; case FieldType.PhoneField: field = new PhoneField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((PhoneField)field).DefaultValue = (string)data["defaultValue"]; if (HasKey(data, "format") && data["format"] != null) ((PhoneField)field).Format = (string)data["format"]; if (HasKey(data, "maxLength") && data["maxLength"] != null) ((PhoneField)field).DefaultValue = (string)data["maxLength"]; break; case FieldType.SelectField: field = new SelectField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((SelectField)field).DefaultValue = (string)data["defaultValue"]; if (HasKey(data, "options") && data["options"] != null) ((SelectField)field).Options = (List<SelectFieldOption>)data["options"]; break; case FieldType.TextField: field = new TextField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((TextField)field).DefaultValue = (string)data["defaultValue"]; if (HasKey(data, "maxLength") && data["maxLength"] != null) ((TextField)field).MaxLength = (int?)data["maxLength"]; break; case FieldType.UrlField: field = new UrlField(); if (HasKey(data, "defaultValue") && data["defaultValue"] != null) ((UrlField)field).DefaultValue = (string)data["defaultValue"]; if (HasKey(data, "maxLength") && data["maxLength"] != null) ((UrlField)field).MaxLength = (int?)data["maxLength"]; if (HasKey(data, "openTargetInNewWindow") && data["openTargetInNewWindow"] != null) ((UrlField)field).OpenTargetInNewWindow = (bool?)data["openTargetInNewWindow"]; break; default: { FieldResponse response = new FieldResponse(); response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "Not supported field type!"; response.Success = false; return response; } } field.Id = id.HasValue && id.Value != Guid.Empty ? id.Value : Guid.NewGuid(); field.Name = name; field.Label = label; field.PlaceholderText = placeholderText; field.Description = description; field.HelpText = helpText; field.Required = required; field.Unique = unique; field.Searchable = searchable; field.Auditable = auditable; field.System = system; return CreateField(entityId, field.MapTo<InputField>()); }
public IActionResult DeleteField(string Id, string FieldId) { FieldResponse response = new FieldResponse(); Guid entityId; if (!Guid.TryParse(Id, out entityId)) { response.Errors.Add(new ErrorModel("id", Id, "id parameter is not valid Guid value")); return DoResponse(response); } Guid fieldId; if (!Guid.TryParse(FieldId, out fieldId)) { response.Errors.Add(new ErrorModel("id", FieldId, "FieldId parameter is not valid Guid value")); return DoResponse(response); } return DoResponse(entMan.DeleteField(entityId, fieldId)); }
public FieldResponse UpdateField(Guid entityId, InputField inputField) { FieldResponse response = new FieldResponse(); IStorageEntity storageEntity = EntityRepository.Read(entityId); if (storageEntity == null) { response.Timestamp = DateTime.UtcNow; response.Success = false; response.Message = "Entity with such Id does not exist!"; return response; } Entity entity = storageEntity.MapTo<Entity>(); return UpdateField(entity, inputField); }