public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (ClientsDAO.GetAllClients().Count(c => c.Id == Id) > 0) { yield return(new ValidationResult(Id + " existe déjà", new[] { "Id" })); } }
[HttpPost] public ActionResult AjouterBack(String id, String nom, String prenom, DateTime DateNaissance) { Client c = new Client(id, nom, prenom, DateNaissance); ClientsDAO.UpdateOrAddClient(c); return(View("Index", ClientsDAO.GetAllClients())); }
[HttpPost] public ActionResult Ajouter(Client client)//, String firstname) { //client.Prenom = firstname; //client.Prenom = Request.Form["firstname"] //client.Prenom = Request.Form.GetValues("firstname")[0]; if (ModelState.IsValid) { ClientsDAO.UpdateOrAddClient(client); return(View("Index", ClientsDAO.GetAllClients())); } return(View(client)); }
[HttpPost] public ActionResult Editer(Client client, String Birthday) { ModelState.Remove("Id"); DateTime dd; DateTime.TryParseExact(Birthday, "dd/MM/yyyy", CultureInfo.CurrentCulture, DateTimeStyles.None, out dd); client.DateNaissance = dd; if (client.DateNaissance != null && client.DateNaissance.CompareTo(DateTime.Now) > 0) { ModelState.AddModelError("DateNaissance", "Trop fort!"); } if (ModelState.IsValid) { ClientsDAO.UpdateOrAddClient(client); return(View("Index", ClientsDAO.GetAllClients())); } return(View(client)); }
public ActionResult Index() { return(View(ClientsDAO.GetAllClients())); }