/// <summary> /// Run events related to instantiation /// </summary> /// <remarks> /// For example custom prefill. /// </remarks> /// <param name="instance">The instance object</param> /// <param name="data">The data created</param> public void DataCreation(Instance instance, object data) { if (data.GetType() == typeof(Skjema)) { Skjema model = (Skjema)data; string navn = "Test Test 123"; if (model.Foretakgrp8820 == null) { model.Foretakgrp8820 = new Foretakgrp8820() { EnhetNavnEndringdatadef31 = new EnhetNavnEndringdatadef31() { orid = 31, value = navn } }; } else if (model.Foretakgrp8820.EnhetNavnEndringdatadef31 == null) { model.Foretakgrp8820.EnhetNavnEndringdatadef31 = new EnhetNavnEndringdatadef31() { orid = 31, value = navn }; } else { model.Foretakgrp8820.EnhetNavnEndringdatadef31.value = navn; } } }
private void RunValidation(Skjema model, ModelStateDictionary validationResults, bool singleFieldValidation = false) { if (model.OpplysningerOmArbeidstakerengrp8819?.Skjemainstansgrp8854?.Journalnummerdatadef33316?.value == 1234) { validationResults.AddModelError(validationField, validationMessage); } else if (singleFieldValidation) { validationResults.AddModelError(validationField, $"{_settings.FixedValidationPrefix}{validationMessage}"); } }
public void ValidateData(object instance, ModelStateDictionary validationResults) { if (instance.GetType() == typeof(Skjema)) { Skjema model = (Skjema)instance; if (model.OpplysningerOmArbeidstakerengrp8819?.Skjemainstansgrp8854?.Journalnummerdatadef33316?.value == 1234) { validationResults.AddModelError( "opplysningerOmArbeidstakerengrp8819.skjemainstansgrp8854.journalnummerdatadef33316.value", "Value cannot be 1234"); } } }
public bool Calculate(object instance) { bool changed = false; if (instance.GetType() == typeof(Skjema)) { Skjema model = (Skjema)instance; decimal?journalnummer = model.OpplysningerOmArbeidstakerengrp8819?.Skjemainstansgrp8854?.Journalnummerdatadef33316?.value; if (journalnummer != null && journalnummer == 1000) { model.OpplysningerOmArbeidstakerengrp8819.Skjemainstansgrp8854.Journalnummerdatadef33316.value = (decimal)journalnummer + 1; changed = true; } } return(changed); }
public void ValidateData(object instance, ModelStateDictionary validationResults) { if (instance.GetType() == typeof(Skjema)) { Skjema model = (Skjema)instance; _httpContextAccessor.HttpContext.Request.Headers .TryGetValue("ValidationTriggerField", out StringValues value); string dataField = value.Any() ? value[0] : string.Empty; if (dataField == validationField) { RunValidation(model, validationResults, true); return; } RunValidation(model, validationResults); } }
/// <summary> /// Handles all custom validations that are not covered by the data model validation. /// </summary> /// <remarks> /// Validations that fail should be handled by updating the validation result object, /// see example. /// </remarks> /// <param name="validationResults">Object to contain any validation results</param> /// <example> /// if ([some condition]) { /// validationResults.Add(new ValidationResult([error message], new List<string>() { [affected field id] } )); /// } /// </example> public void Validate(object instance, Type modelType, ICollection <ValidationResult> validationResults) { if (modelType == typeof(Skjema)) { Skjema model = (Skjema)instance; if (model.OpplysningerOmArbeidstakerengrp8819?.Skjemainstansgrp8854?.Journalnummerdatadef33316?.value == 1234) { validationResults.Add( new ValidationResult( "Value cannot be 1234", new List <string>() { "opplysningerOmArbeidstakerengrp8819.skjemainstansgrp8854.journalnummerdatadef33316.value" } ) ); } } }
public bool Calculate(object instance) { bool changed = false; if (instance.GetType() == typeof(Skjema)) { Skjema model = (Skjema)instance; decimal?journalnummer = model.OpplysningerOmArbeidstakerengrp8819?.Skjemainstansgrp8854?.Journalnummerdatadef33316?.value; if (journalnummer != null && journalnummer == 1000) { model.OpplysningerOmArbeidstakerengrp8819.Skjemainstansgrp8854.Journalnummerdatadef33316.value = (decimal)journalnummer + 1; model.OpplysningerOmArbeidstakerengrp8819.Skjemainstansgrp8854.IdentifikasjonsnummerKravdatadef33317 = new IdentifikasjonsnummerKravdatadef33317 { orid = 33317, value = "12345", }; changed = true; } else if (journalnummer != null && journalnummer == 1001) { model.OpplysningerOmArbeidstakerengrp8819.Skjemainstansgrp8854.Journalnummerdatadef33316.value = (decimal)journalnummer - 1; model.OpplysningerOmArbeidstakerengrp8819.Skjemainstansgrp8854.TestRepeatinggrp123 = new List <Journalnummerdatadef33316> { new Journalnummerdatadef33316 { orid = 1234, value = 555, }, new Journalnummerdatadef33316 { orid = 1234, value = 444, }, }; model.OpplysningerOmArbeidstakerengrp8819.Skjemainstansgrp8854.IdentifikasjonsnummerKravdatadef33317 = null; changed = true; } } return(changed); }