Esempio n. 1
0
        public ActionResult Update(FormCollection form)
        {
            Estabelecimentos estabelecimento = new Estabelecimentos();

            estabelecimento.Codigo       = Convert.ToInt32(form["Codigo"]);
            estabelecimento.Razao_Social = form["Razao"];
            estabelecimento.Fantasia     = form["Fantasia"];
            estabelecimento.Cnpj         = form["Cnpj"];
            estabelecimento.Email        = form["Email"];
            estabelecimento.Endereco     = form["Endereco"];
            estabelecimento.Cidade       = form["Cidade"];
            estabelecimento.Estado       = form["Estado"];
            estabelecimento.Telefone     = form["Telefone"];
            string dataCad = form["Data"].Replace("/", "-");

            estabelecimento.Data      = Convert.ToDateTime(dataCad);
            estabelecimento.Categoria = Convert.ToInt32(form["Categoria"]);
            estabelecimento.Status    = form["Status"];
            estabelecimento.Agencia   = form["Agencia"];
            estabelecimento.Conta     = form["Conta"];

            using (EstabelecimentoModel model = new EstabelecimentoModel())
            {
                model.Update(estabelecimento);
                return(RedirectToAction("Index"));
            }
        }
Esempio n. 2
0
 public ActionResult Excluir(int Codigo)
 {
     using (EstabelecimentoModel model = new EstabelecimentoModel())
     {
         return(View(model.Detalhes(Codigo)));
     }
 }
        public EstabelecimentoModel ExcluirEstabelecimento(EstabelecimentoModel model)
        {
            try
            {
                var context = GetContext;

                var estabelecimento = GetFirstOrDefault <EstabelecimentoModel>(context, x => x.IdEstabelecimento == model.IdEstabelecimento);

                if (estabelecimento != null)
                {
                    estabelecimento.Status = false;

                    Update(context, estabelecimento);
                    return(model);
                }

                throw new ArgumentException("Não foi possivel efetuar a exclusão, pois o estabelecimento já está excluido!");
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(ArgumentException))
                {
                    throw ex;
                }

                throw new Exception("Erro ao Excluir Estabelecimento");
            }
        }
        public EstabelecimentoModel AlterarEstabelecimento(EstabelecimentoModel model)
        {
            try
            {
                var context = GetContext;
                model.Status   = true;
                model.CNPJ     = Format.SetCnpj(model.CNPJ);
                model.Telefone = Format.SetTelefone(model.Telefone);
                if (model.IdCategoria == this.GetFirst <CategoriaModel>(GetContext, x => x.Descricao.ToUpper().Equals("SUPERMERCADO")).IdCategoria)
                {
                    if (string.IsNullOrEmpty(model.Telefone))
                    {
                        throw new ArgumentException("Para essa Categoria o Telefone deverá ser preenchido!");
                    }
                }

                Update(context, model);
                return(model);
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(ArgumentException))
                {
                    throw ex;
                }

                throw new Exception("Erro ao Alterar Estabelecimento");
            }
        }
Esempio n. 5
0
        public ERetornoEstabelecimento Edit(EstabelecimentoModel estabelecimento)
        {
            if (!Helper.ContaValida(estabelecimento.conta))
            {
                return(ERetornoEstabelecimento.ContaInvalida);
            }

            if (!Helper.AgenciaValida(estabelecimento.agencia))
            {
                return(ERetornoEstabelecimento.AgenciaInvalida);
            }

            if (!Helper.EmailValido(estabelecimento.email))
            {
                return(ERetornoEstabelecimento.EmailInvalido);
            }

            var validaCategoria = this.ValidarCategoria(estabelecimento);

            if (validaCategoria != ERetornoEstabelecimento.Ok)
            {
                return(validaCategoria);
            }

            _estabelecimentoRepository.Edit(estabelecimento);
            return(ERetornoEstabelecimento.SucessoEdicao);
        }
