浏览代码

NEW #29 Maj factory / controller

olivier.massot 7 年之前
父节点
当前提交
041ead87bf

+ 37 - 18
CD67.FicheCollege.Factory/CollegeFactory.cs

@@ -4,29 +4,48 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Data.Entity;
+using System.Reflection;
 
 namespace CD67.FicheCollege.Factory
 {
     public partial class CollegeFactory : Internal.BaseFactory<Entity.College>
     {
-        //// Charge les données d'identité des agents depuis le web-service
-        //public void hydrate(ref College college)
-        //{
-        //    Entity.WsAgents.Agents wsAgents = new Entity.WsAgents.Agents();
-            
-        //    if (!String.IsNullOrEmpty(college.PrincipalSid)) {
-        //        college.principal = wsAgents.GetById(college.PrincipalSid);
-        //    }
-        //    if (!String.IsNullOrEmpty(college.AdjointSid)) {
-        //        college.adjoint = wsAgents.GetById(college.AdjointSid);
-        //    }
-        //    if (!String.IsNullOrEmpty(college.Gestionnaire1Sid)) {
-        //        college.gestionnaire1 = wsAgents.GetById(college.Gestionnaire1Sid);
-        //    }
-        //    if (!String.IsNullOrEmpty(college.Gestionnaire2Sid)) {
-        //        college.gestionnaire2 = wsAgents.GetById(college.Gestionnaire2Sid);
-        //    }
-        //}
+        public College clone_to_year(College college, int annee_id)
+        {
+            if (base.getAll().Where(c => c.Annee_Id == annee_id && c.TokenId == college.TokenId).Count() > 0)
+            {
+                throw new InvalidOperationException("Ce collège existe déjà pour l'année cible");
+            }
 
+            College clone = new College();
+            // Nouvelle année
+            clone.Annee_Id = annee_id;
+            // On reprend les valeurs de tous les autres champs
+            clone.CodeRne = college.CodeRne;
+            clone.Libelle = college.Libelle;
+            clone.Adresse = college.Adresse;
+            clone.Code_Postal = college.Code_Postal;
+            clone.TypeCollege_Id = college.TypeCollege_Id;
+            clone.Commune_Insee = college.Commune_Insee;
+            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;
+            clone.Fax = college.Fax;
+            clone.Email = college.Email;
+            clone.PrincipalSid = college.PrincipalSid;
+            clone.AdjointSid = college.AdjointSid;
+            clone.Gestionnaire1Sid = college.Gestionnaire1Sid;
+            clone.Gestionnaire2Sid = college.Gestionnaire2Sid;
+            clone.TokenId = college.TokenId;
+
+            // enregistre le clone en base
+            base.add(ref clone);
+
+            return clone;
+        }
     }
 }

+ 3 - 0
CD67.FicheCollege.Factory/Internal/BaseFactory.cs

@@ -2,9 +2,12 @@
 using System;
 using System.Collections.Generic;
 using System.Data.Entity;
+using System.IO;
 using System.Linq;
 using System.Linq.Dynamic;
 using System.Linq.Expressions;
+using System.Reflection;
+using System.Runtime.Serialization;
 using System.Text;
 using System.Threading.Tasks;
 

+ 12 - 2
CD67.FicheCollege.MVC/Controllers/CollegesController.cs

@@ -5,6 +5,7 @@ using CD67.FicheCollege.Factory;
 using CD67.FicheCollege.MVC.Models;
 using System.Linq;
 using System.Collections.Generic;
+using System;
 
 namespace CD67.FicheCollege.MVC.Controllers
 {
@@ -69,8 +70,7 @@ namespace CD67.FicheCollege.MVC.Controllers
                         liste_options.Add(opt.matiereoption.nom);
                     }
                     college.educfData.Add("Options", string.Join(" - ", liste_options));
-
-
+                    
                 }
                 else
                 {
@@ -92,6 +92,8 @@ namespace CD67.FicheCollege.MVC.Controllers
             }
             Entity.College college = new Entity.College();
             college.Annee_Id = annee_id.Value;
+            college.TokenId = Guid.NewGuid();
+
             AnneeFactory fact = new AnneeFactory(db);
             college.Annee = fact.getById(annee_id);
             college.hydrate();
@@ -190,6 +192,14 @@ namespace CD67.FicheCollege.MVC.Controllers
             return RedirectToAction("Index", new { annee_id = annee_id });
         }
         
+        public ActionResult Clone(int? id, int annee_id)
+        {
+            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 });
+        }
+        
         protected override void Dispose(bool disposing)
         {
             if (disposing)

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

@@ -27,6 +27,8 @@
             <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>