Przeglądaj źródła

Redirige Home/Index vers Annees/Details

olivier.massot 7 lat temu
rodzic
commit
d52d9e389e
1 zmienionych plików z 18 dodań i 2 usunięć
  1. 18 2
      CD67.FicheCollege.MVC/Controllers/HomeController.cs

+ 18 - 2
CD67.FicheCollege.MVC/Controllers/HomeController.cs

@@ -1,13 +1,29 @@
-using System.Web.Mvc;
+using CD67.FicheCollege.Entity;
+using System;
+using System.Linq;
+using System.Web.Mvc;
 
 namespace CD67.FicheCollege.MVC.Controllers
 {
     public class HomeController : Controller
     {
+        private Entities db = new Entities();
+
         // GET: Home
         public ActionResult Index()
         {
-            return View();
+            string annee_lib;
+
+            if (DateTime.Now.Month <= 6) {
+                annee_lib = String.Format("{0}-{1}", DateTime.Now.Year - 1, DateTime.Now.Year);
+            }
+            else {
+                annee_lib = String.Format("{0}-{1}", DateTime.Now.Year, DateTime.Now.Year + 1);
+            }
+
+            int annee_id = db.Annees.Where(a => a.Libelle == annee_lib).First().Id;
+
+            return RedirectToActionPermanent("Details", "Annees", new { id = annee_id });
         }
     }
 }