Esempio n. 6
0
        public IActionResult CreateEstabelecimento([FromBody] EstabelecimentoModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var estabelecimento = new Estabelecimento
            {
                EstabelecimentoNome     = model.Estabelecimento_Nome,
                EstabelecimentoCNPJ     = model.Estabelecimento_CNPJ,
                EstabelecimentoCelular  = model.Estabelecimento_Celular,
                EstabelecimentoTelefone = model.Estabelecimento_Telefone,
                EstabelecimentoEmail    = model.Estabelecimento_Email,
                EnderecoNumero          = model.Endereco_Numero,
                EnderecoLogradouro      = model.Endereco_Logradouro,
                EnderecoComplemento     = model.Endereco_Complemento,
                EnderecoBairro          = model.Endereco_Bairro,
                EnderecoCidade          = model.Endereco_Cidade,
                EnderecoEstado          = model.Endereco_Estado,
                EnderecoCEP             = model.Endereco_CEP
            };

            var newItem = _estabelecimentoRepository.CreateEstabelecimento(estabelecimento);

            model.Estabelecimento_Id = newItem.EstabelecimentoId;
            model.Endereco_Id        = newItem.EnderecoId;

            return(Ok(model));
        }
Esempio n. 7
0
        public IActionResult UpdateEstabelecimento(int estabelecimentoId, [FromBody] EstabelecimentoModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_estabelecimentoRepository.EstabelecimentoExists(estabelecimentoId))
            {
                return(NotFound($"Estabelecimento {estabelecimentoId} não existe!"));
            }

            var estabelecimento = new Estabelecimento
            {
                EstabelecimentoId       = model.Estabelecimento_Id,
                EstabelecimentoNome     = model.Estabelecimento_Nome,
                EstabelecimentoCNPJ     = model.Estabelecimento_CNPJ,
                EstabelecimentoCelular  = model.Estabelecimento_Celular,
                EstabelecimentoTelefone = model.Estabelecimento_Telefone,
                EstabelecimentoEmail    = model.Estabelecimento_Email,
                EnderecoId          = model.Endereco_Id,
                EnderecoNumero      = model.Endereco_Numero,
                EnderecoLogradouro  = model.Endereco_Logradouro,
                EnderecoComplemento = model.Endereco_Complemento,
                EnderecoBairro      = model.Endereco_Bairro,
                EnderecoCidade      = model.Endereco_Cidade,
                EnderecoEstado      = model.Endereco_Estado,
                EnderecoCEP         = model.Endereco_CEP
            };

            _estabelecimentoRepository.UpdateEstabelecimento(estabelecimento);

            return(NoContent());
        }
        public bool Create(EstabelecimentoModel estabelecimento)
        {
            var query = @"INSERT INTO Estabelecimento(razao_social, nome_fantasia, cnpj, email, endereco, cidade, estado, telefone, data_cadastro, cod_categoria, status, agencia, conta) 
                                VALUES(@razao_social, @nome_fantasia, @cnpj, @email, @endereco, @cidade, @estado, @telefone, GETDATE(), @cod_categoria, 1, @agencia, @conta)";

            return(_conn.Execute(query, estabelecimento) > 0);
        }
Esempio n. 9
0
 public ActionResult Index()
 {
     using (EstabelecimentoModel model = new EstabelecimentoModel())
     {
         List <Estabelecimentos> lista = model.Read();
         return(View(lista));
     }
 }
Esempio n. 10
0
 public ActionResult ConfirmarExcluir(int id)
 {
     using (EstabelecimentoModel model = new EstabelecimentoModel())
     {
         model.Excluir(id);
         return(RedirectToAction("Index"));
     }
 }
Esempio n. 11
0
        public ActionResult UpdateEstabelecimentos(EstabelecimentoModel estabelecimento)
        {
            var Repositorio = new EstabelecimentosRepositorio();

            Repositorio.UpdateEstabelecimentos(estabelecimento);

            TempData["Edit"] = "ESTABELECIMENTO EDITADO COM SUCESSO!";
            return(RedirectToAction("EstabelecimentosFirstScreen"));
        }
        public bool Edit(EstabelecimentoModel estabelecimento)
        {
            var query = @"UPDATE Estabelecimento SET razao_social = @razao_social, nome_fantasia = @nome_fantasia, 
                                                     email = @email, endereco = @endereco, cidade = @cidade, estado = @estado, 
                                                     telefone = @telefone, cod_categoria = @cod_categoria, agencia = @agencia, conta = @conta
                          WHERE ID = @ID";

            return(_conn.Execute(query, estabelecimento) > 0);
        }
