Example #1
0
 // GET: Employe/Create
 public ActionResult Create()
 {
     ViewBag.ID = new SelectList(db.Conjoints, "ID", "Nom");
     var employe = new Employe();
     var enfants = new List<Enfant>();
     for (int i = 0; i < 12; i++)
     {
         enfants.Add(new Enfant());
     }
     var employeVM = new AgentVM
     {
         EmployeVM = employe,
         EnfantsVM = enfants,
     };
     return View(employeVM);
 }
Example #2
0
        public ActionResult Create(AgentVM agentVM)
        {
            if (ModelState.IsValid)
            {
                int pNombreEnfants = NombreEnfants(agentVM.EnfantsVM);

                //int pAnneeEngagement = agentVM.EmployeVM.DateEngagement.Year;
                //List<Annee> pAnnees = new List<Annee>();
                //for (int i = pAnneeEngagement; i <= 2020; i++)
                //{
                //    pAnnees.Add(new Annee { NomAnnee = i, Mois = db.Mois.ToList() }); //Je dois creer une nouvelle instance des jours pour chaque annee
                //}
                //pAnnees.ForEach(a => db.Annees.Add(a));

                //List<Jour> pJours = new List<Jour>();
                //List<Moi> pMois = db.Mois.ToList();
                //foreach (Annee pAnnee in pAnnees)
                //{
                //    foreach (Moi pMoi in pMois)
                //    {
                //        pJours.Add(new Jour { JourConge = 0, MoiID = pMoi.ID, AnneeID = pAnnee.ID });
                //    }
                //    pJours.ForEach(j => db.Jours.Add(j));
                //    pJours.Clear();
                //}

                //int pAnneeEngagement = agentVM.EmployeVM.DateEngagement.Year;
                //List<Jour> pJours = new List<Jour>();
                //List<Moi> pMois = db.Mois.ToList();
                //List<Annee> pAnnees = new List<Annee>();
                //Annee[] ppAnnee = new Annee[15];
                //int k = 0;

                //for (int i = pAnneeEngagement; i <= 2020; i++)
                //{
                //    ppAnnee[k] = new Annee { NomAnnee = i, Mois = db.Mois.ToList() }; //Je dois creer une nouvelle instance des jours pour chaque annee
                //    db.Annees.Add(ppAnnee[k]);
                //    pAnnees.Add(ppAnnee[k]);
                //    foreach (Moi pMoi in pMois)
                //    {
                //        pJours.Add(new Jour { JourConge = 0, MoiID = pMoi.ID, AnneeID = ppAnnee[k].ID });
                //    }
                //    pJours.ForEach(j => db.Jours.Add(j));
                //    k++;
                //}

                //List<Annee> pAnnees = new List<Annee>();

                //Annee pAnnee = new Annee();
                //pAnnee.NomAnnee = agentVM.EmployeVM.DateEngagement.Year;
                //pAnnee.Mois = db.Mois.ToList();
                //db.Annees.Add(pAnnee);

                //List<Jour> pJours = new List<Jour>();
                //List<Moi> pMois = db.Mois.ToList();

                //foreach (Moi pMoi in pMois)
                //{
                //    pJours.Add(new Jour { JourConge = 0, MoiID = pMoi.ID, AnneeID = pAnnee.ID });
                //}
                //pJours.ForEach(j => db.Jours.Add(j));

                //pAnnees.Add(pAnnee);

                //Annee pAnnee2 = new Annee();
                //pAnnee2.NomAnnee = agentVM.EmployeVM.DateEngagement.Year;
                //pAnnee2.Mois = db.Mois.ToList();
                //db.Annees.Add(pAnnee2);

                //List<Jour> pJours2 = new List<Jour>();

                //foreach (Moi pMoi in pMois)
                //{
                //    pJours2.Add(new Jour { JourConge = 0, MoiID = pMoi.ID, AnneeID = pAnnee2.ID });
                //}
                //pJours2.ForEach(j => db.Jours.Add(j));

                //pAnnees.Add(pAnnee2);

                Employe pEmploye = new Employe
                {
                    Nom = agentVM.EmployeVM.Nom,
                    Postnom = agentVM.EmployeVM.Postnom,
                    Prenom = agentVM.EmployeVM.Prenom,
                    Sexe = agentVM.EmployeVM.Sexe,
                    DateNaissance = agentVM.EmployeVM.DateNaissance,
                    LieuNaissance = agentVM.EmployeVM.LieuNaissance,
                    Matricule = agentVM.EmployeVM.Matricule,
                    Fonction = agentVM.EmployeVM.Fonction,
                    Categorie = agentVM.EmployeVM.Categorie,
                    Actif = agentVM.EmployeVM.Actif,
                    Adresse = agentVM.EmployeVM.Adresse,
                    EtatCivil = agentVM.EmployeVM.EtatCivil,
                    DateEngagement = agentVM.EmployeVM.DateEngagement,
                    Expiration = agentVM.EmployeVM.Expiration,
                    DureeContrat = agentVM.EmployeVM.DureeContrat,
                    TypeContrat = agentVM.EmployeVM.TypeContrat,
                    LieuEngagement = agentVM.EmployeVM.LieuEngagement,
                    Conge = agentVM.EmployeVM.Conge,
                    Brute = agentVM.EmployeVM.Brute,
                    IndemniteComplementaire = agentVM.EmployeVM.IndemniteComplementaire,
                    Transport = agentVM.EmployeVM.Transport,
                    Logement = agentVM.EmployeVM.Logement,
                    Departement = agentVM.EmployeVM.Departement,
                    Section = agentVM.EmployeVM.Section,
                    NumeroINSS = agentVM.EmployeVM.NumeroINSS,
                    NombreEnfants = pNombreEnfants,
                    Annees = db.Annees.ToList(),
                };

                db.Employes.Add(pEmploye);

                int plEmployeID = pEmploye.ID;

                db.Conjoints.Add(
                        new Conjoint
                        {
                            Nom = agentVM.EmployeVM.Conjoint.Nom,
                            Postnom = agentVM.EmployeVM.Conjoint.Postnom,
                            Prenom = agentVM.EmployeVM.Conjoint.Prenom,
                            Sexe = agentVM.EmployeVM.Conjoint.Sexe,
                            DateNaissance = agentVM.EmployeVM.Conjoint.DateNaissance,
                            LieuNaissance = agentVM.EmployeVM.Conjoint.LieuNaissance,
                            Vivant = agentVM.EmployeVM.Conjoint.Vivant,
                            ID = plEmployeID
                        }
                    );

                List<Enfant> pListeEnfants = new List<Enfant>();
                foreach (Enfant pEnfant in agentVM.EnfantsVM)
                {
                    pListeEnfants.Add(
                        new Enfant
                        {
                            Nom = pEnfant.Nom,
                            Postnom = pEnfant.Postnom,
                            Prenom = pEnfant.Prenom,
                            Sexe = pEnfant.Sexe,
                            DateNaissance = pEnfant.DateNaissance,
                            LieuNaissance = pEnfant.LieuNaissance,
                            Vivant = pEnfant.Vivant,
                            AttestationFS = pEnfant.AttestationFS,
                            EmployeID = plEmployeID,
                        }
                        );
                }
                pListeEnfants.ForEach(e => db.Enfants.Add(e));

                List<Annee> pAnnees = db.Annees.ToList();
                List<Jour> pJours = new List<Jour>();
                foreach(Annee pAnnee in pAnnees)
                {
                    foreach(Moi pMoi in pAnnee.Mois)
                    {
                        pJours.Add(new Jour { JourConge = 0, AnneeID = pAnnee.ID, MoiID = pMoi.ID, EmployeID = plEmployeID });
                    }
                }
                pJours.ForEach(e => db.Jours.Add(e));

                db.SaveChanges();

                return RedirectToAction("Index");
            }
            return View(agentVM);
        }
