Esempio n. 1
0
        public ActionResult Edit(Cliente c)
        {
            string erro = clienteModel.validarCliente(c);
            if (erro == null)
            {
                if (c.IdCliente == 0)
                {
                    erro = clienteModel.adicionarCliente(c);
                }
                else
                {
                    erro = clienteModel.editarCliente(c);
                }
            }

            if (erro == null)
            {
                return RedirectToAction("Index");
            }
            else
            {
                ViewBag.Error = erro;
                return View(c);
            }
        }
Esempio n. 2
0
 // localhost:8080/Cliente/Edit/8
 public ActionResult Edit(int id)
 {
     Cliente c;
     if (id == 0)
     {
         c = new Cliente();
     }
     else
     {
         c = clienteModel.obterCliente(id);
     }
     return View(c);
 }
Esempio n. 3
0
 public string excluirCliente(Cliente c)
 {
     string erro = null;
     try
     {
         db.Cliente.DeleteObject(c);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         erro = ex.Message;
     }
     return erro;
 }
Esempio n. 4
0
 public string adicionarCliente(Cliente c)
 {
     string erro = null;
     try
     {
         db.Cliente.AddObject(c);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         erro = ex.Message;
     }
     return erro;
 }
Esempio n. 5
0
 public string editarCliente(Cliente c)
 {
     string erro = null;
     try
     {
         if (c.EntityState == System.Data.EntityState.Detached)
         {
             db.Cliente.Attach(c);
         }
         db.ObjectStateManager.ChangeObjectState(c, System.Data.EntityState.Modified);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         erro = ex.Message;
     }
     return erro;
 }
Esempio n. 6
0
 public string validarCliente(Cliente c)
 {
     if (c.Nome == null || c.Nome == "")
     {
         return "O nome não pode ser vazio!";
     }
     if (c.CPF == null || c.CPF.Length > 11)
     {
         return "CPF inválido";
     }
     if (c.DataNascimento == null || c.DataNascimento > DateTime.Now.Date)
     {
         return "Data de nascimento inválida";
     }
     if (c.Email == null || c.Email == "")
     {
         return "E-mail inválido";
     }
     return null;
 }
Esempio n. 7
0
 public ActionResult Create(Cliente c)
 {
     clienteModel.adicionarCliente(c);
     return RedirectToAction("Index");
 }
Esempio n. 8
0
 /// <summary>
 /// Create a new Cliente object.
 /// </summary>
 /// <param name="idCliente">Initial value of the IdCliente property.</param>
 /// <param name="nome">Initial value of the Nome property.</param>
 /// <param name="email">Initial value of the Email property.</param>
 /// <param name="cPF">Initial value of the CPF property.</param>
 /// <param name="dataNascimento">Initial value of the DataNascimento property.</param>
 public static Cliente CreateCliente(global::System.Int32 idCliente, global::System.String nome, global::System.String email, global::System.String cPF, global::System.DateTime dataNascimento)
 {
     Cliente cliente = new Cliente();
     cliente.IdCliente = idCliente;
     cliente.Nome = nome;
     cliente.Email = email;
     cliente.CPF = cPF;
     cliente.DataNascimento = dataNascimento;
     return cliente;
 }
Esempio n. 9
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Cliente EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCliente(Cliente cliente)
 {
     base.AddObject("Cliente", cliente);
 }