Esempio n. 13
0
        public ActionResult CreateEstabelecimentos(EstabelecimentoModel estabelecimento)
        {
            var Estabelec = new EstabelecimentosRepositorio();

            Estabelec.CreateEstabelecimentos(estabelecimento);


            TempData["Create"] = "ESTABELECIMENTO CRIADO COM SUCESSO!";
            return(RedirectToAction("EstabelecimentosFirstScreen"));
        }
        public async Task <HttpStatusCode> UpdateEstabelecimentoAsync(EstabelecimentoModel model)
        {
            HttpResponseMessage response = await client.PutAsync(
                $"{URL}/{model.Estabelecimento_Id}",
                new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"));

            response.EnsureSuccessStatusCode();

            return(response.StatusCode);
        }
Esempio n. 15
0
 public ActionResult Detalhar(int Codigo)
 {
     using (CategoriasModel mod = new CategoriasModel())
     {
         ViewBag.Model1 = mod.LerCategorias();
     }
     using (EstabelecimentoModel model = new EstabelecimentoModel())
     {
         return(View(model.Detalhes(Codigo)));
     }
 }
        public async Task <IActionResult> EstabalecimentoAdd(EstabelecimentoModel estabelecimento)
        {
            if (!ModelState.IsValid)
            {
                throw new Exception("Propriedades Inválidas");
            }

            var newEstab = await _estabelecimentoService.CreateEstabelecimentoAsync(estabelecimento);

            return(RedirectToAction("Index"));
        }
Esempio n. 17
0
        public IActionResult CreateEstabelecimento([FromBody] EstabelecimentoModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var             estabelecimento = _mapper.Map <Estabelecimento>(model);
            Estabelecimento newItem         = _estabelecimentoRepository.CreateEstabelecimento(estabelecimento);

            model.Estabelecimento_Id = newItem.Estabelecimento_Id;
            model.Endereco_Id        = newItem.Endereco_Id;

            return(Ok(model));
        }
        public bool UpdateEstabelecimentos(EstabelecimentoModel estabelecimento)
        {
            try
            {
                var           connectionDb = ConfigurationManager.ConnectionStrings["bdConnection"].ConnectionString;
                SqlConnection Connect      = new SqlConnection(connectionDb);

                var UpdateClientes = Connect.Execute("update [ESTABELECIMENTOS] set Razao_Social = @Razao_Social, Nome_Fantasia = @Nome_Fantasia, CNPJ = @CNPJ, Email = @Email, Endereco = @Endereco, Cidade = @Cidade, Estado = @Estado, Telefone = @Telefone, Categoria = @Categoria, Status = @Status, Agencia = @Agencia, Conta = @Conta where id = @Id", estabelecimento);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public async Task <IActionResult> UpdateEstabelecimento(EstabelecimentoModel estabelecimento)
        {
            // Repensar em como fazer aqui
            if (!ModelState.IsValid)
            {
                throw new Exception("Propriedades Inválidas");
            }

            if (!Validators.ValidarCNPJ(estabelecimento.Estabelecimento_CNPJ))
            {
                throw new Exception("CNPJ Inválido");
            }

            await _estabelecimentoService.UpdateEstabelecimentoAsync(estabelecimento);

            return(RedirectToAction("Index"));
        }
Esempio n. 20
0
        private ERetornoEstabelecimento ValidarCategoria(EstabelecimentoModel estabelecimento)
        {
            if (estabelecimento.cod_categoria == null)
            {
                return(ERetornoEstabelecimento.Ok);
            }

            var categoria = _categoriaService.GetSingle((long)estabelecimento.cod_categoria);

            switch (categoria.nome.ToUpper())
            {
            case "SUPERMERCADO":
                return((String.IsNullOrEmpty(estabelecimento.telefone)) ? ERetornoEstabelecimento.TelefoneObrigatorio : ERetornoEstabelecimento.Ok);

            default:
                return(ERetornoEstabelecimento.Ok);
            }
        }
        public bool CreateEstabelecimentos(EstabelecimentoModel estabelecimento)
        {
            try
            {
                var           connectionDb = ConfigurationManager.ConnectionStrings["bdConnection"].ConnectionString;
                SqlConnection Connect      = new SqlConnection(connectionDb);

                estabelecimento.Data_de_Cadastro = DateTime.Now;

                var resultado = Connect.Execute("insert into [ESTABELECIMENTOS] values (@Razao_Social, @Nome_Fantasia, @CNPJ, @Email, @Endereco, @Cidade, @Estado, @Telefone, @Data_de_Cadastro, @Categoria, @Status, @Agencia, @Conta)", estabelecimento);

                return(true);
            }
            catch (Exception varNecessary)
            {
                return(false);
            }
        }
Esempio n. 22
0
        public IActionResult UpdateEstabelecimento(int estabelecimentoId, [FromBody] EstabelecimentoModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_estabelecimentoRepository.EstabelecimentoExists(estabelecimentoId))
            {
                return(NotFound($"Estabelecimento {estabelecimentoId} não existe!"));
            }

            var estabelecimento = _mapper.Map <Estabelecimento>(model);

            _estabelecimentoRepository.UpdateEstabelecimento(estabelecimento);

            return(NoContent());
        }
        public ReturnAllServices Atualizar([FromBody] EstabelecimentoModel dados)
        {
            ReturnAllServices retorno = new ReturnAllServices();

            try
            {
                dados.Atualizar();
                retorno.Result       = true;
                retorno.ErrorMessege = string.Empty;
            }
            catch (Exception ex)
            {
                retorno.Result       = false;
                retorno.ErrorMessege = "Erro ao tentar atualizar um Estabelecimento: " + ex.Message;
            }

            return(retorno);
        }
        public ReturnAllServices Status(int id)
        {
            ReturnAllServices retorno = new ReturnAllServices();

            try
            {
                EstabelecimentoModel dados = Retornar(id);
                dados.Id_Status = (dados.Id_Status == 0 ? 1 : 0);
                dados.StatusEstabelecimento();
                retorno.Result       = true;
                retorno.ErrorMessege = string.Empty;
            }
            catch (Exception ex)
            {
                retorno.Result       = false;
                retorno.ErrorMessege = "Erro ao tentar atualizar um Estabelecimento: " + ex.Message;
            }

            return(retorno);
        }
        public async Task <EstabelecimentoModel> CreateEstabelecimentoAsync(EstabelecimentoModel model)
        {
            var estabelecimento = new EstabelecimentoModel();

            HttpResponseMessage response = await client.PostAsync(
                URL,
                new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"));

            response.EnsureSuccessStatusCode();
            if (response.IsSuccessStatusCode)
            {
                using (var respostaStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
                {
                    return(JsonConvert.DeserializeObject <EstabelecimentoModel>(
                               await new StreamReader(respostaStream).
                               ReadToEndAsync().ConfigureAwait(false)));
                }
            }

            return(estabelecimento);
        }
Esempio n. 26
0
        public ERetornoEstabelecimento Create(EstabelecimentoModel estabelecimento)
        {
            if (_estabelecimentoRepository.FindByCnpj(estabelecimento.cnpj) != null)
            {
                return(ERetornoEstabelecimento.CnpjJaUtilizado);
            }

            if (!Helper.CnpjValido(estabelecimento.cnpj))
            {
                return(ERetornoEstabelecimento.CnpjInvalido);
            }

            if (!Helper.ContaValida(estabelecimento.conta))
            {
                return(ERetornoEstabelecimento.ContaInvalida);
            }

            if (!Helper.AgenciaValida(estabelecimento.agencia))
            {
                return(ERetornoEstabelecimento.AgenciaInvalida);
            }

            if (!Helper.EmailValido(estabelecimento.email))
            {
                return(ERetornoEstabelecimento.EmailInvalido);
            }

            var validaCategoria = this.ValidarCategoria(estabelecimento);

            if (validaCategoria != ERetornoEstabelecimento.Ok)
            {
                return(validaCategoria);
            }

            _estabelecimentoRepository.Create(estabelecimento);
            return(ERetornoEstabelecimento.SucessoCadastro);
        }
        public async Task <IActionResult> DeleteEstabelecimento(EstabelecimentoModel estabelecimento)
        {
            await _estabelecimentoService.DeleteEstabelecimentoAsync((int)estabelecimento.Estabelecimento_Id);

            return(RedirectToAction("Index"));
        }
        private void btnConfirmar_Click(object sender, EventArgs e)
        {
            try
            {
                var totalDespesas = new decimal();
                //
                try
                {
                    foreach (DataGridViewRow linha in this.dataGridView1.Rows)
                    {
                        if (linha.Cells["clValorPago"].Value == null)
                        {
                            throw new Exception("Valor Pago inválido !");
                        }
                        else if (Convert.ToDecimal(linha.Cells["clValorPago"].Value) < Convert.ToDecimal(linha.Cells["clValorTotal"].Value))
                        {
                            throw new Exception("Valor pago não pode ser menor que o valor do Título !");
                        }
                        else
                        {
                            totalDespesas += Convert.ToDecimal(linha.Cells["clValorPago"].Value) - Convert.ToDecimal(linha.Cells["clValorTotal"].Value);
                        }
                    }
                }
                catch (InvalidCastException)
                {
                    throw new Exception("Valor Pago inválido !");
                }
                catch (ArgumentNullException)
                {
                    throw new Exception("Valor Pago inválido !");
                }
                catch (NullReferenceException)
                {
                    throw new Exception("Valor Pago inválido !");
                }
                catch (Exception exception)
                {
                    throw new Exception(exception.Message);
                }
                //
                if (MessageBox.Show(string.Format("Confirma a líquidação de {0} título ?", this.lancamentoListaModel.Count.ToString()), "Responda", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                {
                    try
                    {
                        foreach (DataGridViewRow linha in this.dataGridView1.Rows)
                        {
                            var retorno = string.Empty;
                            //
                            retorno = new LancamentoDAO().LancamentoInserir(new LancamentoModel
                            {
                                IdLancamento   = Convert.ToInt32(linha.Cells["clIdLancamento"].Value),
                                DataLiquidacao = Convert.ToDateTime(this.dtpDataPagamento.Value),
                                ValorLiquidado = Convert.ToDecimal(linha.Cells["clValorPago"].Value)
                                                 //
                            });
                            //
                            if (!Char.IsNumber(retorno, 0))
                            {
                                throw new Exception(string.Format("Erro ao líquidar lançamento !\n{0}", retorno));
                            }
                        }
                        //
                        Mensagens.MensagemInformacao("Títulos líquidados com sucesso !");
                        if (totalDespesas > 0)
                        {
                            var estabelecimento = new EstabelecimentoModel();
                            var fornecedor      = new FornecedorModel();
                            //
                            foreach (var item in this.lancamentoListaModel)
                            {
                                estabelecimento = new EstabelecimentoModel {
                                    IdEstabelecimento = item.Estabelecimento.IdEstabelecimento
                                };
                                fornecedor = new FornecedorModel {
                                    IdFornecedor = item.Fornecedor.IdFornecedor
                                };
                            }
                            using (var f = new DespesaBoletoForm(new DespesaModel
                            {
                                Valor = totalDespesas,
                                Parceiro = fornecedor,
                                Estabelecimento = estabelecimento,
                                DataMovimento = this.dtpDataPagamento.Value,
                                DescricaoDespesa = string.Format("TAXA BOL. LIQ LOTE")
                            }))
                            {
                                f.ShowDialog();
                            }
                        }


                        this.Close();
                    }
                    catch (FormatException)
                    {
                        Mensagens.MensagemErro("Valor Inválido");
                    }
                    catch (Exception exception)
                    {
                        Mensagens.MensagemErro(exception.Message);
                    }
                }
            }
            catch (Exception exception)
            {
                Mensagens.MensagemErro(exception.Message);
            }
        }
        public IHttpActionResult Atualizar([FromBody] EstabelecimentoModel estabelecimento)
        {
            _estabelecimentoCommandService.Salvar(_estabelecimentoTransformer.Reverse(estabelecimento));

            return(Ok());
        }