瀏覽代碼

NEW #29 Clonage des données des collèges ok

olivier.massot 7 年之前
父節點
當前提交
94f917c5d4

+ 8 - 0
CD67.FicheCollege.Entity/Extend/Annee.cs

@@ -18,6 +18,14 @@ namespace CD67.FicheCollege.Entity
                 Libelle = Libelle
             };
         }
+
+        public string AnneePrecLib
+        {
+            get
+            {
+                return this.AnneeRentree - 1 + "-" + this.AnneeRentree;
+            }
+        }
     }
 
     /// <summary>

+ 27 - 3
CD67.FicheCollege.Entity/Extend/College.cs

@@ -48,12 +48,36 @@ namespace CD67.FicheCollege.Entity
 
         }
 
-        public void loadEducfData(EducfEntities educfdb)
+        public College flat()
         {
-
-        }
+            return new College()
+            {
+                Id = Id,
+                Annee_Id = Annee_Id,
+                CodeRne = CodeRne,
+                Libelle = Libelle,
+                Adresse = Adresse,
+                Code_Postal = Code_Postal,
+                TypeCollege_Id = TypeCollege_Id,
+                Commune_Insee = Commune_Insee,
+                Commune = Commune,
+                Canton = Canton,
+                Territoire_Id = Territoire_Id,
+                TAD = TAD,
+                CDC = CDC,
+                Tel = Tel,
+                Fax = Fax,
+                Email = Email,
+                PrincipalSid = PrincipalSid,
+                AdjointSid = AdjointSid,
+                Gestionnaire1Sid = Gestionnaire1Sid,
+                Gestionnaire2Sid = Gestionnaire2Sid,
+                TokenId = TokenId,
+        };
     }
 
+}
+
     /// <summary>
     /// Classe contenant les DataAnnotations pour chaque champ
     /// </summary>

+ 0 - 1
CD67.FicheCollege.Factory/CollegeFactory.cs

@@ -30,7 +30,6 @@ namespace CD67.FicheCollege.Factory
             clone.Commune = college.Commune;
             clone.Canton = college.Canton;
             clone.Territoire_Id = college.Territoire_Id;
-            clone.Canton = college.Canton;
             clone.TAD = college.TAD;
             clone.CDC = college.CDC;
             clone.Tel = college.Tel;

+ 2 - 0
CD67.FicheCollege.MVC/CD67.FicheCollege.MVC.csproj

@@ -195,6 +195,7 @@
     <Compile Include="Models\ActionEduCollegeViewModel.cs" />
     <Compile Include="Models\ActionEduAxeViewModel.cs" />
     <Compile Include="Models\ActionEduThematiqueViewModel.cs" />
+    <Compile Include="Models\ImportCollegeViewModel.cs" />
     <Compile Include="Models\TerritoireViewModel.cs" />
     <Compile Include="Models\TypeCollegeViewModel.cs" />
     <Compile Include="Models\ActionEduViewModel.cs" />
@@ -451,6 +452,7 @@
     <Content Include="Views\ActionsEduCollege\Delete.cshtml" />
     <Content Include="Views\ActionsEduCollege\Edit.cshtml" />
     <Content Include="Views\Shared\_AdminLayout.cshtml" />
+    <Content Include="Views\Colleges\Import.cshtml" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="App_Data\" />

+ 87 - 24
CD67.FicheCollege.MVC/Controllers/CollegesController.cs

