public async Task <bool> forgotPassUser(String cpf) { CpfValidate cpfValidate = new CpfValidate(); if (String.IsNullOrEmpty(cpf)) { throw new BadRequestException("CPF em branco!"); } if (!cpfValidate.ValidaCPF(cpf)) { throw new BadRequestException("CPF inválido!"); } Indicator user = new Indicator(); try { user = _repository.GetIndicatorByCPF(cpf); } catch (Exception e) { throw new Exception("Algo deu errado: " + e.GetType()); } if (user == null) { throw new NotFoundException("Não existe um usuário com este documento!"); } bool res = await _sendForgotPassEmail.SendMessageAsync(new EmailAddress(user.Email, user.Name), "Sua senha é: " + user.Password); return(res); }
public IndicationService(IndicationRepository repository, ProductRepository productRepository, UserRepository userRepository, CnpjValidate cnpjValidate, CpfValidate cpfValidate) { _repository = repository; _productRepository = productRepository; _userRepository = userRepository; _cnpjValidate = cnpjValidate; _cpfValidate = cpfValidate; }
public IndicatorService(CpfValidate cpfValidate, IndicatorRepository repository, PaymentAccountRepository paymentAccountRepository, SendConfirmAccountCode sendConfirmAccountCode, UserRepository userRepository, SendForgotPassEmail sendForgotPassEmail) { _cpfValidate = cpfValidate; _repository = repository; _paymentAccountRepository = paymentAccountRepository; _sendConfirmMail = sendConfirmAccountCode; _userRepository = userRepository; _sendForgotPassEmail = sendForgotPassEmail; }
public JsonResult Alterar(ClienteModel model) { if (!this.ModelState.IsValid) { List <string> erros = (from item in ModelState.Values from error in item.Errors select error.ErrorMessage).ToList(); Response.StatusCode = 400; return(Json(string.Join(Environment.NewLine, erros))); } else { CPFValidateReturn cpfValid = CpfValidate.ValidateCpf(model.CPF); if (!cpfValid.IsValid) { Response.StatusCode = 400; return(Json(string.Join(Environment.NewLine, cpfValid.Message))); } BoCliente bo = new BoCliente(); int qtd = 0; var clientes = bo.Pesquisa(0, 5, "Nome", "ASC".Equals("ASC", StringComparison.InvariantCultureIgnoreCase), out qtd); if (clientes.Where(c => c.Id != model.Id && c.CPF == model.CPF).Count() >= 1) { Response.StatusCode = 400; return(Json(string.Join(Environment.NewLine, "Esse CPF já existe em outro cliente!"))); } bo.Alterar(new Cliente() { Id = model.Id, CEP = model.CEP, Cidade = model.Cidade, Email = model.Email, Estado = model.Estado, Logradouro = model.Logradouro, Nacionalidade = model.Nacionalidade, Nome = model.Nome, Sobrenome = model.Sobrenome, Telefone = model.Telefone, CPF = model.CPF }); return(Json("Cadastro alterado com sucesso")); } }
public JsonResult Incluir(ClienteModel model) { if (!this.ModelState.IsValid) { List <string> erros = (from item in ModelState.Values from error in item.Errors select error.ErrorMessage).ToList(); Response.StatusCode = 400; return(Json(string.Join(Environment.NewLine, erros))); } else { CPFValidateReturn cpfValid = CpfValidate.ValidateCpf(model.CPF); if (!cpfValid.IsValid) { Response.StatusCode = 400; return(Json(string.Join(Environment.NewLine, cpfValid.Message))); } BoCliente bo = new BoCliente(); if (bo.VerificarExistencia(model.CPF)) { Response.StatusCode = 400; return(Json(string.Join(Environment.NewLine, "Esse CPF já está cadastrado!"))); } model.Id = bo.Incluir(new Cliente() { CEP = model.CEP, Cidade = model.Cidade, Email = model.Email, Estado = model.Estado, Logradouro = model.Logradouro, Nacionalidade = model.Nacionalidade, Nome = model.Nome, Sobrenome = model.Sobrenome, Telefone = model.Telefone, CPF = model.CPF }); return(Json("Cadastro efetuado com sucesso")); } }
public UserService(UserRepository repository, CpfValidate cpfValidate, ILogger <User> logger) { _repository = repository; _cpfValidate = cpfValidate; _logger = logger; }