Ejemplo n.º 1
0
 public ActionResult Edit([Bind(Include = "Id,RazaoSocial,NomeFantasia,NomeCompleto,RG,CPF,DataNascimento,CNPJ,Email,Telefone,Celular,Status,LimiteCredito,TipoPessoaId,PapelPessoaId")] Pessoa pessoa, string viewName)
 {
     if (ModelState.IsValid)
     {
         db.Entry(pessoa).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction(viewName));
     }
     return(View(pessoa));
 }
Ejemplo n.º 2
0
        public ActionResult Edit(Produto produto)
        {
            try
            {
                ViewBag.PaisId  = new SelectList(db.Paises.Where(x => x.Status != false), "Id", "Nome", produto.PaisId);
                ViewBag.SafraId = new SelectList(db.Safras.Where(x => x.Status != false), "Id", "Ano", produto.SafraId);

                if (!Validations.HasCredentials(User.Identity.GetUserName(), "Edit", "Produtos"))
                {
                    return(RedirectToAction("Index", "Home"));
                }
                if (ModelState.IsValid)
                {
                    if (!ValidaCampos(produto))
                    {
                        return(View(produto));
                    }
                    produto.Status          = true;
                    db.Entry(produto).State = EntityState.Modified;
                    db.SaveChanges();
                    TempData["Success"] = "Registro salvo com sucesso.";
                    return(RedirectToAction("Index"));
                }
                ViewBag.PaisId  = new SelectList(db.Paises, "Id", "Nome", produto.PaisId);
                ViewBag.SafraId = new SelectList(db.Safras, "Id", "Ano", produto.SafraId);
                return(View(produto));
            }
            catch (Exception ex)
            {
                TempData["Error"] = "Ocorreu um erro,entre em contato com o administrador do sistema!";
                return(RedirectToAction("Index"));

                throw ex;
            }
        }
 public ActionResult Edit([Bind(Include = "Id,Nome,Cpf,Email,Senha,Sexo,Endereco,Cep,Cidade,Estado,DataNasc,Telefone,Celular,DataCadastro,StatusId")] Participante participante)
 {
     if (ModelState.IsValid)
     {
         db.Entry(participante).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(participante));
 }
Ejemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "Id,Ano")] Safra safra)
 {
     if (ModelState.IsValid)
     {
         db.Entry(safra).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(safra));
 }
Ejemplo n.º 5
0
 public ActionResult Edit([Bind(Include = "Id,isVenda,isPessoaFisica,DataPedido,Quantidade,Total,PessoaId")] Pedido pedido)
 {
     if (ModelState.IsValid)
     {
         db.Entry(pedido).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PessoaId = new SelectList(db.Pessoas, "Id", "RazaoSocial", pedido.PessoaId);
     return(View(pedido));
 }
Ejemplo n.º 6
0
        public ActionResult Edit([Bind(Include = "Id,Nome")] Pais pais)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(pais).State = EntityState.Modified;
                    db.SaveChanges();
                    TempData["Success"] = "Registro salvo com sucesso.";
                    return(RedirectToAction("Index"));
                }
                return(View(pais));
            }
            catch (Exception ex)
            {
                TempData["Error"] = "Ocorreu um erro,entre em contato com o administrador do sistema!";
                return(RedirectToAction("Index"));

                throw ex;
            }
        }
Ejemplo n.º 7
0
        public ActionResult Edit([Bind(Include = "Id,Estado,Cidade,Bairro,CEP,Rua,Numero,Complemento,Status,PessoaId")] Endereco endereco)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(endereco).State = EntityState.Modified;
                    db.SaveChanges();
                    TempData["Success"] = "Registro salvo com sucesso.";
                    return(RedirectToAction("Index"));
                }
                ViewBag.PessoaId = new SelectList(db.Pessoas, "Id", "RazaoSocial", endereco.PessoaId);
                return(View(endereco));
            }
            catch (Exception ex)
            {
                TempData["Error"] = "Ocorreu um erro,entre em contato com o administrador do sistema!";
                return(RedirectToAction("Index"));

                throw ex;
            }
        }
        public ActionResult Create(ClienteEnderecoViewModel Cliente, string botao, FormCollection colecao, int?idEndereco)
        {
            try
            {
                if (!Validations.HasCredentials(User.Identity.GetUserName(), "Create", "ClientePessoaJuridica"))
                {
                    return(RedirectToAction("Index", "Home"));
                }
                int IdCliente = 0;
                if (botao == "addCliente")
                {
                    if (Cliente.Pessoa != null)
                    {
                        if (!ValidaCamposPessoaJuridica(Cliente.Pessoa))
                        {
                            return(View(Cliente));
                        }
                        Cliente.Pessoa.Status = true;
                        db.Pessoas.Add(Cliente.Pessoa);
                        db.SaveChanges();
                        IdCliente           = Cliente.Pessoa.Id;
                        Cliente.Pessoa      = Cliente.Pessoa;
                        TempData["Success"] = "Registro salvo com sucesso.";
                    }
                    ViewBag.idCliente = IdCliente;
                    return(View(Cliente));
                }
                if (botao == "addEndereco")
                {
                    if (Cliente.Enderecos == null)
                    {
                        Cliente.Enderecos = new List <Endereco>();
                    }
                    Cliente.Endereco.Status = true;
                    Cliente.Enderecos.Add(Cliente.Endereco);
                    db.Enderecos.Add(Cliente.Endereco);
                    db.SaveChanges();
                    Cliente.Enderecos   = db.Enderecos.AsNoTracking().Where(x => x.PessoaId == Cliente.Endereco.PessoaId).ToList();
                    ViewBag.idCliente   = Cliente.Endereco.PessoaId;
                    TempData["Success"] = "Registro salvo com sucesso.";
                    return(View(Cliente));
                }
                if (botao == "finalizarCadastro")
                {
                    TempData["Success"] = "Registro salvo com sucesso.";
                    return(RedirectToAction("Index", "ClientePessoaJuridica"));
                }
                if (botao == "deletarEndereco")
                {
                    //var cliente = db.Pessoas.Where(m => m.EnderecoId == idEndereco).First();
                    var endereco = db.Enderecos.Include(p => p.Pessoa).Where(e => e.Id == idEndereco).First();
                    endereco.Status          = false;
                    db.Entry(endereco).State = EntityState.Modified;
                    db.SaveChanges();

                    Cliente.Pessoa = endereco.Pessoa;
                    if (Cliente.Enderecos == null)
                    {
                        Cliente.Enderecos = new List <Endereco>();
                    }
                    Cliente.Enderecos   = db.Enderecos.AsNoTracking().Where(x => x.PessoaId == Cliente.Pessoa.Id).Where(x => x.Status == true).ToList();
                    ViewBag.idCliente   = Cliente.Pessoa.Id;
                    TempData["Success"] = "Registro salvo com sucesso.";
                    return(View(Cliente));
                }
                return(RedirectToAction("Index", "ClientePessoaJuridica"));
            }
            catch (Exception ex)
            {
                TempData["Error"] = "Ocorreu um erro,entre em contato com o administrador do sistema!";
                return(RedirectToAction("Index"));

                throw ex;
            }
        }