Esempio n. 1
0
        public async Task <IActionResult> AddComment([FromBody] CommentView result)
        {
            if (!ModelState.IsValid)
            {
                // wysyłamy informacje o błędach
                return(BadRequest(ModelState));
            }

            var settings = await _settingsService.GetBlogSettings();

            var article = await _articleService.Get(result.ArticleId);

            var comment = await _commentService.Create(CommentHelpers.ConvertToModel(result, article));

            if (comment)
            {
                var notification = new NotificationData($"Wpadł Ci nowy komentarz od {result.Name} | {result.Email}");
                _notificationService.Send(notification);

                if (settings.CommentsNotify)
                {
                    _emailService.SendCommentConfirmation(result);
                }

                return(Ok(new { status = "Komentarz zapisany pomyślnie" }));
            }
            else
            {
                return(BadRequest(new { status = "Problem z zapisem komentarza" }));
            }
        }