コード例 #1
0
        private bool ValdiateNif(Empresas model)
        {
            try
            {
                if (!string.IsNullOrEmpty(model.fkPais) && !string.IsNullOrEmpty(model.nif))
                {
                    var appService           = new ApplicationHelper(Context);
                    var fNifValidatorService = new FNifValidatorService(appService.CheckPaisEuropeoService(model.fkPais));
                    var validator            = fNifValidatorService.GetValidator(model.fkPais);
                    var tiposnifs            = appService.GetListTiposNif(_db);
                    var hayQueVerificar      = tiposnifs.SingleOrDefault(f => f.Valor == model.fktipoidentificacion_nif)?.VerificaValor;
                    if (hayQueVerificar.HasValue && hayQueVerificar.Value)
                    {
                        var cadenaNif = model.nif;
                        if (!validator.Validate(ref cadenaNif))
                        {
                            return(false);
                        }
                        model.nif = cadenaNif;
                    }

                    if (!string.IsNullOrEmpty(model.nifcifadministrador))
                    {
                        var cadenaNif = model.nifcifadministrador;
                        if (!validator.Validate(ref cadenaNif))
                        {
                            return(false);
                        }
                        model.nifcifadministrador = cadenaNif;
                    }

                    model.nif = model.nif.ToUpper();
                }
            }
            catch (Exception ex)
            {
                throw new ValidationException(ex.Message);
            }


            return(true);
        }