Ejemplo n.º 1
0
        public ActionResult Index()
        {
            var vml            = new List <ViewFormationAvisModel>();
            var listFormations = new List <Formation>();

            using (var context = new AvisEntities())
            {
                listFormations = context.Formations.OrderBy(x => Guid.NewGuid()).Take(4).ToList();
                foreach (var l in listFormations)
                {
                    var vm = new ViewFormationAvisModel();
                    vm.id          = l.Id;
                    vm.nom         = l.Nom;
                    vm.url         = l.Url;
                    vm.description = l.Description;
                    vm.nomseo      = l.NomSeo;
                    vm.nombreAvis  = l.Avis.Count();
                    if (l.Avis.Count > 0)
                    {
                        vm.noteFormation = l.Avis.Average(f => f.Note);
                    }
                    else
                    {
                        vm.noteFormation = 0;
                    }
                    vm.avis = l.Avis.ToList();
                    vml.Add(vm);
                }
            }
            return(View(vml));
        }
Ejemplo n.º 2
0
        public ActionResult DetailsFormation(string nSeo = "none")
        {
            var formation             = new Formation();
            ViewFormationAvisModel vm = new ViewFormationAvisModel();

            using (var context = new AvisEntitis())
            {
                formation = context.Formation.Where(f => f.NomSeo == nSeo).FirstOrDefault();
                if (formation == null)
                {
                    RedirectToAction("index", "Home");
                }
                else
                {
                    vm.id          = formation.Id;
                    vm.nom         = formation.Nom;
                    vm.url         = formation.Url;
                    vm.description = formation.Description;
                    vm.nomseo      = formation.NomSeo;
                    vm.nombreAvis  = formation.Avis.Count;
                    if (formation.Avis.Count > 0)
                    {
                        vm.noteFormation = formation.Avis.Average(f => f.Note);
                    }
                    else
                    {
                        vm.noteFormation = 0;
                    }

                    vm.avis = formation.Avis.ToList();
                }
            }
            return(View(vm));
        }