public DetailEmployeViewModel() { cardAffectations = new CardAffectationServiceViewModel(); cardEmploye = new CardEmployeViewModel(); cardUtilisateur = new CardEmployeUtilisateurViewModel(); adresse = new AdresseDTO(); }
public ActionResult DeleteAffectationDetail(int idToDelete) { CardAffectationServiceViewModel modelOut = new CardAffectationServiceViewModel(); EmployeDTO emp = new EmployeDTO(); //On conserve l'id de l'employé correspondant pour recontruire ensuite l'affiche de ses affectations int idEmploye = _affectationService.Get(idToDelete).employe.id; try { emp = Mapper.Map <Employe, EmployeDTO>(_employeService.Get(idEmploye)); //Un employé doit avoir au moins une affectation if (emp.affectationServices.Count == 1) { modelOut.notifications.Add(new Notification { dureeNotification = Parametres.DureeNotification.Always, message = "Un employé doit avoir au moins une affectation", typeNotification = Parametres.TypeNotification.Warning }); //On reconstruit l'affichage modelOut.tableauAffectations.avecActionCrud = false; modelOut.tableauAffectations.lesLignes.Add(new List <object> { "Service", "Droit", "Activité principale", "" }); if (emp.affectationServices != null) { foreach (AffectationServiceDTO affectation in emp.affectationServices) { modelOut.tableauAffectations.lesLignes.Add(new List <object> { affectation.service.libe, affectation.groupe.libe, affectation.affectationPrincipaleOuiNon(), affectation.id }); } } #region préparation des éléments utiles à la création d'une affectation modelOut.lesDroits = _donneListeGroupeUtilisateur(); modelOut.lesServices = _donneListeService(); modelOut.nouvelleAffectation.emplyeId = emp.id; #endregion return(PartialView("~/Areas/RessourcesHumaines/Views/Employe/_CardAffectationPartial.cshtml", modelOut)); } //On supprimer l'affectation _affectationService.Delete(idToDelete, _donneNomPrenomUtilisateur()); _affectationService.Save(); FlashMessage.Confirmation("Suppression de l'affectation avec succès"); emp = Mapper.Map <Employe, EmployeDTO>(_employeService.Get(idEmploye)); //On reconstruit l'affichage modelOut.tableauAffectations.avecActionCrud = false; modelOut.tableauAffectations.lesLignes.Add(new List <object> { "Service", "Droit", "Activité principale", "" }); if (emp.affectationServices != null) { foreach (AffectationServiceDTO affectation in emp.affectationServices) { modelOut.tableauAffectations.lesLignes.Add(new List <object> { affectation.service.libe, affectation.groupe.libe, affectation.affectationPrincipaleOuiNon(), affectation.id }); } } #region préparation des éléments utiles à la création d'une affectation modelOut.lesDroits = _donneListeGroupeUtilisateur(); modelOut.lesServices = _donneListeService(); modelOut.nouvelleAffectation.emplyeId = emp.id; #endregion } catch (Exception e) { FlashMessage.Danger("Erreur lors de la suppression de l'affectation"); //On reconstruit l'affichage modelOut.tableauAffectations.avecActionCrud = false; modelOut.tableauAffectations.lesLignes.Add(new List <object> { "Service", "Droit", "Activité principale", "" }); if (emp.affectationServices != null) { foreach (AffectationServiceDTO affectation in emp.affectationServices) { modelOut.tableauAffectations.lesLignes.Add(new List <object> { affectation.service.libe, affectation.groupe.libe, affectation.affectationPrincipaleOuiNon(), affectation.id }); } } #region préparation des éléments utiles à la création d'une affectation modelOut.lesDroits = _donneListeGroupeUtilisateur(); modelOut.lesServices = _donneListeService(); modelOut.nouvelleAffectation.emplyeId = emp.id; #endregion return(PartialView("~/Areas/RessourcesHumaines/Views/Employe/_CardAffectationPartial.cshtml", modelOut)); } _updateSession(); return(PartialView("~/Areas/RessourcesHumaines/Views/Employe/_CardAffectationPartial.cshtml", modelOut)); }
public ActionResult DetailAjoutAffectation(NouvelleAffectationDTO nouvelleAffectation) { CardAffectationServiceViewModel modelOut = new CardAffectationServiceViewModel(); AffectationService newAffectation = new AffectationService(); Employe emp = new Employe(); EmployeDTO emplo = new EmployeDTO(); try { emp = _employeService.Get(nouvelleAffectation.emplyeId); newAffectation.groupe = _droitService.Get(nouvelleAffectation.groupeIdPourAffectation); newAffectation.service = _serviceService.Get(nouvelleAffectation.serviceIdPourAffectation); newAffectation.isPrincipal = nouvelleAffectation.isAffecttionPrincipal; _insertOrUpdateAffectation(ref emp, newAffectation); _employeService.Update(emp, _donneNomPrenomUtilisateur()); _employeService.Save(); FlashMessage.Confirmation("Ajout de l'affectation avec succès"); #region tableau des affectations de l'employé //On récupère l'employé avecla dernière affectation emplo = Mapper.Map <Employe, EmployeDTO>(_employeService.Get(nouvelleAffectation.emplyeId)); //On prépare le tableau récapitulant les affectations de l'employé modelOut.tableauAffectations.avecActionCrud = false; modelOut.tableauAffectations.lesLignes.Add(new List <object> { "Service", "Droit", "Activité principale", "" }); if (emplo.affectationServices != null) { foreach (AffectationServiceDTO affectation in emplo.affectationServices) { modelOut.tableauAffectations.lesLignes.Add(new List <object> { affectation.service.libe, affectation.groupe.libe, affectation.affectationPrincipaleOuiNon(), affectation.id }); } } #endregion modelOut.nouvelleAffectation.emplyeId = nouvelleAffectation.emplyeId; modelOut.lesDroits = _donneListeGroupeUtilisateur(); modelOut.lesServices = _donneListeService(); //On met à jour l'utilisateur en session, car lesa ffectations influes sur les éléments du menu de navigation _updateSession(); } catch (Exception e) { emplo = Mapper.Map <Employe, EmployeDTO>(_employeService.Get(nouvelleAffectation.emplyeId)); #region tableau des affectations de l'employé //On prépare le tableau récapitulant les affectations de l'employé modelOut.tableauAffectations.avecActionCrud = false; modelOut.tableauAffectations.lesLignes.Add(new List <object> { "Service", "Droit", "Activité principale", "" }); if (emplo.affectationServices != null) { foreach (AffectationServiceDTO affectation in emplo.affectationServices) { modelOut.tableauAffectations.lesLignes.Add(new List <object> { affectation.service.libe, affectation.groupe.libe, affectation.affectationPrincipaleOuiNon(), "" }); } } #endregion modelOut.nouvelleAffectation.emplyeId = nouvelleAffectation.emplyeId; modelOut.lesDroits = _donneListeGroupeUtilisateur(); modelOut.lesServices = _donneListeService(); FlashMessage.Danger("Erreur lors de la création de l'affectation"); } return(PartialView("~/Areas/RessourcesHumaines/Views/Employe/_CardAffectationPartial.cshtml", modelOut)); }