コード例 #1
0
        public async Task<ActionResult> AddComment(CreateCommentsViewModel model)
        {
            if (ModelState.IsValid)
            {
                string userId = User.Identity.GetUserId();
                var activity = await db.Activities.FindAsync(model.ActivityId);

                var newComment = new Comment()
                {

                    Description = model.Description,
                    CommentOwner = await db.Users.FirstAsync(u => u.Id == userId),
                    CreationDate = DateTime.Now
                };
                activity.Comments.Add(newComment);

                db.SaveChanges();

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

        }
コード例 #2
0
        // GET: Comment/AddComment/ActivityId
        public ActionResult AddComment(int id)
        {
            if (id <= 0)
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);



            var model = new CreateCommentsViewModel
            {
                ActivityId = id
            };

            return View(model);
        }