@@ -50,27 +50,46 @@ namespace CD67.FicheCollege.MVC.Controllers
                 etablissement educf_etablissement = educfFact.getByRne(college.CodeRne);
                 if (educf_etablissement != null)
                 {
-                    college.educfData.Add("Effectifs", educf_etablissement.etabeffectifannees.Where(e=>e.annee== college.Annee.AnneeRentree).Sum(e => e.effectif).ToString());
-                    college.educfData.Add("Effectif Bilingue", educf_etablissement.eleveannees.Where(e=>e.annee== college.Annee.AnneeRentree & e.idetablissement == 3 & e.idfiliere == 6).Count().ToString());
-                    college.educfData.Add("Demi-pensionnaires", educf_etablissement.etablissementannees.Where(e=>e.annee== college.Annee.AnneeRentree).First().demipensionnaires.ToString());
+                    try {
+                        college.educfData.Add("Effectifs", educf_etablissement.etabeffectifannees.Where(e => e.annee == college.Annee.AnneeRentree).Sum(e => e.effectif).ToString());
+                    } catch { college.educfData.Add("Effectifs", "(Données introuvables)"); }
+
+                    try { 
+                        college.educfData.Add("Effectif Bilingue", educf_etablissement.eleveannees.Where(e=>e.annee== college.Annee.AnneeRentree & e.idetablissement == 3 & e.idfiliere == 6).Count().ToString());
+                    } catch { college.educfData.Add("Effectif Bilingue", "(Données introuvables)"); }
+
+                    try { 
+                        college.educfData.Add("Demi-pensionnaires", educf_etablissement.etablissementannees.Where(e=>e.annee== college.Annee.AnneeRentree).First().demipensionnaires.ToString());
+                    } catch { college.educfData.Add("Demi-pensionnaires", "(Données introuvables)"); }
+
+                    try { 
                     college.educfData.Add("Internes", educf_etablissement.etablissementannees.Where(e=>e.annee== college.Annee.AnneeRentree).First().capaciteeleves.ToString());
-                    college.educfData.Add("Accessibilité handicapés", educf_etablissement.accueilhandicape != 0 ? "Oui" : "Non");
+                    } catch { college.educfData.Add("Internes", "(Données introuvables)"); }
+
+                    try { 
+                        college.educfData.Add("Accessibilité handicapés", educf_etablissement.accueilhandicape != 0 ? "Oui" : "Non");
+                    } catch { college.educfData.Add("Accessibilité handicapés", "(Données introuvables)"); }
+
+                    try { 
                     college.educfData.Add("Capacité Théorique", educf_etablissement.etablissementannees.Where(e => e.annee == college.Annee.AnneeRentree).First().internes.ToString());
+                    } catch { college.educfData.Add("Capacité Théorique", "(Données introuvables)"); }
+                    try { 
+                        List<string> liste_niveaux = new List<string>();
+                        foreach(etabeffectifannee effectif in educf_etablissement.etabeffectifannees.Where(e => e.annee == college.Annee.AnneeRentree).OrderBy(e=>e.niveau.ordre))
+                        {
+                            liste_niveaux.Add(effectif.niveau.nom + ": " + effectif.effectif);
+                        }
+                        college.educfData.Add("Niveaux", string.Join(" - ", liste_niveaux));
+                    } catch { college.educfData.Add("Niveaux", "(Données introuvables)"); }
 
-                    List<string> liste_niveaux = new List<string>();
-                    foreach(etabeffectifannee effectif in educf_etablissement.etabeffectifannees.Where(e => e.annee == college.Annee.AnneeRentree).OrderBy(e=>e.niveau.ordre))
-                    {
-                        liste_niveaux.Add(effectif.niveau.nom + ": " + effectif.effectif);
-                    }
-                    college.educfData.Add("Niveaux", string.Join(" - ", liste_niveaux));
-
-                    List<string> liste_options = new List<string>();
-                    foreach (etaboptionsannee opt in educf_etablissement.etaboptionsannees)
-                    {
-                        liste_options.Add(opt.matiereoption.nom);
-                    }
-                    college.educfData.Add("Options", string.Join(" - ", liste_options));
-                    
+                    try { 
+                        List<string> liste_options = new List<string>();
+                        foreach (etaboptionsannee opt in educf_etablissement.etaboptionsannees)
+                        {
+                            liste_options.Add(opt.matiereoption.nom);
+                        }
+                        college.educfData.Add("Options", string.Join(" - ", liste_options));
+                    } catch { college.educfData.Add("Options", "(Données introuvables)"); }
                 }
                 else
                 {
@@ -191,15 +210,59 @@ namespace CD67.FicheCollege.MVC.Controllers
             collegeFactory.delete(ref college);
             return RedirectToAction("Index", new { annee_id = annee_id });
         }
-        
-        public ActionResult Clone(int? id, int annee_id)
+
+        public List<College> colleges_non_importes(int annee_id)
+        {
+            List<College> non_importes = new List<College>();
+            AnneeFactory fact = new AnneeFactory(db);
+            Annee annee_prec = fact.getById(annee_id - 1);
+
+            foreach (College college in annee_prec.Colleges)
+            {
+                // Pour chaque college de l'année précédente, on vérifie s'il existe dans l'année en cours en se basant sur le TokenId
+                if (!db.Colleges.Any(c=> c.TokenId == college.TokenId && c.Annee_Id == annee_id))
+                {
+                    non_importes.Add(college.flat());
+                }
+            }
+
+            return non_importes;
+        }
+
+        // GET: Colleges
+        public ActionResult Import(int? annee_id)
+        {
+            if (annee_id == null)
+            {
+                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
+            }
+
+            ImportCollegeViewModel model = new ImportCollegeViewModel();
+            model.Annee_Id = annee_id.Value;
+            model.set_liste(colleges_non_importes(annee_id.Value));
+
+            return View(model);
+        }
+
+        [HttpPost]
+        [ValidateAntiForgeryToken]
+        //public ActionResult Import([Bind(Include = "Annee_id, Annee_Lib,liste")] ImportCollegeViewModel model)
+        public ActionResult Import(int Annee_Id, List<int> colleges_ids, List<bool> selection)
+        //public ActionResult Import(ImportCollegeViewModel model)
         {
             CollegeFactory fact = new CollegeFactory(db);
-            College college = fact.getById(id);
-            College clone = fact.clone_to_year(college, annee_id);
-            return RedirectToAction("Details", new { id = clone.Id });
+            for (int i = 0; i < selection.Count; i++)
+            {
+                if (selection[i])
+                {
+                    int college_id = colleges_ids[i];
+                    College college = fact.getById(college_id);
+                    fact.clone_to_year(college, Annee_Id);
+                }
+            }
+            return RedirectToAction("Index", new { annee_id = Annee_Id });
         }
