| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- namespace Diligent.WebAPI.Business.Services
- {
- public class CommentService : ICommentService
- {
- private readonly FrontEndSettings _frontEndSettings;
- private readonly DatabaseContext _context;
- private readonly IMapper _mapper;
- private readonly ILogger<CommentService> _logger;
- private readonly IEmailer _emailer;
-
- public CommentService(IOptions<FrontEndSettings> frontEndSettings,DatabaseContext context, IMapper mapper, ILogger<CommentService> logger,IEmailer emailer)
- {
- _frontEndSettings = frontEndSettings.Value;
- _context = context;
- _mapper = mapper;
- _logger = logger;
- _emailer = emailer;
- }
- public async Task CreateComment(CommentCreateDto commentCreateDto)
- {
- _logger.LogInformation("Start creating comment");
- var comment = _mapper.Map<Comment>(commentCreateDto);
-
- if(commentCreateDto.UsersToNotify.Count > 0)
- {
- _logger.LogInformation("Start sending emails");
- await _emailer.SendEmailAsync(commentCreateDto.UsersToNotify, "You're tagged in comment by another user",
- HTMLHelper.RenderTagPage($"{_frontEndSettings.BaseUrl}/candidates/{commentCreateDto.ApplicantId}"), isHtml: true);
- _logger.LogInformation("Emails send successfully");
- }
-
- comment.DateOfSending = DateTime.Now;
- _logger.LogInformation($"Comment created successfully in {comment.DateOfSending}");
-
- _logger.LogInformation($"Saving comment in Db");
- await _context.Comments.AddAsync(comment);
- var result = _context.SaveChangesAsync();
- _logger.LogInformation($"Comment saved in Db");
- await result;
- }
- }
- }
|