public ActionResult Login(UtilisateurLoginDTO loginUtilisateur)
        {
            Models.ViewModel.LoginViewModel model = new Models.ViewModel.LoginViewModel();
            EmployeDTO util = Mapper.Map <Employe, EmployeDTO>(_employeService.TrouveUtilisateur(loginUtilisateur.login, loginUtilisateur.password));

            if (util != null)
            {
                Session["utilisateur"] = util;

                _traceService.create(new ApplicationTrace
                {
                    utilisateur = _donneNomPrenomUtilisateur(),
                    action      = Parametres.Action.Connexion.ToString(),
                    description = string.Format("Connexion de {0} {1}", util.nom.ToUpperFirst(), util.prenom.ToUpperFirst())
                });

                _traceService.save();

                return(RedirectToAction("Index", "MaderaSoft"));
            }

            model.loginUtilisateur.login    = loginUtilisateur.login;
            model.loginUtilisateur.password = loginUtilisateur.password;

            model.notifications.Add(new Models.Notification
            {
                dureeNotification = Parametres.DureeNotification.Always,
                message           = "Couple identifiant/mot de passe incorect",
                typeNotification  = Parametres.TypeNotification.Danger
            });

            return(RedirectToAction("Index", "MaderaSoft"));
        }
        private string _donneNomPrenomUtilisateur()
        {
            EmployeDTO emp = (EmployeDTO)HttpContext.Session["utilisateur"];

            if (emp != null)
            {
                return(string.Format("{0} {1}", emp.nom.ToUpperFirst(), emp.prenom.ToUpperFirst()));
            }
            else
            {
                return("");
            }
        }
        private EmployeDTO Transform(Employe employee)
        {
            var dto = new EmployeDTO()
            {
                Id              = employee.Id,
                Name            = employee.Name,
                ContractType    = employee.ContractType,
                RoleId          = employee.RoleId,
                RoleName        = employee.RoleName,
                RoleDescription = employee.RoleDescription,
            };

            var calculator = _factory.Build(dto.ContractType);

            dto.CalculatedSalary = calculator.Calculate(employee);
            return(dto);
        }
        private void _updateSession()
        {
            EmployeDTO emp = (EmployeDTO)HttpContext.Session["utilisateur"];

            Session["utilisateur"] = Mapper.Map <Employe, EmployeDTO>(_employeService.Get(emp.id));
        }
        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));
        }
        public ActionResult Detail(int id)
        {
            //On renseigne le service courant pour adapater l'IHM en fonction des droits de l'utilisateur connecté
            Session["service"] = _service;

            DetailEmployeViewModel modelOut = new DetailEmployeViewModel();
            EmployeDTO             emp      = Mapper.Map <Employe, EmployeDTO>(_employeService.Get(id));

            #region préparation de la card identité de l'employé

            modelOut.cardEmploye.employe = new EmployeSimpleDTO
            {
                id          = emp.id,
                civ         = emp.civ,
                nom         = emp.nom,
                prenom      = emp.prenom,
                email       = emp.email,
                tel1        = emp.tel1,
                tel2        = emp.tel2,
                typeEmploye = emp.typeEmploye
            };

            //modelOut.cardEmploye.lesTypesEmployes = _donneListeTypeEmploye();

            #endregion

            #region préparation des infos utilisateur de l'employé

            modelOut.cardUtilisateur.utilisateur = emp.utilisateur;

            if (emp.utilisateur.isActive)
            {
                modelOut.cardUtilisateur.notifications.Add(new MaderaSoft.Models.Notification
                {
                    dureeNotification = Parametres.DureeNotification.Always,
                    message           = "Le compte utilisateur est actif",
                    typeNotification  = Parametres.TypeNotification.Information
                });

                if (emp.utilisateur.isFirstConnexion)
                {
                    modelOut.cardUtilisateur.notifications.Add(new MaderaSoft.Models.Notification
                    {
                        dureeNotification = Parametres.DureeNotification.Always,
                        message           = "L'utilisateur doit changer le mot de passe par défaut",
                        typeNotification  = Parametres.TypeNotification.Warning
                    });
                }
            }
            else
            {
                modelOut.cardUtilisateur.notifications.Add(new MaderaSoft.Models.Notification
                {
                    dureeNotification = Parametres.DureeNotification.Always,
                    message           = "Le compte utilisateur est désactivé",
                    typeNotification  = Parametres.TypeNotification.Warning
                });
            }



            #endregion

            #region préparation de la card des affectations de l'employé
            //les affectations de l'employé

            //On prépare le tableau récapitulant les affectations de l'employé
            modelOut.cardAffectations.tableauAffectations.avecActionCrud = false;
            modelOut.cardAffectations.tableauAffectations.lesLignes.Add(new List <object> {
                "Service", "Droit", "Activité principale", ""
            });

            if (emp.affectationServices != null)
            {
                foreach (AffectationServiceDTO affectation in emp.affectationServices)
                {
                    modelOut.cardAffectations.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.cardAffectations.lesDroits = _donneListeGroupeUtilisateur();

            modelOut.cardAffectations.lesServices = _donneListeService();

            modelOut.cardAffectations.nouvelleAffectation.emplyeId = id;


            #endregion

            #endregion

            #region préparation de la card adresse

            modelOut.adresse = emp.adresse;

            #endregion

            return(View(modelOut));
        }