public JsonResult AjouterCommentaire(CommentViewModel cvm)
        {
            var c = new DataLayer.Models.Commentaires()
            {
                idParent  = cvm.parent_id,
                datePoste = DateTime.Now,
                idProduit = cvm.product_id,
                texte     = cvm.text,
                idAuteur  = _user.GetUserId()
            };

            _db.Commentaires.Add(c);
            _db.SaveChanges();

            var auteur         = _user.Name;
            var auteurOriginal = _db.Commentaires.Where(co => co.idComment == cvm.parent_id).Select(p => p.AspNetUsers.UserName);
            int nbComm         = _db.Commentaires.Where(co => co.idProduit == 2).Count();

            var results = new Dictionary <string, object>();

            results.Add("success", "true");
            var comments = new List <Dictionary <string, object> >();
            var comment  = new Dictionary <string, object>();

            results.Add("parent_id", cvm.parent_id);
            results.Add("in_reply_to", auteurOriginal);
            results.Add("element_id", "134");
            results.Add("created_by", "1");
            results.Add("fullname", auteur);
            results.Add("picture", "../../Content/Comments/images/user_blank_picture.png");
            results.Add("posted_date", c.datePoste.ToString());
            results.Add("text", c.texte);
            var children = new List <Dictionary <string, object> >();

            results.Add("childrens", children);
            var users = new Dictionary <string, string>();

            users.Add("user_id", "1");
            users.Add("fullname", "Administrator admin");
            users.Add("picture", "../../Content/Comments/images/user_blank_picture.png");
            users.Add("is_logged_in", "false");
            users.Add("is_add_allowed", "true");
            users.Add("is_edit_allowed", "true");

            results.Add("user", users);
            var r = new CommentViewModel()
            {
                success = true,
                results = results
            };

            return(Json(results));
        }
        public JsonResult AjouterCommentaire(CommentViewModel cvm)
        {
            var c = new DataLayer.Models.Commentaires()
            {
                idParent = cvm.parent_id,
                datePoste = DateTime.Now,
                idProduit = cvm.product_id,
                texte = cvm.text,
                idAuteur = _user.GetUserId()
            };
            _db.Commentaires.Add(c);
            _db.SaveChanges();

            var auteur = _user.Name;
            var auteurOriginal = _db.Commentaires.Where(co => co.idComment == cvm.parent_id).Select(p => p.AspNetUsers.UserName);
            int nbComm = _db.Commentaires.Where(co => co.idProduit == 2).Count();

            var results = new Dictionary<string, object>();
            results.Add("success", "true");
            var comments = new List<Dictionary<string, object>>();
            var comment = new Dictionary<string, object>();
            results.Add("parent_id", cvm.parent_id);
            results.Add("in_reply_to", auteurOriginal);
            results.Add("element_id", "134");
            results.Add("created_by", "1");
            results.Add("fullname", auteur);
            results.Add("picture", "../../Content/Comments/images/user_blank_picture.png");
            results.Add("posted_date", c.datePoste.ToString());
            results.Add("text", c.texte);
            var children = new List<Dictionary<string, object>>();
            results.Add("childrens", children);
            var users = new Dictionary<string, string>();
            users.Add("user_id", "1");
            users.Add("fullname", "Administrator admin");
            users.Add("picture", "../../Content/Comments/images/user_blank_picture.png");
            users.Add("is_logged_in", "false");
            users.Add("is_add_allowed", "true");
            users.Add("is_edit_allowed", "true");

            results.Add("user", users);
            var r = new CommentViewModel()
            {
                success = true,
                results = results
            };
            return Json(results);
        }
        public ActionResult Comment(CommentViewModel cvm, int id)
        {
            // TODO debut : problème avec le GetUSerId ici
            // TODO tester mlodèle + règles métiers sur entrée utilisateurs
            // + vérifier enrigtrement BDD pour afficher éventuellement petit message
            var user = UserManager.FindById(User.Identity.GetUserId());
            var commentaire = new Commentaires
            {
                IdHotel = id,
                IdUtilisateur = _db.Utilisateurs.Where(u => u.IdAspNetUsers == user.Id)
                                                .Select(u => u.IdUtilisateur)
                                                .FirstOrDefault(),
                Titre = cvm.Titre,
                Commentaire = cvm.Commentaire,
                DateCommentaire = DateTime.Now,
                IdCommentaireReference = cvm.IdCommentaire
            };

            _db.Commentaires.Add(commentaire);
            _db.SaveChanges();

            return RedirectToAction("Details", new {id = id});
        }