示例#1
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));
        }
示例#2
0
        public ActionResult Index()
        {
            var vml       = new List <ViewFormationAvisModel>();
            var formation = new List <Formation>();

            using (var context = new AvisEntitis())
            {
                formation = context.Formation.OrderBy(g => Guid.NewGuid()).Take(4).ToList();
                foreach (var l in formation)
                {
                    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));
        }
示例#3
0
        public bool IsExiste(string user_id, int formationId)
        {
            Avis avi;

            using (var context = new AvisEntitis())
            {
                avi = context.Avis.FirstOrDefault(a => a.IdFormation == formationId && a.UserId == user_id);
            }
            return((avi != null) ? true : false);
        }
示例#4
0
        // GET: Formation
        public ActionResult ToutesLesFormations()
        {
            var listFormation = new List <Formation>();

            using (var contexte = new AvisEntitis())
            {
                listFormation = contexte.Formation.ToList();
            }


            return(View(listFormation));
        }
示例#5
0
 public string GetNameByUserId(string user_id)
 {
     using (var context = new AvisEntitis())
     {
         var namePerson = context.Person.Where(f => f.user_id == user_id).FirstOrDefault();
         if (namePerson == null)
         {
             return("Anonyme");
         }
         else
         {
             return(namePerson.Nom);
         }
     }
 }
示例#6
0
        public void InsertPerson(string user_id, string nom)
        {
            using (var context = new AvisEntitis())
            {
                var person = context.Person.Where(f => f.user_id == user_id).FirstOrDefault();
                if (person == null)
                {
                    Person p = new Person();
                    p.Nom     = nom;
                    p.user_id = user_id;

                    context.Person.Add(p);
                    context.SaveChanges();
                }
            }
        }
示例#7
0
        public ActionResult LaisserUnAvis(String nSeo)
        {
            LaisserUnAvisViewModel vm = new LaisserUnAvisViewModel();

            vm.formationNseo = nSeo;
            using (var context = new AvisEntitis())
            {
                var formation = context.Formation.FirstOrDefault(f => f.NomSeo == nSeo);
                if (formation == null)
                {
                    RedirectToAction("ToutesLesFormations", "Formation");
                }

                vm.formationName = formation.Nom;
            }
            return(View(vm));
        }
示例#8
0
        public ActionResult SaveComment(string name, string note, string description, string nSeo)
        {
            PersonManager mgr     = new PersonManager();
            string        user_id = User.Identity.GetUserId();

            Avis nouveAvis = new Avis();

            nouveAvis.DateAvis    = DateTime.Now;
            nouveAvis.Description = description;
            nouveAvis.Nom         = name;
            nouveAvis.UserId      = "";
            //
            double dNote = 0;

            if (!double.TryParse(note, out dNote))
            {
                throw new Exception("Parse Invalid");
            }
            else
            {
                nouveAvis.Note = dNote;
            }

            using (var context = new AvisEntitis())
            {
                var formation = context.Formation.FirstOrDefault(f => f.NomSeo == nSeo);
                nouveAvis.IdFormation = formation.Id;
                nouveAvis.Nom         = mgr.GetNameByUserId(user_id);
                PersonManager mngr = new PersonManager();
                if (mngr.IsExiste(User.Identity.GetUserId(), nouveAvis.IdFormation) == false)
                {
                    context.Avis.Add(nouveAvis);
                    context.SaveChanges();
                }
            }

            /// RedirectToAction("DetailsFormation", "Formations", new { nSeo = nSeo });

            return(RedirectToAction("DetailsFormation", "Formation", new { nSeo = nSeo }));
        }