public void Update(UserDTO newPacket) { Validate(newPacket); Contact contact = FormateContact(newPacket); User user = FormateUser(newPacket, contact); int ContactIdToDelete = -1; if (UserDAO.ReferenceToThisContact(user) > 1) { ContactDAO.Save(contact); user.ContactId = contact.Id; } else { ContactIdToDelete = ContactDAO.Update(user); user.ContactId = contact.Id; } UserDAO.Update(user); if (ContactIdToDelete > 0) { ContactDAO.Delete(ContactIdToDelete); } }
public void Delete(User user) { UserDAO.Delete(user); if (UserDAO.ReferenceToThisContact(user) == 0) { ContactDAO.Delete(user.Contact); } }
public JsonResult Delete(int ID) { return(Json(ContactDAO.Delete(ID), JsonRequestBehavior.AllowGet)); }
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); }