public async Task <bool> Handle(AddSupplierCommand request, CancellationToken cancellationToken) { var company = _companyRepository.Find(request.CompanyID); if (company == null) { await _bus.RaiseEvent(new DomainErrorNotification("NotAllowed", "Company informed does not exists.")); return(false); } if (await _supplierRepository.ExistsSupplierWithCPFCNPJ(request.CpfCnpj)) { await _bus.RaiseEvent(new DomainErrorNotification("Conflict", "Supplier with informed CPF/CNPJ already exists.")); return(false); } if (company.UF.ToString().Equals("PR") && CPF.IsCpf(request.CpfCnpj) && request.BirthDate.Value.Age() < 18) { await _bus.RaiseEvent(new DomainErrorNotification("NotAllowed", "Underage Supplier not permmited.")); return(false); } _repository.Add(new Supplier(request.Name, (CPFCNPJ)request.CpfCnpj, request.Phones, company, request.SupplierID, request.BirthDate, (RG)request.Rg)); return(Commit()); }
protected void ValidatePrivateIndividual(Expression <Func <T, string> > cpfcnpjFiled, Expression <Func <T, string> > rgFiled, Expression <Func <T, DateTimeOffset?> > birthDateFiled) { When(supplier => CPF.IsCpf(cpfcnpjFiled.Compile().Invoke(supplier)), () => { RuleFor(rgFiled).Cascade(CascadeMode.StopOnFirstFailure) .NotNull().WithMessage("RG was not provided for private individual.") .NotEmpty().WithMessage("RG was not provided for private individual."); RuleFor(birthDateFiled).Cascade(CascadeMode.StopOnFirstFailure) .NotNull().WithMessage("Birth date was not provided for private individual.") .NotEmpty().WithMessage("Birth date was not provided for private individual."); }); }
public AtualizarFuncionarioValidator() { RuleFor(v => v.CPF) .Must(Cpf => CPF.IsCpf(Cpf)) .WithMessage("CPF Invalido.") .NotEmpty() .WithMessage("CPF Invalido."); RuleFor(v => v.Nome) .NotEmpty() .WithMessage("Nome Invalida."); RuleFor(v => v.Email) .Must(Cpf => Email.IsValidEmail(Cpf)) .WithMessage("Email Invalida.") .NotEmpty() .WithMessage("Email Invalida."); }
public FilterGetAllEmployeesValidador() { RuleFor(v => v.EmailUsuario) .Must(email => Util.Regex.Email.IsValidEmail(email)) .WithMessage("Email Usuario Invalido."); RuleFor(v => v.Cnpj) .Must(cnpj => cnpj == null || cnpj == "" ? true : CNPJ.IsCnpj(cnpj)) .WithMessage("CNPJ Invalido."); RuleFor(v => v.Cpf) .Must(cpf => cpf == null || cpf == "" ? true : CPF.IsCpf(cpf)) .WithMessage("CPF Invalido."); RuleFor(v => v.EmailFuncionario) .Must(email => email == null || email == "" ? true : Util.Regex.Email.IsValidEmail(email)) .WithMessage("Email Funcionario."); }
public Supplier(string name, CPFCNPJ cPFCNPJ, ICollection <Phone> phones, Company company, Guid id, DateTimeOffset?birthDate = null, RG rg = null) { Id = id; Name = name; CPFCNPJ = cPFCNPJ; CreationDate = DateTimeOffset.Now; Phones = phones; Company = company; if (CPF.IsCpf(cPFCNPJ)) { BirthDate = birthDate; RG = rg; if (BirthDate == null || RG == null) { throw new InvalidOperationException("Birthdate and RG must be provided for private individual"); } } }
public bool ValidCpf(string cpf) { return(CPF.IsCpf(cpf)); }