Quellcode durchsuchen

Restaure Onglets

olivier.massot vor 7 Jahren
Ursprung
Commit
d06618916b

+ 7 - 1
CD67.FicheCollege.Entity/ActionCLAS.cs

@@ -14,8 +14,14 @@ namespace CD67.FicheCollege.Entity
     
     public partial class ActionCLAS
     {
+        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
+        public ActionCLAS()
+        {
+            this.Action = false;
+        }
+    
         public int College_Id { get; set; }
-        public Nullable<bool> Action { get; set; }
+        public bool Action { get; set; }
         public string Commentaire { get; set; }
     
         public virtual College College { get; set; }

+ 1 - 1
CD67.FicheCollege.Entity/EntityModel.Context.cs

@@ -30,6 +30,6 @@ namespace CD67.FicheCollege.Entity
         public virtual DbSet<College> Colleges { get; set; }
         public virtual DbSet<Identite> Identites { get; set; }
         public virtual DbSet<Annee> Annees { get; set; }
-        public virtual DbSet<ActionCLAS> ActionCLAS { get; set; }
+        public virtual DbSet<ActionCLAS> ActionsCLAS { get; set; }
     }
 }

+ 4 - 4
CD67.FicheCollege.Entity/EntityModel.edmx

@@ -211,10 +211,10 @@
             <End Role="Annee" EntitySet="Annees" />
             <End Role="College" EntitySet="Colleges" />
           </AssociationSet>
-          <EntitySet Name="ActionCLAS" EntityType="CD67.FicheCollege.ActionCLAS" />
+          <EntitySet Name="ActionsCLAS" EntityType="CD67.FicheCollege.ActionCLAS" />
           <AssociationSet Name="FK_Actions_CLAS_College" Association="CD67.FicheCollege.FK_Actions_CLAS_College">
             <End Role="College" EntitySet="Colleges" />
-            <End Role="Actions_CLAS" EntitySet="ActionCLAS" />
+            <End Role="Actions_CLAS" EntitySet="ActionsCLAS" />
           </AssociationSet>
           </EntityContainer>
         <EntityType Name="TypeCollege">
@@ -363,7 +363,7 @@
             <PropertyRef Name="College_Id" />
           </Key>
           <Property Name="College_Id" Type="Int32" Nullable="false" />
-          <Property Name="Action" Type="Boolean" />
+          <Property Name="Action" Type="Boolean" Nullable="false" DefaultValue="false" />
           <Property Name="Commentaire" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
           <NavigationProperty Name="College" Relationship="CD67.FicheCollege.FK_Actions_CLAS_College" FromRole="Actions_CLAS" ToRole="College" />
         </EntityType>
@@ -474,7 +474,7 @@
         </MappingFragment>
       </EntityTypeMapping>
     </EntitySetMapping>
-          <EntitySetMapping Name="ActionCLAS">
+          <EntitySetMapping Name="ActionsCLAS">
             <EntityTypeMapping TypeName="CD67.FicheCollege.ActionCLAS">
               <MappingFragment StoreEntitySet="Actions-CLAS">
                 <ScalarProperty Name="Commentaire" ColumnName="Commentaire" />

+ 1 - 1
CD67.FicheCollege.Entity/Extend/ActionCLAS.cs

@@ -21,7 +21,7 @@ namespace CD67.FicheCollege.Entity
     public class ActionCLAS_Metadata
     {
         [UIHint("YesNoBool")]
-        public Nullable<bool> Action { get; set; }
+        public bool Action { get; set; }
         [DataType(DataType.MultilineText)]
         public string Commentaire { get; set; }
     }

+ 3 - 3
CD67.FicheCollege.Factory/ActionCLASFactory.cs