Example #3
0
 public ActionResult Edit(AgentVM agentVM)
 {
     if (ModelState.IsValid)
     {
         agentVM.EmployeVM.NombreEnfants = NombreEnfants(agentVM.EnfantsVM);
         db.Entry(agentVM.EmployeVM).State = EntityState.Modified;
         db.Entry(agentVM.EmployeVM.Conjoint).State = EntityState.Modified;
         agentVM.EnfantsVM.ForEach(m => db.Entry(m).State = EntityState.Modified);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.ID = new SelectList(db.Conjoints, "ID", "Nom", agentVM.EmployeVM.ID);
     return View(agentVM);
 }
Example #4
0
 // GET: Employe/Edit/5
 public ActionResult Edit(int? id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     Employe employe = db.Employes.Find(id);
     if (employe == null)
     {
         return HttpNotFound();
     }
     ViewBag.ID = new SelectList(db.Conjoints, "ID", "Nom", employe.ID);
     var enfants = db.Enfants.Where(i => i.EmployeID == id).ToList();
     var model = new AgentVM
     {
         EmployeVM = employe,
         EnfantsVM = enfants,
     };
     return View(model);
 }
Example #5
0
 // GET: Employe/Details/5
 public ActionResult Details(int? id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     Employe employe = db.Employes.Find(id);
     if (employe == null)
     {
         return HttpNotFound();
     }
     var enfants = db.Enfants.Where(i => i.EmployeID == id).ToList();
     var model = new AgentVM
     {
         EmployeVM = employe,
         EnfantsVM = enfants,
     };
     return View(model);
 }