Beispiel #1
0
        public ActionResult CreateComment(CommentViewModels model)
        //FormCollection collection)
        {
            if (ModelState.IsValid)
            {
                //InsertComment in DB
                using (var database = new BlogDbContext())
                {
                    //Get comentator id
                    var comentatorId = database.Users
                                       .Where(u => u.UserName == this.User.Identity.Name)
                                       .First()
                                       .Id;

                    //Set Comment
                    var comment = new Comment();
                    comment.CommentContent = model.CommentContent;
                    comment.UserId         = comentatorId;
                    comment.ArticleId      = model.ArticleId;



                    //Save comment in DB
                    database.Comments.Add(comment);
                    database.SaveChanges();

                    return(RedirectToAction("Details", "Article", new { id = comment.ArticleId }));
                }
            }

            return(View(model));
        }
Beispiel #2
0
        public ActionResult Edit(CommentViewModels model)
        {
            //Check if model state is valid
            if (ModelState.IsValid)
            {
                using (var database = new BlogDbContext())
                {
                    //Get comment from database
                    var comment = database.Comments
                                  .FirstOrDefault(a => a.Id == model.Id);

                    //Set comment properties
                    comment.Id             = model.Id;
                    comment.CommentContent = model.CommentContent;

                    //Save comment state in database
                    database.Entry(comment).State = EntityState.Modified;
                    database.SaveChanges();

                    //Redirect to the page
                    return(RedirectToAction("Details", "Article", new { id = comment.ArticleId }));
                }
            }
            //if model state is invalid, return the same view
            return(View(model));
        }
Beispiel #3
0
        public ActionResult Create(int id, CommentViewModels commentViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Create"));
            }

            ApplicationUser currentUser = this.Context.Users.FirstOrDefault(user => user.UserName == HttpContext.User.Identity.Name);
            Post            post        = this.Context.Posts.FirstOrDefault(p => p.Id == id);
            Comment         comment     = new Comment()
            {
                Message    = commentViewModel.Message,
                PostedDate = DateTime.Now,
                User       = currentUser,
                Post       = post
            };

            commentViewModel.userName   = currentUser.UserName;
            commentViewModel.PostedDate = comment.PostedDate;

            this.Context.Comments.Add(comment);
            this.Context.SaveChanges();

            /*ICollection<CommentViewModels> postComments = this.Context.Comments.Where(c => c.Post.Id == id).Select
             *  (c => new CommentViewModels()
             *  {
             *      Message = c.Message,
             *      PostedDate = c.PostedDate,
             *      userName = c.User.UserName,
             *      PostId = c.Post.Id
             *  }).ToList();*/

            return(PartialView("_Create", commentViewModel));
            //return RedirectToAction("Details", "Post", new { id = id });
        }
Beispiel #4
0
        // GET: Posts/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var post = await _context.Posts.Include(x => x.Category).FirstOrDefaultAsync(m => m.Id == id);

            var comments = await _context.Comments.Where(comment => comment.PostId == id).ToListAsync();

            var musics = await _context.Musics.Where(music => music.PostId == id).ToArrayAsync();

            CommentViewModels commentViewModels = new CommentViewModels()
            {
                Post     = post,
                Comments = comments,
                Musics   = musics
            };

            if (post == null)
            {
                return(NotFound());
            }

            return(View(commentViewModels));
        }
        public async Task <ActionResult> getComment(int id)
        {
            //  var comments = commSer.GetCommentsByArticle(id);
            var comms = await commSer.FindAllAsync(t => t.article.idArticle == id);

            List <CommentViewModels> gVM = new List <CommentViewModels>();

            foreach (var item in comms)
            {
                // var games = artSer.GetById(item.idArticle);
                // var name = games.name;
                CommentViewModels cm = new CommentViewModels()
                {
                    idArticle   = item.idArticle,
                    idUser      = item.idUser,
                    description = item.description,
                    date        = item.date,
                    user        = item.user,
                    article     = item.article,
                };

                gVM.Add(cm);
            }
            return(View(gVM));
        }
Beispiel #6
0
        public ActionResult CreateComment(int id)
        {
            //ViewBag.ArticleId = id;
            var model = new CommentViewModels();

            model.ArticleId = id;
            return(View(model));
        }
Beispiel #7
0
        public async Task <IActionResult> UpdateComment(int id, [FromBody] CommentViewModels model)
        {
            Result result = await _commentGateway.Update(model.PropositionId,
                                                         model.EventId, model.OrganizerId, model.Proposition,
                                                         model.PropositionDate);

            return(this.CreateResult(result));
        }
Beispiel #8
0
        public ActionResult AddComment(String CommentContent, String IDPost)
        {
            ReviewFilmService reviewS = new ReviewFilmService();

            string            IDUser = User.Identity.GetUserId();
            CommentViewModels result = reviewS.addComment(CommentContent, IDPost, IDUser);

            return(RedirectToAction("CommentsOfTopReview", new { page = 1, IDPhim = TempData["IDPhim"], IDReview = TempData["IDReview"] }));
        }
