Browse Source

NEW #29 Finalisation

olivier.massot 7 năm trước cách đây
mục cha
commit
9bea200449

+ 7 - 2
CD67.FicheCollege.Factory/ActionEduFactory.cs

@@ -95,8 +95,13 @@ namespace CD67.FicheCollege.Factory
                 cloneActionEduCollege.Commentaire = actionEduCollege.Commentaire;
                 cloneActionEduCollege.NbEleves = actionEduCollege.NbEleves;
 
-                cloneActionEduCollege.College = dbContext.Colleges.Where(c => c.TokenId == actionEduCollege.College.TokenId && c.Annee_Id == annee_id).First();
-
+                try
+                {
+                    cloneActionEduCollege.College = dbContext.Colleges.Where(c => c.TokenId == actionEduCollege.College.TokenId && c.Annee_Id == annee_id).First();
+                }
+                catch(InvalidOperationException) {
+                    throw new InvalidOperationException("Un ou plusieurs collegesaffectés à cette action n'ont pas été créés pour l'année en cours");
+                }
                 clone.ActionsEduColleges.Add(cloneActionEduCollege);
             }
 

+ 22 - 3
CD67.FicheCollege.MVC/Controllers/ActionsEduController.cs

@@ -148,10 +148,14 @@ namespace CD67.FicheCollege.MVC.Controllers
         [ValidateAntiForgeryToken]
         public ActionResult DeleteConfirmed(int id)
         {
+            ActionEduCollegeFactory aec_fact = new ActionEduCollegeFactory(db);
+            aec_fact.deleteMany(a => a.ActionEduId == id);
+
             ActionEduFactory fact = new ActionEduFactory(db);
             ActionEdu actionEdu = fact.getById(id);
+            int annee_id = actionEdu.AnneeId;
             fact.delete(ref actionEdu);
-            return RedirectToAction("Index", new { annee_id = actionEdu.AnneeId });
+            return RedirectToAction("Index", new { annee_id = annee_id });
         }
 
         public List<ActionEdu> actions_non_importees(int annee_id)
@@ -164,7 +168,7 @@ namespace CD67.FicheCollege.MVC.Controllers
                 // 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.ActionsEdu.Any(a => a.TokenId == actionEdu.TokenId && a.AnneeId == annee_id))
                 {
-                    non_importees.Add(actionEdu.flat());
+                    non_importees.Add(actionEdu);
                 }
             }
             return non_importees;
@@ -180,7 +184,22 @@ namespace CD67.FicheCollege.MVC.Controllers
 
             ImportActionEduViewModel model = new ImportActionEduViewModel();
             model.Annee_Id = annee_id.Value;
-            model.set_liste(actions_non_importees(annee_id.Value));
+            model.Annee_Lib = db.Annees.Where(a => a.Id == annee_id.Value).First().Libelle;
+            List<ActionEdu> non_importes = actions_non_importees(annee_id.Value);
+
+            model.set_liste(non_importes);
+
+            for (int i = 0; i < non_importes.Count; i++)
+            {
+                ActionEdu actionEdu = non_importes[i];
+                foreach (ActionEduCollege aec in actionEdu.ActionsEduColleges)
+                {
+                    if (!db.Colleges.Where(c=>c.TokenId==aec.College.TokenId && c.Annee_Id == annee_id.Value).Any())
+                    {
+                        model.actionsEdu_averts[i].Add(aec.College.Libelle);
+                    }
+                }
+            }
 
             return View(model);
         }

+ 1 - 1
CD67.FicheCollege.MVC/Models/ActionEduCollegeViewModel.cs

@@ -13,7 +13,7 @@ namespace CD67.FicheCollege.MVC.Models
         public ActionEduCollegeViewModel(ActionEduCollege model, Entities dbContext, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
         {
             CollegeFactory fact = new CollegeFactory(dbContext);
-            Sel_College = new SelectList(fact.getAll(), "Id", "Libelle", Obj.CollegeId);
+            Sel_College = new SelectList(fact.getManyBy(c=>c.Annee_Id==Obj.ActionEdu.AnneeId), "Id", "Libelle", Obj.CollegeId);
         }
 
         public override int Annee_Id { get { return Obj.ActionEdu.Annee.Id; } }

+ 2 - 2
CD67.FicheCollege.MVC/Models/ImportActionEduViewModel.cs

@@ -4,7 +4,6 @@ using System.ComponentModel.DataAnnotations;
 
 namespace CD67.FicheCollege.MVC.Models
 {
-
     public class ImportActionEduViewModel
     {
         public int Annee_Id;
@@ -13,6 +12,7 @@ namespace CD67.FicheCollege.MVC.Models
         public List<int> actionsEdu_ids = new List<int>();
         public List<string> actionsEdu_noms = new List<string>();
         public List<string> actionsEdu_nums = new List<string>();
+        public List<List<string>> actionsEdu_averts = new List<List<string>>();
         public List<bool> selection = new List<bool>();
 
         public void set_liste(List<ActionEdu> actionsEdu)
@@ -22,9 +22,9 @@ namespace CD67.FicheCollege.MVC.Models
                 actionsEdu_ids.Add(actionEdu.Id);
                 actionsEdu_noms.Add(actionEdu.Nom);
                 actionsEdu_nums.Add(actionEdu.Numero);
+                actionsEdu_averts.Add(new List<string>());
                 selection.Add(false);
             }
         }
-
     }
 }

+ 6 - 0
CD67.FicheCollege.MVC/Views/ActionsEdu/Import.cshtml

@@ -41,6 +41,12 @@
                             <td>
                                 @Html.DisplayFor(model => Model.actionsEdu_noms[i])
                             </td>
+                            <td>
+                                @if (Model.actionsEdu_averts[i].Count > 0)
+                                {
+                                    <span class="text-danger">Un ou plusieurs collèges affectés à cette action n'ont pas été créés pour l'année cible: @String.Join(", ", Model.actionsEdu_averts[i])</span>
+                                }
+                            </td>
                         </tr>
                     }
                 </tbody>