@@ -7,12 +7,12 @@ using System.Data.Entity;
 
 namespace CD67.FicheCollege.Factory
 {
-    public partial class ActionCLASFactory : Internal.BaseFactory<Entity.ActionCLAS>
+    public partial class ActionCLASFactory : Internal.BaseFactory<ActionCLAS>
     {
-        public override Entity.ActionCLAS getById(params object[] keyValues)
+        public override ActionCLAS getById(params object[] keyValues)
         {
             //si l'élément n'existe pas, on le créé
-            Entity.ActionCLAS item = base.getById(keyValues);
+            ActionCLAS item = base.getById(keyValues);
             if(item == null)
             {
                 int id = (int)keyValues[0];

+ 13 - 20
CD67.FicheCollege.MVC/Controllers/ActionsCLASController.cs

@@ -8,6 +8,7 @@ using System.Web;
 using System.Web.Mvc;
 using CD67.FicheCollege.Entity;
 using CD67.FicheCollege.Factory;
+using CD67.FicheCollege.MVC.Models;
 
 namespace CD67.FicheCollege.MVC.Controllers
 {
@@ -23,12 +24,14 @@ namespace CD67.FicheCollege.MVC.Controllers
                 return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
             }
             ActionCLASFactory actionClasFactory = new ActionCLASFactory(db);
-            Entity.ActionCLAS actionClas = actionClasFactory.getById(id);
+            ActionCLAS actionClas = actionClasFactory.getById(id);
             if (actionClas == null)
             {
                 return HttpNotFound();
             }
-            return View(GetViewModel(actionClas, Models.ModeAcces.Lecture));
+
+            ActionClasViewModel model = new ActionClasViewModel(actionClas);
+            return View(model);
         }
 
         // GET: ActionCLAS/Edit/5
@@ -44,7 +47,8 @@ namespace CD67.FicheCollege.MVC.Controllers
             {
                 return HttpNotFound();
             }
-            return View(GetViewModel(actionClas, Models.ModeAcces.Modification));
+            ActionClasViewModel model = new ActionClasViewModel(actionClas, ModeAcces.Modification);
+            return View(model);
         }
 
         // POST: ActionCLAS/Edit/5
@@ -52,29 +56,18 @@ namespace CD67.FicheCollege.MVC.Controllers
         // plus de détails, voir  http://go.microsoft.com/fwlink/?LinkId=317598.
         [HttpPost]
         [ValidateAntiForgeryToken]
-        public ActionResult Edit(ActionCLAS Contenu)
+        public ActionResult Edit(ActionCLAS actionClas)
         {
             if (ModelState.IsValid)
             {
                 ActionCLASFactory actionClasFactory = new ActionCLASFactory(db);
-                actionClasFactory.update(ref Contenu);
-                return RedirectToAction("Index");
+                actionClasFactory.update(ref actionClas);
+                return RedirectToAction("Details", new { id = actionClas.College_Id });
             }
-            return View(GetViewModel(Contenu, Models.ModeAcces.Modification));
-        }
 
-        private Models.CollegeViewModel_old GetViewModel(Entity.ActionCLAS action, Models.ModeAcces Acces)
-        {
-            return new Models.CollegeViewModel_old()
-            {
-                College_Id = action.College.Id,
-                //CodeRne = action.College.CodeRne,
-                //Annee_Id = action.College.Annee_Id,
-                College_Libelle = action.College.Libelle,
-                Contenu = action,
-                Acces = Acces,
-                Listes = null
-            };
+            db.Entry(actionClas).Reference(i => i.College).Load();
+            ActionClasViewModel model = new ActionClasViewModel(actionClas, ModeAcces.Modification);
+            return View(model);
         }
 
         protected override void Dispose(bool disposing)

+ 57 - 1
CD67.FicheCollege.MVC/Models/TopModel.cs

@@ -24,6 +24,7 @@ namespace CD67.FicheCollege.MVC.Models
     {
         internal object _Obj;
 
+        public abstract int Id { get; }
         public abstract string Annee_Lib { get; }
 
         // (Facultatif) Mode d'accès à la page
@@ -65,6 +66,14 @@ namespace CD67.FicheCollege.MVC.Models
             }
         }
 
+        public override int Id
+        {
+            get
+            {
+                return Obj.Id;
+            }
+        }
+
         public override string Annee_Lib
         {
             get
@@ -72,7 +81,6 @@ namespace CD67.FicheCollege.MVC.Models
                 return Obj.Libelle;
             }
         }
-
     }
 
     public class CollegeViewModel : TopModel
@@ -97,6 +105,14 @@ namespace CD67.FicheCollege.MVC.Models
             }
         }
 
+        public override int Id
+        {
+            get
+            {
+                return Obj.Id;
+            }
+        }
+
         public override string Annee_Lib
         {
             get {
@@ -130,6 +146,46 @@ namespace CD67.FicheCollege.MVC.Models
             }
         }
 
