public CardAffectationServiceViewModel()
 {
     lesServices         = new List <SelectListItem>();
     lesDroits           = new List <SelectListItem>();
     nouvelleAffectation = new NouvelleAffectationDTO();
     tableauAffectations = new BootstrapTableViewModel();
 }
Exemplo n.º 2
0
        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));
        }