Example #1
0
        public int AddEmploye(EmployeDto empDto, EmployeSalaireDto empSalReg, EmployeSalaireDto empSalSpe,
                              IEnumerable <CongeDto> congesDto, IEnumerable <EmployePrelevementDto> empPrelReg,
                              IEnumerable <EmployePrelevementDto> empPrelSpe)
        {
            //Obtenir un numéro interne pour l'employé
            int numInterne = new EmployeRepository().GetNewNumeroInterne(empDto.CompagnieID);

            //Ajouter numero interne pour l'employé
            empDto.NumeroEmploye = numInterne;
            //Ajouter les dates d'embauche et de naissance de l'employé à partir des champs string correspondant
            empDto.DateEmbauche  = DateTime.Parse(empDto.DateEmbaucheString);
            empDto.DateNaissance = DateTime.Parse(empDto.DateNaissanceString);

            //Déterminer si le type de l'employé
            bool isSpecial = false;

            if (empDto.TypeEmployeID == (int)LookupEnum.TypeEmploye.Special)
            {
                isSpecial = true;
            }

            //Ajouter les salaires régulier et spécial dans une liste
            List <EmployeSalaireDto> empSalaires = new List <EmployeSalaireDto>();

            empSalaires.Add(empSalReg);
            if (isSpecial)
            {
                empSalaires.Add(empSalSpe);
            }

            //Fusionner les listes de prélèvement des salaires réguliers et spéciaux s'il ya lieu
            List <EmployePrelevementDto> empPrelList = empPrelReg.ToList();

            if (isSpecial)
            {
                empPrelList.AddRange(empPrelSpe);
            }

            //Ajouter l'employé
            EmployeRepository empRep = new EmployeRepository();

            empRep.AddEmploye(empDto, empSalaires, congesDto, empPrelList);

            //Renvoyer le numéro interne de l'employé
            return(numInterne);
        }
        public ActionResult Create([Bind(Include = "IdEmploye,Matricule,NomComplet,DateEmbauche,IdPoste,IdDepartement,Actif,Ville,Email,Telephone")] Employe employe)
        {
            if (ModelState.IsValid)
            {
                var employeService = new EmployeService();
                if (!employeService.Exist(employe.Matricule))
                {
                    var employeRepository = new EmployeRepository();
                    employeRepository.AddEmploye(employe);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("Matricule", "Ce matricule existe déjà");
                }
            }

            ViewBag.IdDepartement = new SelectList(db.Departement, "IdDepartement", "NomDepartement", employe.IdDepartement);
            ViewBag.IdPoste       = new SelectList(db.Poste, "IdPoste", "NomPoste", employe.IdPoste);
            return(View(employe));
        }