-        
+
         protected override void Dispose(bool disposing)
         {
             if (disposing)

+ 1 - 0
CD67.FicheCollege.MVC/Models/CollegeViewModel.cs

@@ -28,4 +28,5 @@ namespace CD67.FicheCollege.MVC.Models
         public override string Annee_Lib { get { return Obj.Annee.Libelle; } }
 
     }
+
 }

+ 30 - 0
CD67.FicheCollege.MVC/Models/ImportCollegeViewModel.cs

@@ -0,0 +1,30 @@
+using CD67.FicheCollege.Entity;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+
+namespace CD67.FicheCollege.MVC.Models
+{
+
+    public class ImportCollegeViewModel
+    {
+        public int Annee_Id;
+        public string Annee_Lib = "";
+
+        public List<int> colleges_ids = new List<int>();
+        public List<string> colleges_libs = new List<string>();
+        public List<string> colleges_rnes = new List<string>();
+        public List<bool> selection = new List<bool>();
+
+        public void set_liste(List<College> colleges)
+        {
+            foreach (College college in colleges)
+            {
+                colleges_ids.Add(college.Id);
+                colleges_libs.Add(college.Libelle);
+                colleges_rnes.Add(college.CodeRne);
+                selection.Add(false);
+            }
+        }
+
+    }
+}

+ 0 - 2
CD67.FicheCollege.MVC/Views/Colleges/Details.cshtml

@@ -27,8 +27,6 @@
             <div class="pull-right">
                 @Html.ActionLink("Supprimer", "Delete", "Colleges", new { Id = college.Id }, new { @class = "btn btn-danger" })
                 @Html.ActionLink("Modifier", "Edit", "Colleges", new { Id = college.Id }, new { @class = "btn btn-default" })
-
-                @Html.ActionLink("(test) Dupliquer vers 2018", "Clone", "Colleges", new { Id = college.Id, annee_id = 18 }, new { @class = "btn btn-default" })
             </div>
         }
     </legend>

+ 62 - 0
CD67.FicheCollege.MVC/Views/Colleges/Import.cshtml

@@ -0,0 +1,62 @@
+@using CD67.FicheCollege.MVC.Models
+@model ImportCollegeViewModel
+
+@{
+    ViewBag.Title = "Import";
+    Layout = "~/Views/Shared/_Layout.cshtml";
+}
+
+@*Selection de colleges à importer*@
+<div>
+
+    @if(Model.colleges_ids.Count == 0)
+    {
+        <span> Aucun collège à importer </span>
+        <div>
+            @Html.ActionLink("Annuler", "Index", new { annee_id = Model.Annee_Id })
+        </div>
+    }
+    else
+    {
+        using (Html.BeginForm())
+        {
+            @Html.AntiForgeryToken()
+            @Html.HiddenFor(model => Model.Annee_Id)
+
+            <table id="table-college-import" class="datatable table">
+                <thead>
+                </thead>
+                <tbody>
+                    @*@foreach (ImportCollegeItem item in Model.liste)*@
+                    @for(int i=0; i < Model.selection.Count; i++)
+                    {
+                        <tr>
+                            <td>
+                                @Html.EditorFor(model => Model.selection[i])
+                                @Html.HiddenFor(model => Model.colleges_ids[i])
+                            </td>
+                            <td>
+                                @Html.DisplayFor(model => Model.colleges_rnes[i])
+                            </td>
+                            <td>
+                                @Html.DisplayFor(model => Model.colleges_libs[i])
+                            </td>
+                        </tr>
+                    }
+                </tbody>
+            </table>
+
+            <div class="form-group">
+                <span style="margin-right:20px;">
+                    <input type="submit" value="Importer" class="btn btn-default" />
+                </span>
+                <span>
+                    @Html.ActionLink("Annuler", "Index", new { annee_id = Model.Annee_Id })
+                </span>
+            </div>
+        }
+    }
+
+</div>
+
+

+ 9 - 0
CD67.FicheCollege.MVC/Views/Colleges/Index.cshtml

@@ -7,10 +7,19 @@
     College college_model = new College();
 }
 
+@*Selection de colleges à importer*@
+<div id="college-import-dlg" style="display:none">
+    <ul class="college-import-list">
+        @* Injection ajax *@
+    </ul>
+    <input class="btn btn-default" type="button" value="Importer" />
+</div>
+
 <header>
     <h2>Les collèges @Model.Annee_Lib</h2>
     <span>
         <a href="@Url.Action("Create", new { annee_id = Model.Obj.Id })"> <span class="glyphicon glyphicon-plus-sign color1"></span> Nouveau collège</a>
+        <a href="@Url.Action("Import", new { annee_id = Model.Obj.Id })"> <span class="glyphicon glyphicon-plus-sign color1"></span> Importer depuis @Model.Obj.AnneePrecLib</a>
         <a class="start-trace" href="@Url.Action("Index", "TypeCollege")"> <span class="glyphicon glyphicon-cog color1"></span> Types de collège</a>
         <a class="start-trace" href="@Url.Action("Index", "Territoire")"> <span class="glyphicon glyphicon-cog color1"></span> Territoires</a>
     </span>