locked
Validation Is Firing with Data Not Present In The Current Screen RRS feed

  • Question

  • Validation warnings are showing wen some users try to save updated records on their screens and the validation does not correspond to the data they are working on...<o:p></o:p>

    Low latency internet could be the cause?<o:p></o:p>


    Alexander Matos

    Tuesday, March 4, 2014 3:14 PM

All replies

  • Hello Alexander,

    There are several ways that I can think of in which you can get the behavior described.  For example suppose the entity displayed on the screen is called Alpha.  In the Updating interception logic for Alpha there exists custom business logic that creates/modifies another entity called Beta.  If the modifications to Beta cause it to be invalid, those validation results would be displayed on the screen that initiated the save.  Similarly if there exists custom validation logic for A, that logic is free to create validation results for any entity in addition to A.

    If you shared more information about your application/scenario, the community may be able to offer more suggestions/help.

    Tuesday, March 4, 2014 3:53 PM
  • Hi Michael thanks for your response, there are two kind of validations firing in the entity, one is at the entity it self and the other is at a property level.  Here are the codes :

    At Entity level

    partial void Participantes_Inserting(Participante entity)
    {
        if (entity.TipoDocumento == "C" && entity.DocumentoIdentidad != null)
        {
            entity.DocumentoPlain = entity.DocumentoIdentidad.Replace("-""").Trim();
        }
    }

    At property level

    partial void DocumentoIdentidad_Validate(EntityValidationResultsBuilder results)
            {
                // Validar solo si es una Insercion de Participante ** Validate only if there's new records to insert
                if (this.DataWorkspace.ApplicationData.Details.GetChanges().AddedEntities.OfType<Participante>().Count() >= 1)
                {
                    // Datos generales
                    var doc = this.DocumentoIdentidad;
     
                    // Determinando si el Tipo de Documento es Cedula y Documento esta vacio
                    if (this.TipoDocumento == "C" &&
                        string.IsNullOrEmpty(this.DocumentoIdentidad) &&
                        !string.IsNullOrEmpty(this.Nombre))
                    {
                        results.AddPropertyError("El Documento no puede quedar vacio si es una Cédula");
                    }
     
                    if (this.TipoDocumento == "C" &&
                        string.IsNullOrEmpty(this.DocumentoIdentidad) &&
                        string.IsNullOrEmpty(this.Nombre))
                    {
                        results.AddPropertyError("El Documento no puede quedar vacio si es una Cédula");
                    }
     
                    // Determinando si el Documento no es nulo siendo tipo Cedula y con datos en el nombre
                    if (this.TipoDocumento == "C" && !string.IsNullOrEmpty(this.DocumentoIdentidad))
                    {
                        // Determinando si el Alfabetizador fue introducido como participante
                        if (this.DocumentoIdentidad == this.Nucleo.DocumentoIdentidad)
                        {
                            results.AddPropertyError("El Alfabetizador no puede ser un participante.");
                        }
     
                        // Determinando si el participante ya esta en otro Nucleo, siempre que la accion sea insertando
                        var data = this.DataWorkspace.ApplicationData.ParticipanteEnNucleo(doc).FirstOrDefault();
                        if (data != null)
                        {
                            results.AddPropertyError(string.Format("El Participante {0} {1} ya esta registrado en un Nucleo Activo!"this.Nombre, this.Apellido));
                        }
     
                        // Determinar si el participante es un Alfabetizador en la tabla de Alfabetizadores
                        var alfaya = this.DataWorkspace.ApplicationData.Alfabetizadores.Where(a => a.Documento == doc).FirstOrDefault();
                        if (alfaya != null)
                        {
                            results.AddPropertyError(string.Format("El participante {0} es un Alfabetizador", alfaya.NombreCompleto));
                        }
     
                        // Determinando si el participante ya esta en el listado
                        if (this != null)
                        {
                            var dupes = from p in this.Nucleo.Participante
                                        where p != null &&
                                        p.DocumentoIdentidad == this.DocumentoIdentidad &&
                                        p != this
                                        select p;
     
                            if (dupes.FirstOrDefault() != null)
                            {
                                results.AddPropertyError(string.Format("El Participante {0} {1} ya esta en la lista!"this.Nombre, this.Apellido));
                            }
                        }
                    }
                }
            }

    I dont have any new instance or entity affected in this two validations


    Alexander Matos

    Tuesday, March 4, 2014 7:49 PM