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); } }
// 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); }
public string excluirCliente(Cliente c) { string erro = null; try { db.Cliente.DeleteObject(c); db.SaveChanges(); } catch (Exception ex) { erro = ex.Message; } return erro; }
public string adicionarCliente(Cliente c) { string erro = null; try { db.Cliente.AddObject(c); db.SaveChanges(); } catch (Exception ex) { erro = ex.Message; } return erro; }
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; }
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; }
public ActionResult Create(Cliente c) { clienteModel.adicionarCliente(c); return RedirectToAction("Index"); }
/// <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; }
/// <summary> /// Deprecated Method for adding a new object to the Cliente EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCliente(Cliente cliente) { base.AddObject("Cliente", cliente); }