public void EditarFornecedor(Fornecedor forn)
        {
            Fornecedor fornecedor = fornecedorRepositorio.Listar(x => x.FornecedorID == forn.FornecedorID).FirstOrDefault();

            try
            {
                if (ModelState.IsValid)
                {
                    fornecedor.Nome       = forn.Nome;
                    fornecedor.Pessoa     = forn.Pessoa;
                    fornecedor.Email      = forn.Email;
                    fornecedor.CPF        = forn.CPF;
                    fornecedor.CNPJ       = forn.CNPJ;
                    fornecedor.Telefone   = forn.Telefone;
                    fornecedor.Endereco   = forn.Endereco;
                    fornecedor.Observacao = forn.Observacao;
                    fornecedor.StatusId   = forn.StatusBool ? 1 : 2;

                    fornecedorRepositorio.Atualizar(fornecedor);
                    fornecedorRepositorio.SalvarTodos();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #2
0
        public NotificationResult Atualizar(Fornecedor entidade)
        {
            var notificationResult = new NotificationResult();

            try
            {
                if (EmailUtil.ValidarEmail(entidade.Email) == false)
                {
                    notificationResult.Add(new NotificationError("Email Inválido!", NotificationErrorType.USER));
                }

                if (CNPJUtil.ValidarCNPJ(entidade.CNPJ) == false)
                {
                    notificationResult.Add(new NotificationError("CNPJ Do Fornecedor Inválido", NotificationErrorType.USER));
                }

                if (string.IsNullOrEmpty(entidade.TelefoneFixo))
                {
                    notificationResult.Add(new NotificationError("Telefone Inválido", NotificationErrorType.USER));
                }

                if (string.IsNullOrEmpty(entidade.Nome))
                {
                    notificationResult.Add(new NotificationError("Nome Do Fornecedor Inválido", NotificationErrorType.USER));
                }

                if (entidade.idFornecedor <= 0)
                {
                    return(notificationResult.Add(new NotificationError("Código do Fornecedor Inválido!")));
                }

                if (string.IsNullOrEmpty(entidade.EnderecoImagem))
                {
                    notificationResult.Add(new NotificationError("URL da Imagem Inválida ou Não Suportada!", NotificationErrorType.USER));
                }

                if (notificationResult.IsValid)
                {
                    _fornecedorRepositorio.Atualizar(entidade);
                    notificationResult.Add("Fornecedor Atualizado com sucesso.");
                }

                return(notificationResult);
            }
            catch (Exception ex)
            {
                return(notificationResult.Add(new NotificationError(ex.Message)));
            }
        }