/// <summary> /// Show the index page. /// The content depends on whether the user is connected or not /// The page contains the new products and the top n of rented products for anyone /// It shows the products currently rented by someone if he's connected /// </summary> /// <returns>View</returns> public ActionResult Index() { string role = ""; string id = ""; int idUser = 0; if (Request.IsAuthenticated) { var claimIdentity = User.Identity as ClaimsIdentity; if (claimIdentity != null) { role = claimIdentity.FindFirst(ClaimTypes.Role).Value; id = claimIdentity.FindFirst(ClaimTypes.NameIdentifier).Value; idUser = Convert.ToInt32(id); } } ProductsDb dbProducts = new ProductsDb(); RentDb dbRent = new RentDb(); ModelState.Clear(); AccueilViewModel vm = new AccueilViewModel { NewProducts = dbProducts.GetNewProducts() }; if (Request.IsAuthenticated) { if (role == "User") { vm.Rent = dbRent.GetRentByCustomer(idUser); } } return(View(vm)); }