Ejemplo n.º 1
0
            public async Task <CommentDto> Handle(Command request,
                                                  CancellationToken cancellationToken)
            {
                var activity = await _context.Activities.FindAsync(request.ActivityId);

                if (activity == null)
                {
                    throw new RestException(System.Net.HttpStatusCode.NotFound, new { Activity = "Not found" });
                }
                var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == request.Username);

                var comment = new Domain.Comment
                {
                    Author    = user,
                    Activity  = activity,
                    Body      = request.Body,
                    CreatedAt = DateTime.Now
                };

                activity.Comments.Add(comment);

                var succes = await _context.SaveChangesAsync() > 0;

                if (succes)
                {
                    return(_mapper.Map <CommentDto>(comment));
                }
                throw new Exception("Problem saving changes");
            }
Ejemplo n.º 2
0
 public virtual void AddComment(Comment comment)
 {
     if (comment == null)
     {
         return;
     }
     Comments.Add(comment);
 }
Ejemplo n.º 3
0
 public CommentModel(Domain.Comment comment)
 {
     Id        = comment.Id;
     AuthorId  = comment.Author.Id;
     Content   = comment.Content.Value;
     ReviewId  = comment.Review.Id;
     CreatedAt = comment.CreatedAt;
     Author    = comment.Author.Model != null ? new UserModel(comment.Author.Model) : null;
     Review    = comment.Review.Model != null ? new ReviewModel(comment.Review.Model) : null;
 }
Ejemplo n.º 4
0
        public static DAL.App.DTO.DomainLikeDTO.Comment MapFromDomain(Domain.Comment comment)
        {
            var res = comment == null ? null : new DAL.App.DTO.DomainLikeDTO.Comment
            {
                Id           = comment.Id,
                CommentTitle = comment.CommentTitle.Translate(),
                CommentBody  = comment.CommentBody.Translate(),
                ProductId    = comment.ProductId,
                Product      = ProductMapper.MapFromDomain(comment.Product),
                ShopId       = comment.ShopId,
                Shop         = ShopMapper.MapFromDomain(comment.Shop)
            };

            return(res);
        }
Ejemplo n.º 5
0
        private static void CreatePost(string title)
        {
            var postRepository = new PostRepository();
            var categoryRepository = new CategoryRepository();
            var commentRepository = new CommentRepository();

            var post = new Post
                           {
                               Title = title,
                               PostedDate = DateTime.Now,
                               Contents = "This is just a simple test post..."
                           };

            for (int i = 0; i < 10; i++)
            {
                var category = new Category
                                   {
                                       Name = "Category " + i,
                                       CreatedDate = DateTime.Now,
                                       Description = "Just a test..."
                                   };

                post.AddCategory(category);
                categoryRepository.Create(category);
            }

            for (int i = 0; i < 20; i++)
            {
                var comment = new Comment
                                  {
                                      PostedDate = DateTime.Now,
                                      Author = "Author " + i,
                                      Text = "testing..."
                                  };

                post.AddComment(comment);
                commentRepository.Create(comment);
            }

            postRepository.Create(post);
        }
Ejemplo n.º 6
0
        public int AddComment(string text, int PostId)
        {
            var user = unitOfWork.Users.Query.First(e => e.Id == CurrentUser.Id);

            if (user.IsBanned)
            {
                return(-1);
            }

            var comment = new Domain.Comment()
            {
                Content      = text,
                PostId       = PostId,
                UserId       = CurrentUser.Id,
                AddingMoment = DateTime.Now
            };

            unitOfWork.Comments.Add(comment);
            unitOfWork.SaveChanges();
            return(comment.Id);
        }
 /// <summary>
 /// Assigns the comment.
 /// </summary>
 /// <param name="comment">The comment.</param>
 /// <returns>ticket comment</returns>
 public TeamDashboardPresenter AssignComment(Comment comment)
 {
     this.comment = comment;
     return this;
 }
Ejemplo n.º 8
0
 /// <inheritdoc />
 public void Comment(Comment comment) => this.Comments.Add(comment);
Ejemplo n.º 9
0
 /// <summary>
 /// Assigns the comment.
 /// </summary>
 /// <param name="comment">The comment.</param>
 /// <returns>ticket comment</returns>
 public TicketPresenter AssignComment(Comment comment)
 {
     this.comment = comment;
     return this;
 }