+        public override int Id
+        {
+            get
+            {
+                return Obj.College_Id;
+            }
+        }
+
+        public override string Annee_Lib
+        {
+            get
+            {
+                return Obj.College.Annee.Libelle;
+            }
+        }
+    }
+
+    public class ActionClasViewModel : TopModel
+    {
+
+        public ActionClasViewModel(object model, ModeAcces acces = ModeAcces.Lecture, Dictionary<string, object> bag = null) : base(model, acces, bag)
+        {
+        }
+
+        public ActionCLAS Obj
+        {
+            get
+            {
+                return (_Obj as ActionCLAS);
+            }
+        }
+
+        public override int Id
+        {
+            get
+            {
+                return Obj.College_Id;
+            }
+        }
+
         public override string Annee_Lib
         {
             get

+ 8 - 8
CD67.FicheCollege.MVC/Views/ActionsCLAS/Details.cshtml

@@ -1,15 +1,15 @@
 @using CD67.FicheCollege.MVC.Models
-@model CollegeViewModel
+@model ActionClasViewModel
 
 @{
     ViewBag.Title = "Details";
     Layout = "~/Views/Shared/_Layout.cshtml";
-    ActionCLAS contenu = Model.Contenu as ActionCLAS;
+    ActionCLAS actionClas = Model.Obj;
 }
 
 <h1>
     Actions éducatives, sportives et culturelles
-    <br /><span>du @Model.College_Libelle</span>
+    <br /><span>du @actionClas.College.Libelle</span>
 </h1>
 
 <fieldset>
@@ -18,24 +18,24 @@
         @if (Model.Acces == ModeAcces.Lecture)
         {
             <div class="pull-right">
-                @Html.ActionLink("Modifier", "Edit", "ActionsCLAS", new { Id = Model.College_Id }, new { @class = "btn btn-default" })
+                @Html.ActionLink("Modifier", "Edit", "ActionsCLAS", new { Id = actionClas.College_Id }, new { @class = "btn btn-default" })
             </div>
         }
     </legend>
 
     <dl class="dl-horizontal">
         <dt>
-            @Html.DisplayNameFor(model => contenu.Action)
+            @Html.DisplayNameFor(model => actionClas.Action)
         </dt>
 
         <dd>
-            @Html.DisplayFor(model => contenu.Action)
+            @Html.DisplayFor(model => actionClas.Action)
         </dd>
 
         <dt>
-            @Html.DisplayNameFor(model => contenu.Commentaire)
+            @Html.DisplayNameFor(model => actionClas.Commentaire)
         </dt>
 
-        <dd style="white-space: pre-line;">@Html.DisplayFor(model => contenu.Commentaire)</dd>
+        <dd style="white-space: pre-line;">@Html.DisplayFor(model => actionClas.Commentaire)</dd>
     </dl>
 </fieldset>

+ 11 - 11
CD67.FicheCollege.MVC/Views/ActionsCLAS/Edit.cshtml

@@ -1,13 +1,13 @@
 @using CD67.FicheCollege.MVC.Models
-@model CollegeViewModel
+@model ActionClasViewModel
 
 @{
     ViewBag.Title = "Edit";
     Layout = "~/Views/Shared/_Layout.cshtml";
-    ActionCLAS contenu = Model.Contenu as ActionCLAS;
+    ActionCLAS actionClas = Model.Obj;
 }
 
-<h1>@Model.College_Libelle</h1>
+<h1>@actionClas.College.Libelle</h1>
 
 @using (Html.BeginForm())
 {
@@ -19,30 +19,30 @@
         </legend>
         <div class="form-horizontal">
             @Html.ValidationSummary(true, "", new { @class = "text-danger" })
-            @Html.HiddenFor(model => contenu.College_Id)
+            @Html.HiddenFor(model => actionClas.College_Id)
 
             <div class="form-group">
-                @Html.LabelFor(model => contenu.Action, htmlAttributes: new { @class = "control-label col-md-2" })
+                @Html.LabelFor(model => actionClas.Action, htmlAttributes: new { @class = "control-label col-md-2" })
                 <div class="col-md-10">
                     <div class="checkbox">
-                        @Html.EditorFor(model => contenu.Action)
-                        @Html.ValidationMessageFor(model => contenu.Action, "", new { @class = "text-danger" })
+                        @Html.EditorFor(model => actionClas.Action)
+                        @Html.ValidationMessageFor(model => actionClas.Action, "", new { @class = "text-danger" })
                     </div>
                 </div>
             </div>
 
             <div class="form-group">
-                @Html.LabelFor(model => contenu.Commentaire, htmlAttributes: new { @class = "control-label col-md-2" })
+                @Html.LabelFor(model => actionClas.Commentaire, htmlAttributes: new { @class = "control-label col-md-2" })
                 <div class="col-md-10">
-                    @Html.EditorFor(model => contenu.Commentaire, new { htmlAttributes = new { @class = "form-control", @rows = 10 } })
-                    @Html.ValidationMessageFor(model => contenu.Commentaire, "", new { @class = "text-danger" })
+                    @Html.EditorFor(model => actionClas.Commentaire, new { htmlAttributes = new { @class = "form-control", @rows = 10 } })
+                    @Html.ValidationMessageFor(model => actionClas.Commentaire, "", new { @class = "text-danger" })
                 </div>
             </div>
 
             <div class="form-group">
                 <div class="col-md-offset-2 col-md-10">
                     <input type="submit" value="@Model.Acces.EnumDisplayNameFor(MvcHtmlHelpers.DisplayValue.Prompt)" class="btn btn-default" /> |
-                    @Html.ActionLink("Annuler", "Details", new { Id = Model.College_Id })
+                    @Html.ActionLink("Annuler", "Details", new { Id = actionClas.College_Id })
                 </div>
             </div>
         </div>

+ 13 - 13
CD67.FicheCollege.MVC/Views/Shared/_Layout.cshtml

@@ -7,11 +7,11 @@
     UtilisateurConnecte utilisateurConnecte = CD67.FicheCollege.MVC.Internal.UtilisateurConnecteFactory.getUtilisateurConnecte();
     string url = Request.Url.ToString();
 
-    bool editionCollege = false;
-    int? college_Id = null;
-    string college_Libelle = null;
-    int? annee_Id = null;
-    string annee_Libelle = null;
+    //bool editionCollege = false;
+    //int? college_Id = null;
+    //string college_Libelle = null;
+    //int? annee_Id = null;
+    //string annee_Libelle = null;
 
     //if (Model is CollegeViewModel && Model.College_Id != null)
     //{
@@ -56,7 +56,7 @@
             <div id="topbar" class="navbar navbar-inner">
                 <div id="open-button" class="menu-button"><span>Menu invisible</span></div>
                 <ul id="titre" class="nav navbar ">
-                    <li><h1 id="app-title">Fiches collège @annee_Libelle</h1></li>
+                    <li><h1 id="app-title">Fiches collège @Model.Annee_Lib</h1></li>
                 </ul>
                 <ul class="nav navbar-nav navbar-right">
                     <li class="search">
@@ -136,23 +136,23 @@
                 <li><a href="/">Accueil</a><span class="divider"></span></li>
                 <li><a>&gt;</a><span class="divider"></span></li>
                 <li>@Html.ActionLink("Collèges", "Index", "Colleges")</li>
-                @if (editionCollege)
+                @*@if (Model.Obj is College & Model.Acces == ModeAcces.Modification)
                 {
                     <li><a>&gt;</a><span class="divider"></span></li>
-                    <li>@Html.ActionLink(String.Format("{0} {1}", college_Id, college_Libelle), "Details", "Colleges", new { Id = college_Id })</li>
-                }
+                    <li>@Html.ActionLink(String.Format("{0} {1}", Model.Obj.CodeRne, Model.Obj.Libelle), "Details", "Colleges", new { Id = Model.Obj.Id })</li>
+                }*@
             </ul>
             @*@Html.MvcSiteMap().SiteMapPath()*@
         </div>
 
         <!-- Menu de niveau 2 -->
-        @if (editionCollege)
+        @if (Model.Obj is College | Model.Obj is Identite | Model.Obj is ActionCLAS)
         {
             <div>
                 <ul id="menu-l2">
-                    <li><a id="" class="@(controllerName == "Colleges" ? "active":"") btn-sm menu-color-@controllerName" href="@Url.Action("Details", "Colleges", new { Id = Model.College_Id })">Général</a></li>
-                    <li><a id="" class="@(controllerName == "Identites" ? "active":"") btn-sm menu-color-@controllerName" href="@Url.Action("Details", "Identites", new { Id = Model.College_Id })/">Identité</a></li>
-                    <li><a id="" class="@(controllerName == "ActionsCLAS" ? "active":"") btn-sm menu-color-@controllerName" href="@Url.Action("Details", "ActionsCLAS", new { Id = Model.College_Id })/">Actions</a></li>
+                    <li><a id="" class="@(controllerName == "Colleges" ? "active":"") btn-sm menu-color-@controllerName" href="@Url.Action("Details", "Colleges", new { id = Model.Id })">Général</a></li>
+                    <li><a id="" class="@(controllerName == "Identites" ? "active":"") btn-sm menu-color-@controllerName" href="@Url.Action("Details", "Identites", new { id = Model.Id })/">Identité</a></li>
+                    <li><a id="" class="@(controllerName == "ActionsCLAS" ? "active":"") btn-sm menu-color-@controllerName" href="@Url.Action("Details", "ActionsCLAS", new { id = Model.Id })/">Actions</a></li>
                 </ul>
             </div>
         }