コード例 #1
0
        public ActionResult Index(Review review)
        {
            var mapper = MapperConfigWeb.GetConfigToDTO().CreateMapper();

            try
            {
                review.Id   = Guid.NewGuid().ToString();
                review.Date = DateTime.UtcNow;
                var reviewDto = mapper.Map <ReviewDTO>(review);
                _reviewService.CreateReview(reviewDto);
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError(ex.Property, ex.Message);
            }
            mapper = MapperConfigWeb.GetConfigFromDTO().CreateMapper();
            var model = mapper.Map <IEnumerable <Review> >(_reviewService.GetReviews());

            return(PartialView("Partials/ReviewList", model));
        }
コード例 #2
0
        public ActionResult Index(Comment comment)
        {
            var mapper = MapperConfigWeb.GetConfigToDTO().CreateMapper();

            try
            {
                comment.Id   = Guid.NewGuid().ToString();
                comment.Date = DateTime.UtcNow;
                comment.User = User.Identity.Name;
                var reviewDto = mapper.Map <CommentDTO>(comment);
                _commentService.CreateComment(reviewDto);
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError(ex.Property, ex.Message);
            }
            mapper = MapperConfigWeb.GetConfigFromDTO().CreateMapper();
            var model = mapper.Map <IEnumerable <Review> >(_commentService.GetComments(comment.IdArticle));

            return(PartialView("~/Views/Comment/Partials/DisplayComments.cshtml", model));
        }