Beispiel #9
0
        public async Task <IActionResult> CreateComment([FromBody] CommentViewModels model)
        {
            int          userId = int.Parse(User.Claims.ElementAt <Claim>(0).Value);
            Result <int> result = await _commentGateway.Create(model.EventId,
                                                               userId, model.Proposition, DateTime.Now);

            //( SqlDbType.DateTime2
            return(this.CreateResult(result, o =>
            {
                o.RouteName = "GetComment";
                o.RouteValues = id => new { id };
            }));
        }
        // GET: Comment/Delete/5
        public ActionResult DeleteComm(int id, string idUser, DateTime date)
        {
            commentt item = new commentt();

            item = commSer.Get(t => t.article.idArticle == id && t.idUser.Equals(idUser) && t.date == date);
            CommentViewModels g = new CommentViewModels()
            {
                idArticle   = item.idArticle,
                idUser      = item.idUser,
                description = item.description,
                date        = item.date,
            }; return(View(g));
        }
Beispiel #11
0
        public ActionResult Create(CommentViewModels cvm)
        {
            Comment c = new Comment
            {
                Content     = cvm.Content,
                MemberID    = "7",
                PostID      = 1,
                DateComment = DateTime.Now
            };

            cs.Add(c);
            cs.Commit();
            return(RedirectToAction("Details"));
        }
Beispiel #12
0
        // GET: Comment/Delete/5
        public ActionResult DeleteComm(int id)
        {
            commentt item = new commentt();

            item = commSer.GetById(id);
            CommentViewModels g = new CommentViewModels()
            {
                idArticle   = item.idArticle,
                idUser      = item.idUser,
                description = item.description,
                date        = item.date,
                user        = item.user,
                article     = item.article,
            }; return(View(g));
        }
Beispiel #13
0
        public override async Task GetComments()
        {
            // Only add them if they don't already exist in the list
            foreach (FacebookComment comment in _facebookPost.Comments)
            {
                var any = CommentViewModels.Any(vm => vm.UserName.Equals(comment.User.Name) && vm.UserImageUrl.Equals(comment.User.Picture) && vm.Text.Equals(comment.Message));

                if (!any)
                {
                    var viewModel = new FacebookCommentCardViewModel(comment);

                    CommentViewModels.Add(viewModel);
                }
            }
        }
        public List <CommentViewModels> getComment(String IDPost)
        {
            CommentBus cmtBus = new CommentBus();

            List <CommentViewModels> result = new List <CommentViewModels>();

            List <BinhLuan> lst = cmtBus.getComments(Int32.Parse(IDPost));

            foreach (BinhLuan p in lst)
            {
                CommentViewModels pvm = BinhLuan2ViewModels(p);
                result.Add(pvm);
            }

            return(result);
        }
Beispiel #15
0
        public async Task <IActionResult> Create(
            [FromBody] CommentCreationContext.CommentForm commentForm,
            [FromServices] CommentCreationContext commentCreationContext)
        {
            try
            {
                var comment = await commentCreationContext
                              .Setup(UserId)
                              .CreateAsync(commentForm);

                return(Ok(CommentViewModels.Create(comment)));
            }
            catch (CommentCreationContext.ParentNotFoundException e)
            {
                return(BadRequest(e.Message));
            }
        }
        private CommentViewModels BinhLuan2ViewModels(BinhLuan p)
        {
            CommentViewModels result = new CommentViewModels();

            result.datePost = (DateTime)p.NgayDang;
            result.content  = p.NoiDung;

            AccountBus acBus = new AccountBus();

            ThanhVien temp = acBus.getMemberByUserId(p.MS_ThanhVien.ToString());

            result.url_Avatar = temp.Avatar;
            result.fullName   = temp.HoTen;

            result.IDPost = p.MS_BaiNhanXet.ToString();

            return(result);
        }
        internal CommentViewModels addComment(string CommentContent, string IDPost, string IDUser)
        {
            CommentViewModels result    = new CommentViewModels();
            ReviewFilmsBus    reviewBus = new ReviewFilmsBus();

            BinhLuan binhLuan = new BinhLuan();

            binhLuan.MS_BaiNhanXet = Int32.Parse(IDPost);
            binhLuan.MS_ThanhVien  = IDUser;
            binhLuan.NoiDung       = CommentContent;
            binhLuan.NgayDang      = System.DateTime.Now;
            if (reviewBus.addComment(binhLuan))
            {
                result = BinhLuan2ViewModels(binhLuan);
            }

            return(result);
        }
Beispiel #18
0
        public async Task <IActionResult> CreateComment(
            [FromBody] CommentCreationContext.CommentForm commentForm,
            [FromServices] CommentCreationContext commentCreationContext)
        {
            try
            {
                // Provide UserId when creating comment, so we know who it belongs to
                var comment = await commentCreationContext
                              .Setup(UserId)
                              .CreateCommentAsync(commentForm);

                // Return ok with created comment
                return(Ok(CommentViewModels.Create(comment)));
            }
            catch (CommentCreationContext.ParentNotFoundException e)
            {
                return(BadRequest(e.Message));
            }
        }
