コード例 #1
0
        public async Task <CommentResponse> Create(CommentDTO newComment)
        {
            var comment = CommentMapper.Map(newComment);

            if (comment.UserId < 0)
            {
                string errorMessage = "Comment user ID not found.";
                Log.Error(errorMessage);
                return(new CommentResponse(errorMessage));
            }
            if (comment.Text == null)
            {
                string errorMessage1 = "Comment context not found.";
                Log.Error(errorMessage1);
                return(new CommentResponse(errorMessage1));
            }
            try
            {
                await _commentRepository.Create(comment);

                await _context.SaveChangesAsync();

                return(new CommentResponse(CommentMapper.Map(comment)));
            }
            catch (Exception exception)
            {
                string errorMessage = $"An error occured when creating the item: {exception.Message}";
                return(new CommentResponse(errorMessage));
            }
        }
コード例 #2
0
ファイル: ArticleService.cs プロジェクト: hrybnyak/Blog
        public async Task <ArticleDTO> GetArticleById(int id)
        {
            var article = _unitOfWork.ArticleRepository.Get(a => a.Id == id, includeProperties: "Comments,ArticleTegs").FirstOrDefault();

            if (article == null)
            {
                throw new ArgumentNullException(nameof(article));
            }
            var result = ArticleMapper.Map(article);

            if (article.Comments != null && article.Comments.Count > 0)
            {
                result.Comments = new List <CommentDTO>();
                foreach (Comment comment in article.Comments)
                {
                    CommentDTO dto = CommentMapper.Map(comment);
                    dto.CreatorUsername = (await _userManager.FindByIdAsync(comment.UserId)).UserName;
                    result.Comments.Add(dto);
                }
            }
            result.AuthorId       = (await _unitOfWork.BlogRepository.GetByIdAsync(article.BlogId)).OwnerId;
            result.AuthorUsername = (await _userManager.FindByIdAsync(result.AuthorId)).UserName;
            if (article.ArticleTegs != null && article.ArticleTegs.Count > 0)
            {
                result.Tegs = new List <TegDTO>();
                foreach (ArticleTeg teg in article.ArticleTegs)
                {
                    result.Tegs.Add(TegMapper.Map(await _unitOfWork.TegRepository.GetByIdAsync(teg.TegId)));
                }
            }
            return(result);
        }
コード例 #3
0
 public ActionResult CommentArticle(CommentViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         Service.Comment(CommentMapper.Map(viewModel));
     }
     return(GetArticleComments(viewModel.ArticleId));
 }
コード例 #4
0
        public IActionResult Insert(Comentario com)
        {
            if (!ModelState.IsValid)
            {
                throw new System.Exception("Not valid value provid. See documentation");
            }

            return(Created(Request.Path.Value, CommentMapper.Map(_work.RepositoryComentarios.Insert(com))));
        }
コード例 #5
0
        public void MapCommonConditionSuccessTest()
        {
            var comment       = new Comment(3, "My test comment", "My test name", "*****@*****.**");
            var commentMapper = new CommentMapper();

            Entities.Comment result = commentMapper.Map(comment);

            Assert.AreEqual(3, result.PostId);
            Assert.AreEqual("My test comment", result.Text);
            Assert.AreEqual("*****@*****.**", result.CommenterEmail);
            Assert.AreEqual("My test name", result.CommenterName);
        }
コード例 #6
0
        public async Task <CommentResponse> GetById(int id)
        {
            var comment = await _commentRepository.GetById(id);

            if (comment == null)
            {
                string errorMessage = "Comment not found.";

                Log.Error(errorMessage);

                return(new CommentResponse(errorMessage));
            }

            return(new CommentResponse(CommentMapper.Map(comment)));
        }
コード例 #7
0
        public IActionResult Update(Comentario com)
        {
            if (!ModelState.IsValid)
            {
                throw new System.Exception("Not valid value provid. See documentation");
            }

            if (_work.RepositoryComentarios.Update(com))
            {
                return(Ok(CommentMapper.Map(com)));
            }
            else
            {
                throw new System.Exception("An fail has ocurred");
            }
        }
コード例 #8
0
        public List <TicketComment> CommentList(int TktId)
        {
            CommentMapper mprobj = new CommentMapper();

            SqlParameter[] parameters =
            {
                new SqlParameter("@Type",     "B"),
                new SqlParameter("@TicketID", TktId)
            };
            IDataReader reader = base.GetReader("SP_Manage_Comment", parameters);

            using (reader)
            {
                return(mprobj.Map(reader));
            }
        }
