public ActionResult Create(CommentInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return this.View();
            }

            var comment = new Comment
            {
                Content = model.Content,
                TripId = model.TripId,
                CreatorId = this.User.Identity.GetUserId()
            };

            this.commentService.Create(comment);

            return this.RedirectToAction("Details", "Trip", new { id = model.TripId });
        }
예제 #2
0
        public ActionResult AddComment(CommentInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return this.View();
            }

            var comment = new Comment
            {
                Content = model.Content,
                TripId = model.TripId,
                CreatorId = this.User.Identity.GetUserId()
            };

            var trip = this.trips.GetById(comment.TripId)
                                  .FirstOrDefault();

            if (trip == null)
            {
                throw new Exception("Not Existing Trip!");
            }

            trip.Comments.Add(comment);
            this.trips.Update(trip);
            return this.RedirectToAction("Details", "Trip", new { id = model.TripId });
        }