Beispiel #19
0
        public ActionResult Submit(CommentViewModels comment)
        {
            try
            {
                using (DbContextTransaction transaction = _context.Database.BeginTransaction())
                {
                    _context.Comments.Add(_converter.CreateComment(comment));
                    _context.SaveChanges();

                    transaction.Commit();
                }
            }
            catch (Exception ex)
            {
                Response.StatusCode        = 500;
                Response.StatusDescription = ex.Message;
            }

            var isBlog = comment.PropertyId == null;

            return(RedirectToAction("Detail", isBlog ? "Blog" : "Home", new { id = isBlog ? comment.PostId : comment.PropertyId }));
        }
Beispiel #20
0
        public PartialViewResult AddComment(IFormCollection collection)
        {
            int     postId      = Convert.ToInt32(collection["postId"][0]);
            var     currentPost = _context.Posts.Where(p => p.Id == postId).FirstOrDefault();
            string  userId      = collection["userId"][0];
            Comment newComment  = new Comment()
            {
                Content = collection["comment"][0],
                UserId  = userId,
                PostId  = currentPost.Id,
                Post    = currentPost
            };

            _context.Add(newComment);
            _context.SaveChanges();

            CommentViewModels commentViewModel = new CommentViewModels()
            {
                Post     = currentPost,
                Comments = currentPost.Comments
            };

            return(PartialView("CommentPartial", commentViewModel));
        }
Beispiel #21
0
        //GET: Comment/Edit
        public ActionResult EditComment(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            using (var database = new BlogDbContext())
            {
                //Get comment from database
                var comment = database.Comments
                              .Where(cm => cm.Id == id)
                              .FirstOrDefault();


                if (!IsUserAuthorizedToEdit(comment))
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                }

                //Check if comment exists
                if (comment == null)
                {
                    return(HttpNotFound());
                }

                //Create the view model
                var model = new CommentViewModels();
                model.Id             = comment.Id;
                model.ArticleId      = comment.ArticleId;
                model.CommentContent = comment.CommentContent;

                //Pass view model to View
                return(View(model));
            }
        }
Beispiel #22
0
        public ActionResult getMostCommented()
        {
            var games      = artSer.getMostCommented().ToArray();
            var TotalGames = artSer.GetMany().ToArray();


            var totalFund = artSer.GetMany().ToArray();
            var comm      = commSer.getDateOfComm().ToArray();


            List <gameViewModels> gVM = new List <gameViewModels>();

            foreach (var item in games)
            {
                gameViewModels gm = new gameViewModels()
                {
                    idArticle   = item.idArticle,
                    DTYPE       = item.DTYPE,
                    name        = item.name,
                    description = item.description,
                    link_img    = item.link_img,
                    date        = item.date,
                    commentts   = item.commentts,
                };
                gVM.Add(gm);
            }


            CommentViewModels cm = new CommentViewModels();

            ViewBag.gmCount        = games.Count();
            ViewBag.TotalCount     = TotalGames.Count();
            ViewBag.notcommented   = TotalGames.Count() - games.Count();
            ViewBag.usersComm      = users.getUsersComments().Count();
            ViewBag.totalUsers     = users.GetMany().Count();
            ViewBag.NonActiveUsers = users.GetMany().Count() - users.getUsersComments().Count();

            var comms1  = commSer.GetCommentsByMonth(1).ToArray();
            var comms2  = commSer.GetCommentsByMonth(2).ToArray();
            var comms3  = commSer.GetCommentsByMonth(3).ToArray();
            var comms4  = commSer.GetCommentsByMonth(4).ToArray();
            var comms5  = commSer.GetCommentsByMonth(5).ToArray();
            var comms6  = commSer.GetCommentsByMonth(6).ToArray();
            var comms7  = commSer.GetCommentsByMonth(7).ToArray();
            var comms8  = commSer.GetCommentsByMonth(8).ToArray();
            var comms9  = commSer.GetCommentsByMonth(9).ToArray();
            var comms10 = commSer.GetCommentsByMonth(10).ToArray();
            var comms11 = commSer.GetCommentsByMonth(11).ToArray();
            var comms12 = commSer.GetCommentsByMonth(12).ToArray();

            ViewBag.nbComm1  = comms1.Count();
            ViewBag.nbComm2  = comms2.Count();
            ViewBag.nbComm3  = comms3.Count();
            ViewBag.nbComm4  = comms4.Count();
            ViewBag.nbComm5  = comms5.Count();
            ViewBag.nbComm6  = comms6.Count();
            ViewBag.nbComm7  = comms7.Count();
            ViewBag.nbComm8  = comms8.Count();
            ViewBag.nbComm9  = comms9.Count();
            ViewBag.nbComm10 = comms10.Count();
            ViewBag.nbComm11 = comms11.Count();
            ViewBag.nbComm12 = comms12.Count();



            return(View(gVM));
        }