private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                _correntistaSelecionado.Nome    = txtNome.Text;
                _correntistaSelecionado.CpfCnpj = txtCpfCnpj.Text;
                _correntistaSelecionado.Ativo   = chkAtivo.Checked;

                _correntistaBO.CriarOuAtualizarCorrentista(_correntistaSelecionado);

                //limpar tudo
                txtNome.Clear();
                txtCpfCnpj.Clear();
                chkAtivo.Checked  = false;
                pnlEdicao.Enabled = false;
                btnNovo.Focus();
                _correntistaSelecionado = null;
                HabilitarDesabilitarControles();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                "Validação",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
        public IActionResult FazerTransacao([FromBody] Transacao transacao)
        {
            try
            {
                ContaCorrente conta = contaService.Get(transacao.Id);
                conta.Saldo += transacao.Valor;
                contaService.Put <ContaCorrenteValidator>(conta);

                if (transacao.PrecisaNotificarCoaf())
                {
                    Correntista correntista = correntistaService.Get(conta.correntistaId);
                    coafService.NotificarCoafApi(correntista, transacao);
                }

                return(new ObjectResult(conta));
            }
            catch (ArgumentNullException ex)
            {
                return(NotFound(ex));
            }
            catch (InvalidOperationException ex)
            {
                return(Problem(ex.Message));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Пример #3
0
        public void Update(Correntista pCorrentista)
        {
            var correntistaCursor = _correntistas.FirstOrDefault(x => x.Id == pCorrentista.Id);

            correntistaCursor.Nome    = pCorrentista.Nome;
            correntistaCursor.CpfCnpj = pCorrentista.CpfCnpj;
        }
 private void btnNovo_Click(object sender, EventArgs e)
 {
     pnlEdicao.Enabled       = true;
     _correntistaSelecionado = new Correntista();
     txtNome.Focus();
     HabilitarDesabilitarControles();
 }
Пример #5
0
 public Conta(int numero, Cliente cliente, Correntista correntista, Agencia agencia)
 {
     this.numero      = numero;
     this.correntista = correntista;
     this.cliente     = cliente;
     this.agencia     = agencia;
     this.saldo       = 100;
 }
 public ActionResult Edit([Bind(Include = "Id,Senha,Nome,Email,CPF")] Correntista correntista)
 {
     if (ModelState.IsValid)
     {
         business.Alterar(correntista);
         return(RedirectToAction("Index"));
     }
     return(View(correntista));
 }
Пример #7
0
 public void Excluir(Correntista correntista)
 {
     using (IUnitOfWork uow = new UnitOfWork())
     {
         dal = new CorrentistaDal(uow);
         dal.Delete(correntista);
         uow.Commit();
     }
 }
Пример #8
0
 private static Conta RetornarConta(Correntista joao)
 {
     return(new ContaMesada
     {
         Numero = "123",
         Correntista = joao,
         ValorMaximoSaque = 100
     });
 }
Пример #9
0
 private static Conta RetornarConta(Correntista joao)
 {
     return(new Conta
     {
         Numero = "123",
         Correntista = joao,
         Limite = 1000
     });
 }
Пример #10
0
 public void Alterar(Correntista correntista)
 {
     using (IUnitOfWork uow = new UnitOfWork())
     {
         dal = new CorrentistaDal(uow);
         correntista.Senha = criptografia.Criptografa(correntista.Senha);
         dal.Update(correntista);
         uow.Commit();
     }
 }
Пример #11
0
        public async Task <IActionResult> Put(int id, [FromBody] CorrentistaVM correntista)
        {
            Correntista request = mapper.Map <CorrentistaVM, Correntista>(correntista);

            request.Id = id;
            correntistaService.Update(request);
            await unitOfWork.SaveChangesAsync();

            return(Response(mapper.Map <Correntista, CorrentistaVM>(request)));
        }
 private void btnCancelar_Click(object sender, EventArgs e)
 {
     _correntistaSelecionado = null;
     txtNome.Clear();
     txtCpfCnpj.Clear();
     chkAtivo.Checked  = false;
     pnlEdicao.Enabled = false;
     btnNovo.Focus();
     HabilitarDesabilitarControles();
 }
Пример #13
0
        public async Task <IActionResult> Post([FromBody] CorrentistaVM correntista)
        {
            Correntista request = mapper.Map <CorrentistaVM, Correntista>(correntista);

            request.ContaCorrentes = new List <ContaCorrente>();
            correntistaService.Add(request);
            await unitOfWork.SaveChangesAsync();

            return(Response(correntista, $"api/correntista/{request.Id}"));
        }
Пример #14
0
        public ActionResult Create(Correntista correntista)
        {//[Bind(Include = "Id,Senha,Nome,Email,CPF")]
            if (ModelState.IsValid)
            {
                business.Incluir(correntista);
                return(RedirectToAction("Index"));
            }

            return(View(correntista));
        }
 private void btnExcluir_Click(object sender, EventArgs e)
 {
     ObterItemSelecionado();
     if (MessageBox.Show("Deseja excluir o correntista?", "Confirmar exclusão", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         _correntistaBO.ExcluirCorrentista(_correntistaSelecionado);
         _correntistaSelecionado = null;
         HabilitarDesabilitarControles();
         MessageBox.Show("Correntista excluído com sucesso!", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Пример #16
0
        static void Main(string[] args)
        {
            Correntista joao  = RetornarCorrentista();
            Conta       conta = RetornarConta(joao);

            var viewConta = new ContaView(conta);

            viewConta.Apresentar();

            Console.WriteLine("Fim do programa. Tecle <Enter> para sair.");
            Console.ReadKey();
        }
Пример #17
0
        public int Incluir(Correntista correntista)
        {
            using (IUnitOfWork uow = new UnitOfWork())
            {
                dal = new CorrentistaDal(uow);
                correntista.Senha = criptografia.Criptografa(correntista.Senha);
                correntista       = dal.Add(correntista);

                uow.Commit();
            }
            return(correntista.Codigo);
        }
        private void Validar(Correntista pCorrentista)
        {
            if (string.IsNullOrWhiteSpace(pCorrentista.Nome))
            {
                throw new Exception("O campo nome não foi preenchido.");
            }

            if (string.IsNullOrWhiteSpace(pCorrentista.CpfCnpj))
            {
                throw new Exception("O campo Cpf/Cnpj não foi preenchido.");
            }
        }
Пример #19
0
    public static void Main()
    {
        Correntista c = new Correntista();

        c.Nome        = "Fabio Galuppo";
        c.Idade       = 20;
        c.SenhaCartão = "Desenvolvendo.NET";

        Dump(c);

        FileMode   create = FileMode.Create, open = FileMode.Open;
        FileAccess write = FileAccess.Write, read = FileAccess.Read;
        FileShare  share = FileShare.None;
        string     filebin = "correntista.bin", filexml = "correntista.soap";

        //Serialização Binária
        IFormatter binfmtr = new BinaryFormatter();
        Stream     binstrm = new FileStream(filebin, create, write, share);

        binfmtr.Serialize(binstrm, c);
        //Serialização Binária

        //Serialização SOAP
        IFormatter soapfmtr = new SoapFormatter();
        Stream     soapstrm = new FileStream(filexml, create, write, share);

        soapfmtr.Serialize(soapstrm, c);
        soapstrm.Close(); //o Soap Stream deve ser fechado
        //Serialização SOAP

        c = null;

        //Deserialização Binária
        IFormatter dbinfmtr = new BinaryFormatter();
        Stream     dbinstrm = new FileStream(filebin, open, read, share);

        c = (Correntista)dbinfmtr.Deserialize(dbinstrm);

        Dump(c);
        //Deserialização Binária

        c = null;

        //Deserialização SOAP
        IFormatter dsoapfmtr = new SoapFormatter();
        Stream     dsoapstrm = new FileStream(filexml, open, read, share);

        c = (Correntista)dsoapfmtr.Deserialize(dsoapstrm);

        Dump(c);
        //Deserialização SOAP
    }
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            //criei uma nova instancia de corretista
            var novoCorrentista = new Correntista();

            //atribui os dados do novo correntista para a instancia do novo correntista
            novoCorrentista.Nome    = txtNome.Text;
            novoCorrentista.CpfCnpj = txtCpfCnpj.Text;

            //invoquei o metodo create do dataset
            repositorio.Create(novoCorrentista);
            _datasource.ResetBindings(true);
        }
Пример #21
0
        // GET: Correntistas/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Correntista correntista = business.Obter(id.Value);

            if (correntista == null)
            {
                return(HttpNotFound());
            }
            return(View(correntista));
        }
 public IActionResult Atualizar([FromBody] Correntista correntista)
 {
     try
     {
         if (_correntistaRepository.Existe(correntista.Identificador))
         {
             _correntistaRepository.Atualizar(correntista);
             return(Ok("Registro atualizado."));
         }
         return(NotFound("Registo não encontrado."));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, $"Erro interno no servidor: {ex.Message.ToString()}"));
     }
 }
 public IActionResult Adicionar([FromBody] Correntista correntista)
 {
     try
     {
         if (_correntistaRepository.Existe(correntista.Identificador))
         {
             return(StatusCode(409, "Já existe um cadastro com esse numero de Identificador."));
         }
         _correntistaRepository.Adicionar(correntista);
         return(Ok($"Correntista {correntista.Nome} com código identificador {correntista.Identificador} adicionado com sucesso."));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, $"Erro interno no servidor: {ex.Message.ToString()}"));
     }
 }
