/// <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; } } }
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"); } } }
/// <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 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); }