示例#1
0
 private CommentInfoViewModel CreateCommentInfo(int commentId)
 {
     var comment = base.GetById(commentId);
     var writer = _context.Users.FirstOrDefault(u => u.Id == comment.UserId);
     var model = new CommentInfoViewModel
     {
         Id = commentId,
         Writer = $"{writer.FirstName} {writer.LastName}",
         AddedDate = comment.InsertDate,
         WriterImage = writer?.Avatar ?? "temp.png",
         Message = comment.Message
     };
     return model;
 }
示例#2
0
        public async Task <ActionResult> Add(AddCommentViewModel model)
        {
            Comment comment = null;
            Comment result  = null;

            try
            {
                var book = await _unitOfWork.BookRepository.FindByGoogleIdAsync(model.GoogleBookId);

                comment = Comment.Create(book.Id, User.Identity.GetUserId());
                comment = _mapper.Map(model, comment);
                result  = _unitOfWork.CommentRepository.Add(comment);
                await _unitOfWork.CompleteAsync();
            }
            catch (Exception e)
            {
                return(Json("error"));
            }
            CommentInfoViewModel returnModel = _mapper.Map <CommentInfoViewModel>(result);

            return(Json(returnModel));
        }