コード例 #9
0
        public void MapDbCommentTest()
        {
            var dbComment = new Comment
            {
                Text           = "comment",
                CommenterName  = "name",
                PostId         = 1,
                CommenterEmail = "email"
            };
            var mapper = new CommentMapper();
            var result = mapper.Map(dbComment);

            Assert.AreEqual(result.PostId, 1);
            Assert.AreEqual(result.CommenterName, "name");
            Assert.AreEqual(result.CommenterEmail, "email");
            Assert.AreEqual(result.Text, "comment");
        }
コード例 #10
0
        public ActionResult Create([Bind(Include = "Id,Comentario")] CommentViewModel comment, int bookId)
        {
            if (ModelState.IsValid)
            {
                _commentRepository.Add(CommentMapper.Map(comment), bookId);

                var book = VerifyData(bookId);
                if (book == null)
                {
                    return(HttpNotFound("El Id bo corresponde a un Book"));
                }

                return(RedirectToAction("Create", "Comments", new { bookId = bookId }));
            }

            return(View());
        }
コード例 #11
0
 public IEnumerable <Comment> GetAllCommentsByRequestId(int id)
 {
     using (var command = new SqlCommand("sp_GetAllCommentsByRequestId", _connection))
     {
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.AddWithValue("@RequestId", id);
         var commentList = new List <Comment>();
         using (var reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 var comment = CommentMapper.Map(reader);
                 commentList.Add(comment);
             }
         }
         return(commentList);
     };
 }
コード例 #12
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            CommentMapper.Map(modelBuilder.Entity <Comment>());
            IngredientMapper.Map(modelBuilder.Entity <Ingredient>());
            LikeMapper.Map(modelBuilder.Entity <Like>());
            MeasureMapper.Map(modelBuilder.Entity <Measure>());
            RecipeTagMapper.Map(modelBuilder.Entity <RecipeTag>());
            TagMapper.Map(modelBuilder.Entity <Tag>());
            RecipeMapper.Map(modelBuilder.Entity <Recipe>());
            UserMapper.Map(modelBuilder.Entity <User>());

            foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
            {
                relationship.DeleteBehavior = DeleteBehavior.Restrict;
            }
        }
コード例 #13
0
        public void MapCommonConditionSuccessTest()
        {
            var user    = new User(1, "John", "*****@*****.**", "url");
            var comment = new Comment(3, "My test comment", "My test name", "*****@*****.**");

            var userMapper    = new UserMapper();
            var commentMapper = new CommentMapper(userMapper);

            Core.Models.Comment result = commentMapper.Map(comment, user);

            Assert.AreEqual(3, result.PostId);
            Assert.AreEqual("My test comment", result.Text);
            Assert.AreNotEqual(null, result.User);
            Assert.AreEqual(1, result.User.UserId);
            Assert.AreEqual("John", result.User.Name);
            Assert.AreEqual("*****@*****.**", result.User.Email);
            Assert.AreEqual("url", result.User.ImageUrl);
        }
コード例 #14
0
        public void CommentMapTest()
        {
            // Arrange
            var commentMapper = new CommentMapper();

            dynamic obj = new JObject();
            obj.id = "101";
            obj.created_at = "2017-11-20T14:28:53.572+11:00";
            obj.body = "Hey!";

            var comment = new Comment();

            // Act
            commentMapper.Map(obj, comment);

            // Assert
            Assert.AreEqual(comment.Id, 101);
            Assert.AreEqual(comment.CreatedAt, Convert.ToDateTime("2017-11-20T14:28:53.572+11:00"));
            Assert.AreEqual(comment.Body, "Hey!");
        }
コード例 #15
0
 public Comment ToModel()
 {
     return(mapper.Map(this));
 }
コード例 #16
0
        public IActionResult Get()
        {
            var comments = _work.RepositoryComentarios.GetAll().ToList();

            return(Ok(CommentMapper.Map(comments)));
        }
コード例 #17
0
        public IEnumerable <CommentDTO> GetAllCommentsToOneEncounter(string encounterId)
        {
            try
            {
                List <CommentDTO> comments = encounterRepository.Get(encounterId).Comments.Select(c => commentMapper.Map(c)).ToList();
                comments.ForEach(c => c.EncounterId = encounterId);

                return(comments);
            }
            catch (DataAccessException e)
            {
                throw new ServicesException("Failure to recover all commentaries from encounter with id " + encounterId, e);
            }
        }
コード例 #18
0
        public IActionResult GetByReview(int id)
        {
            var comments = _work.RepositoryComentarios.GetByCritica(id);

            return(Ok(CommentMapper.Map(comments)));
        }
コード例 #19
0
        public IActionResult GetPaginatedCrit(int idRew, int page, int rows)
        {
            var comments = _work.RepositoryComentarios.GetPaginated(idRew, page, rows).ToList();

            return(Ok(CommentMapper.Map(comments)));
        }