public ResponseObject <ClientForGetDto> Update(ClientForUpdateDto clientForUpdateDto) { if (!ValidateCPF.IsCpf(clientForUpdateDto.SocialSecurityNumber)) { return(new ResponseObject <ClientForGetDto>(false, "CPF Inválido")); } var occupationForCheckId = _occupationRepository.GetById(clientForUpdateDto.IdOccupation); if (occupationForCheckId == null) { return(new ResponseObject <ClientForGetDto>(false, "Não existe um cargo com o ID informado")); } var clientForCheckId = _clientRepository.GetById(clientForUpdateDto.Id); if (clientForCheckId == null) { return(new ResponseObject <ClientForGetDto>(false, "Não existe um usuário com o ID informado")); } var clientForUpdate = _mapper.Map <Client>(clientForUpdateDto); _clientRepository.Update(clientForUpdate); var commit = _unityOfWork.Commit(); return(commit ? new ResponseObject <ClientForGetDto>(true, obj: _mapper.Map <ClientForGetDto>(clientForUpdate)) : new ResponseObject <ClientForGetDto>(false)); }
private List <ErrorsTO> ValidateCpfAsync(ResponsibleRequestTO responsibleRequestTO) { var errors = new List <ErrorsTO>(); if (!ValidateCPF.IsCpf(responsibleRequestTO.Cpf.ToString().PadLeft(11, '0'))) { errors.Add(new ErrorsTO { Field = "CPF", Validation = Messaging.InvalidCPF }); } return(errors); }
public CatererValidation() { RuleFor(c => c.Name) .NotEmpty().WithMessage("Field {propertyName} required") .Length(2, 100); When(c => c.CatererType == CatererType.Person, () => { RuleFor(c => c.Document.Length).Equal(ValidateCPF.cpfSize) .WithMessage("The field must be {ComparisonValue} characters and has {PropertyValue}"); RuleFor(c => ValidateCPF.Validate(c.Document)).Equal(true) .WithMessage("Invalid CPF"); }); When(c => c.CatererType == CatererType.Company, () => { RuleFor(c => c.Document.Length).Equal(ValidateCNPJ.cnpjSize) .WithMessage("The field must be {ComparisonValue} characters and has {PropertyValue}"); RuleFor(c => ValidateCNPJ.Validate(c.Document)).Equal(true) .WithMessage("Invalid CNPJ"); }); }