Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. namespace Diligent.WebAPI.Business.Services
  2. {
  3. public class CommentService : ICommentService
  4. {
  5. private readonly FrontEndSettings _frontEndSettings;
  6. private readonly DatabaseContext _context;
  7. private readonly IMapper _mapper;
  8. private readonly ILogger<CommentService> _logger;
  9. private readonly IEmailer _emailer;
  10. public CommentService(IOptions<FrontEndSettings> frontEndSettings,DatabaseContext context, IMapper mapper, ILogger<CommentService> logger,IEmailer emailer)
  11. {
  12. _frontEndSettings = frontEndSettings.Value;
  13. _context = context;
  14. _mapper = mapper;
  15. _logger = logger;
  16. _emailer = emailer;
  17. }
  18. public async Task CreateComment(CommentCreateDto commentCreateDto)
  19. {
  20. _logger.LogInformation("Start creating comment");
  21. var comment = _mapper.Map<Comment>(commentCreateDto);
  22. if(commentCreateDto.UsersToNotify.Count > 0)
  23. {
  24. _logger.LogInformation("Start sending emails");
  25. await _emailer.SendEmailAsync(commentCreateDto.UsersToNotify, "You're tagged in comment by another user",
  26. HTMLHelper.RenderTagPage($"{_frontEndSettings.BaseUrl}/candidates/{commentCreateDto.ApplicantId}"), isHtml: true);
  27. _logger.LogInformation("Emails send successfully");
  28. }
  29. comment.DateOfSending = DateTime.Now;
  30. _logger.LogInformation($"Comment created successfully in {comment.DateOfSending}");
  31. _logger.LogInformation($"Saving comment in Db");
  32. await _context.Comments.AddAsync(comment);
  33. var result = _context.SaveChangesAsync();
  34. _logger.LogInformation($"Comment saved in Db");
  35. await result;
  36. }
  37. }
  38. }