Ejemplo n.º 1
0
 void HandleTextChanged(object sender, TextChangedEventArgs e)
 {
     if (e.OldTextValue == null)
     {
         IsValid = null;
     }
     else
     {
         IsValid = (ValidationsUtil.IsCNPJValid(e.NewTextValue));
         ((Entry)sender).TextColor = IsValid.Value ? Color.Default : Color.Red;
     }
 }
Ejemplo n.º 2
0
        public bool IsViewModelValid()
        {
            if (UsuarioModel.TipoApp != TipoAppModel.CLIENTE && UsuarioModel.TipoApp != TipoAppModel.FORNECEDOR)
            {
                throw new InvalidViewModelException("O tipo de aplicativo deve ser cliente ou fornecedor");
            }

            if (string.IsNullOrEmpty(UsuarioModel.PessoaJuridicaModel.CNPJ) ||
                string.IsNullOrWhiteSpace(UsuarioModel.PessoaJuridicaModel.CNPJ))
            {
                throw new InvalidViewModelException("CNPJ é obrigatório");
            }

            if (ValidationsUtil.IsCNPJValid(UsuarioModel.PessoaJuridicaModel.CNPJ) == false)
            {
                throw new InvalidViewModelException("CNPJ não está em um formato correto");
            }

            if (string.IsNullOrEmpty(UsuarioModel.PessoaJuridicaModel.RazaoSocial) ||
                string.IsNullOrWhiteSpace(UsuarioModel.PessoaJuridicaModel.RazaoSocial))
            {
                throw new InvalidViewModelException("Nome fantasia é obrigatório");
            }

            if (string.IsNullOrEmpty(UsuarioModel.Email) || string.IsNullOrWhiteSpace(UsuarioModel.Email))
            {
                throw new InvalidViewModelException("Email é obrigatório");
            }

            if (ValidationsUtil.IsEmailValid(UsuarioModel.Email) == false)
            {
                throw new InvalidViewModelException("Email não está em um formato correto");
            }

            if (string.IsNullOrEmpty(UsuarioModel.Senha) || string.IsNullOrWhiteSpace(UsuarioModel.Senha))
            {
                throw new InvalidViewModelException("Senha é obrigatória");
            }

            if (UsuarioModel.Senha.Equals(ConfirmacaoSenha) == false)
            {
                throw new InvalidViewModelException("Senha e confirmação de senha devem ser iguais");
            }

            return(true);
        }
Ejemplo n.º 3
0
 public HttpResponseMessage Post(ClienteCadastroViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             service.Cadastrar(model);
             return(Request.CreateResponse(HttpStatusCode.OK, "O plano foi excluido com sucesso."));
         }
         catch (Exception erro)
         {
             return(Request.CreateResponse(HttpStatusCode.InternalServerError, erro.Message));
         }
     }
     else
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, ValidationsUtil.GetErrorMessages(ModelState)));
     }
 }
Ejemplo n.º 4
0
        public bool IsViewModelValid()
        {
            if (string.IsNullOrEmpty(UsuarioModel.Email) || string.IsNullOrWhiteSpace(UsuarioModel.Email))
            {
                throw new InvalidViewModelException("Email é obrigatório");
            }

            if (ValidationsUtil.IsEmailValid(UsuarioModel.Email) == false)
            {
                throw new InvalidViewModelException("Email não está em um formato correto");
            }

            if (string.IsNullOrEmpty(UsuarioModel.Senha) || string.IsNullOrWhiteSpace(UsuarioModel.Senha))
            {
                throw new InvalidViewModelException("Senha é obrigatória");
            }

            return(true);
        }
Ejemplo n.º 5
0
        public HttpResponseMessage PUT(ClienteEdicaoViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    service.Alterar(model);

                    return(Request.CreateResponse(HttpStatusCode.OK, $"O cliente {model.Nome} foi atualizado com sucesso."));
                }
                catch (Exception erro)
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, erro.Message));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ValidationsUtil.GetErrorMessages(ModelState)));
            }
        }