public ActionResult Create(Contact contact, string tempstatus) { if (ModelState.IsValid) { if (tempstatus == "Kích Hoạt") { contact.Status = true; } else { contact.Status = false; } ContactDAO contactDAO = new ContactDAO(); int check = contactDAO.Create(contact); if (check > 0) { TempData["msg"] = MessageBox.Show("Create Success"); RedirectToAction("Create", "Contact"); } else { ModelState.AddModelError("", "Create fail"); } } return(View("Create")); }
public ActionResult FormContact(string id) { ActionResult retour = View(); if (Session["UserID"] == null) { retour = RedirectToAction("Login"); } else { ContactDAO contactDao = new ContactDAO(); Contact contact = new Contact(); ViewBag.contact = contact; if (Request.HttpMethod == "POST") { int idContact = Int32.Parse(Request.Form["idContact"]); string nom = Request.Form["nom"]; string prenom = Request.Form["prenom"]; string mel = Request.Form["adresseMel"]; string numeroTelephone = Request.Form["numeroTelephone"]; string poste = Request.Form["poste"]; string commentaire = Request.Form["commentaire"]; List <Etablissement> listeEmployeur = new List <Etablissement>(); contact = new Contact(poste, commentaire, listeEmployeur, idContact, nom, prenom, mel, numeroTelephone); if (idContact == 0) { contactDao.Create(contact); } else { contactDao.Update(contact); } ViewBag.contact = contact; retour = View("FicheContact"); } else { if (!String.IsNullOrWhiteSpace(id)) { if (Int32.TryParse(id, out int idContact)) { if (contactDao.Read(idContact) != null) { contact = contactDao.Read(idContact); if ((Request.HttpMethod == "GET") && (Request.Params["action"] != null)) { if (Request.Params["action"] == "del") { contactDao.Delete(contact); retour = RedirectToAction("FicheEtablissement"); } } else { ViewBag.contact = contact; } } } } } } return(retour); }