Пример #24
0
        public void NotificarCoafApi(Correntista correntista, Transacao transacao)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("Movimentação acima dos limites, notificando Coaf");
            builder.Append("\nNome: ");
            builder.Append(correntista.Nome);
            builder.Append("\nCPF: ");
            builder.Append(correntista.Cpf);
            builder.Append("\nValor: R$ ");
            builder.Append(transacao.Valor);
            builder.Append("\nData: ");
            builder.Append(DateTime.Now.ToString("dd/mm/yyyy HH:mm"));

            Console.WriteLine(builder.ToString());
        }
        public bool CriarOuAtualizarCorrentista(Correntista pCorrentista)
        {
            Validar(pCorrentista);

            var correntistaExistente = _dataset.Read().FirstOrDefault(x => x.Id == pCorrentista.Id);

            if (correntistaExistente == null)
            {
                _dataset.Create(pCorrentista);
            }
            else
            {
                _dataset.Update(pCorrentista);
            }

            return(true);
        }
        public async Task <bool> CriarCorrentista(Correntista model)
        {
            try
            {
                await _repositoryCorrentista.AddAsync(model);

                await _uow.CommitAsync();

                var ls = _repositoryCorrentista.GetAll().ToList();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public IActionResult NovoCorrentista([FromBody] Correntista item)
        {
            try
            {
                correntistaService.Post <CorrentistaValidator>(item);

                return(new ObjectResult(item.Id));
            }
            catch (ArgumentNullException ex)
            {
                return(NotFound(ex));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
        public void Creditar(decimal valor)
        {
            ContaCorrenteTesteService service            = new ContaCorrenteTesteService();
            TestService <Correntista> serviceCorrentista = new TestService <Correntista>();

            var correntista = new Correntista();

            correntista.Nome     = "Teste";
            correntista.CPF      = "11111";
            correntista.Telefone = "33333";
            correntista.Endereco = "Teste";
            serviceCorrentista.Post <CorrentistaValidator>(correntista);

            var novaConta = new ContaCorrente();

            Assert.NotNull(novaConta);
            novaConta.saldo         = 1000;
            novaConta.limiteCredito = 500;
            novaConta.IdCorrentista = correntista.Id;
            service.Post <ContaCorrenteValidator>(novaConta);

            var conta = service.Get(novaConta.Id);

            // Se houver erro em validações, deve dar erro ao adicionar no banco.
            if (valor == 0)
            {
                Assert.Throws <System.Exception>(() => service.Debitar(novaConta.Id, valor));
                return;
            }

            var contaAtualizada = service.Creditar(novaConta.Id, valor);

            var conta2 = service.Get(novaConta.Id);

            Assert.Equal(contaAtualizada.saldo, (conta.saldo + valor));
        }
Пример #29
0
 public static void Dump(Correntista c)
 {
     Console.WriteLine("\n{0}", c.Nome);
     Console.WriteLine(c.Idade);
     Console.WriteLine(c.SenhaCartão);
 }
 public void ExcluirCorrentista(Correntista pCorrentista)
 {
     _dataset.Delete(pCorrentista);
 }