Exemplo n.º 1
0
        public void Execute(AddComment request)
        {
            _validator.ValidateAndThrow(request);
            var comentDto = Context.Comments.Find(request);

            if (comentDto != null)
            {
                try
                {
                    comentDto.IsDeleted   = false;
                    comentDto.ModifidedAt = DateTime.Now;
                    comentDto.PostId      = request.PostId;
                    comentDto.UserId      = request.UserID;
                    comentDto.Text        = request.Text;
                    Context.SaveChanges();
                }
                catch (Exception)
                {
                    throw new Exception();
                }
            }
            else
            {
                throw new EntityNotFoundException(request.Id, typeof(AddComment));
            }
        }
Exemplo n.º 2
0
        public void Execute(CommentDto request)
        {
            var id = request.Id;

            var comment = _context.Comments.Find(id);

            if (comment == null)
            {
                throw new EntityNotFoundException(id, typeof(CommentDto));
            }

            _validator.ValidateAndThrow(request);

            _mapper.Map(request, comment);

            _context.SaveChanges();
        }