// GET: Employes/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var employe = await _context.Employes.Include(e => e.Personne).FirstOrDefaultAsync(e => e.EmployeId == id); if (employe == null) { return(NotFound()); } EditEmployeViewModel editEmployeViewModel = new EditEmployeViewModel { EmployeId = (int)id, Nom = employe.Personne.Nom, Prenom = employe.Personne.Prenom, Sexe = employe.Personne.Sexe, NumSecu = employe.Personne.NumSecu, DateNaissance = employe.Personne.DateNaissance, Telephone = employe.Telephone, Externe = (byte)employe.Externe, Poste = employe.Poste }; return(View(editEmployeViewModel)); }
public async Task <IActionResult> Edit(int id, EditEmployeViewModel editEmployeViewModel) { if (id != editEmployeViewModel.EmployeId) { return(NotFound()); } if (ModelState.IsValid) { try { Personne personne = new Personne { PersonneId = id, Nom = editEmployeViewModel.Nom, Prenom = editEmployeViewModel.Prenom, Sexe = editEmployeViewModel.Sexe, DateNaissance = editEmployeViewModel.DateNaissance, NumSecu = editEmployeViewModel.NumSecu, Discriminator = "Employe" }; _context.Update(personne); await _context.SaveChangesAsync(); string telephone = phoneRegex.Replace(editEmployeViewModel.Telephone, "($1) $2-$3"); Employe employe = new Employe { EmployeId = id, Personne = personne, Externe = editEmployeViewModel.Externe, Poste = editEmployeViewModel.Poste, Telephone = telephone }; _context.Update(employe); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeExists(editEmployeViewModel.EmployeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(editEmployeViewModel)); }
public ActionResult EditModal(int?id) { //On renseigne le service courant pour adapater l'IHM en fonction des droits de l'utilisateur connecté Session["service"] = _service; BootstrapModalViewModel modelOut = new BootstrapModalViewModel(); EditEmployeViewModel editEmploye = new EditEmployeViewModel(); BootstrapButtonViewModel button = new BootstrapButtonViewModel(); if (id.HasValue) { editEmploye.personne = Mapper.Map <Employe, EditEmployeDTO>(_employeService.Get(id.Value)); modelOut.titreModal = string.Format("Modification des informations de {0} {1} {2}", editEmploye.personne.getCiv(), editEmploye.personne.nom.ToUpperFirst(), editEmploye.personne.prenom.ToUpperFirst()); #region préparation du tableau récapitulatif des affectations //On prépare le tableau récapitulant les affectations de l'employé editEmploye.lesAffectationsEmploye.lesLignes.Add(new List <object> { "", "Service", "Droit", "Activité principale" }); if (editEmploye.personne != null) { if (editEmploye.personne.affectationServices != null) { foreach (AffectationServiceDTO affectation in editEmploye.personne.affectationServices) { button = new BootstrapButtonViewModel { href = Url.Action("Detail", "Employe", new { area = "RessourcesHumaines", id = editEmploye.personne.id }).ToString(), cssClass = "", libe = " ", typeDeBouton = Parametres.TypeBouton.Detail }; editEmploye.lesAffectationsEmploye.lesLignes.Add(new List <object> { button, affectation.service.libe, affectation.groupe.libe, affectation.affectationPrincipaleOuiNon() }); } } } #endregion } else { modelOut.titreModal = "Ajout d'un employé"; } //On récupère la liste des services disponibles dans l'application editEmploye.lesServices = _donneListeService(); //On récupère les niveaux de droits disponibles dans l'application editEmploye.lesDroits = _donneListeGroupeUtilisateur(); //On récuère la liste des types d'employés editEmploye.lesTypesEmployes = _donneListeTypeEmploye(); modelOut.formulaireUrl = "~/Areas/RessourcesHumaines/Views/Employe/_EditEmployePartial.cshtml"; modelOut.objet = editEmploye; return(PartialView("~/Views/Shared/_BootstrapModalPartial.cshtml", modelOut)); }