public async Task <Comment> CreateAsync(int photoId, string userName, string subject, string body)
        {
            Guard.Against.NullOrEmpty(subject, nameof(subject));
            Guard.Against.Null(photoId, nameof(photoId));
            Comment comment = new Comment(photoId, userName, subject, body, DateTime.Now);

            _logger.LogInformation("CreateAsync called", comment);
            return(await _commentsRepository.CreateAsync(comment));
        }
Beispiel #2
0
        public async Task <Comment> CreateAsync(int photoId, string subject, string body, string tokenValue)
        {
            Guard.Against.NullOrEmpty(subject, nameof(subject));
            Guard.Against.NullOrEmpty(body, nameof(body));

            var comment = new Comment()
            {
                PhotoId = photoId, Subject = subject, Body = body
            };

            return(await repository.CreateAsync(comment, tokenValue));
        }
Beispiel #3
0
        public async Task <IActionResult> CreateComment(CommentsViewModel model)
        {
            if (string.IsNullOrWhiteSpace(model.NewComment.Content))
            {
                return(BadRequest("Zadejte obsah komentáře."));
            }

            model.NewComment.Created = DateTime.Now;
            model.NewComment.User    = await userManager.GetUserAsync(User);

            await commentsRepository.CreateAsync(model.NewComment);

            return(Json(model.NewComment));
        }
Beispiel #4
0
        public async Task <Comment> CreateAsync(Comment comment)
        {
            var user = await userService.GetUserAsync();

            if (await commentsAuthorizationService.ItemMayBeCreatedAsync(user, comment))
            {
                comment.SubmittedOn = DateTime.Now;
                comment.UserName    = user.Identity.Name;
                return(await repository.CreateAsync(comment));
            }
            else
            {
                throw new UnauthorizedCreateAttemptException <Comment>($"Unauthorized Create Attempt of Comment {comment.Id}");
            }
        }
Beispiel #5
0
        public async Task <Unit> Handle(CreateCommentCommand request, CancellationToken cancellationToken)
        {
            string          username = request.NewComment.Username;
            int?            userId   = null;
            ClaimsPrincipal user     = _httpContextAccessor.HttpContext.User;

            if (user.Identity.IsAuthenticated)
            {
                username = user.FindFirst(ClaimTypes.Name).Value;
                userId   = int.Parse(user.FindFirst("id").Value);
            }
            var comment = new Comment
            {
                PostId   = request.NewComment.PostId,
                Content  = request.NewComment.Content,
                Username = username,
                UserId   = userId
            };
            await _commentsRepository.CreateAsync(comment);

            return(Unit.Value);
        }
 public async Task <Comment> CreateAsync(Comment comment) => await repository.CreateAsync(comment);
 public async Task <Comment> CreateAsync(Comment comment)
 {
     comment.SubmittedOn = DateTime.Now;
     comment.UserName ??= "";
     return(await repository.CreateAsync(comment));
 }