public async Task <IActionResult> SendReminderEmailForAllEvents( [FromQuery] PagingOptions pagingOptions, [FromQuery] SortOptions <Event, EventEntity> sortOptions, [FromQuery] SearchOptions <Event, EventEntity> searchOptions, CancellationToken ct) { pagingOptions.Offset = pagingOptions.Offset ?? _defaultPagingOptions.Offset; pagingOptions.Limit = pagingOptions.Limit ?? _defaultPagingOptions.Limit; var events = await _event.GetAllAsync(pagingOptions, sortOptions, searchOptions, ct); foreach (var @event in events.Items) { foreach (var participant in @event.Participant.Where(x => !x.IsFeedbackReceived)) { var feedbackType = participant.Attended ? "participated" : participant.NotAttended ? "notparticipated" : "unregistered"; var emailModel = new FeedbackRequestEmailTemplateModel { EventName = @event.EventName, EventDate = @event.EventDate.ToShortDateString(), ParticipantName = participant.EmployeeName, FeedbackUrl = $"{_configuration.GetSection("EmailUrl").Value}/feedback/{feedbackType}/{@event.Id}/{participant.Id}" }; var body = await _renderer.RenderPartialToStringAsync("_FeedbackRequestEmailPartial", emailModel); await _emailService.SendAsync(User.Identity.Name, "Admin", participant.EmployeeId, $"Feedback Requested for {@event.EventName} at {@event.EventDate}", body); } } return(Ok()); }
public async Task <IActionResult> CreateReminderEmail([FromBody] ReminderEmailForm form) { var userId = await _user.GetUserIdAsync(User); if (userId == null) { return(NotFound()); } var @event = await _event.FindAsync(form.EventId, CancellationToken.None); foreach (var participant in @event.Participant.Where(x => !x.IsFeedbackReceived)) { var feedbackType = participant.Attended ? "participated" : participant.NotAttended ? "notparticipated" : "unregistered"; var emailModel = new FeedbackRequestEmailTemplateModel { EventName = @event.EventName, EventDate = @event.EventDate.ToShortDateString(), ParticipantName = participant.EmployeeName, FeedbackUrl = $"{_configuration.GetSection("EmailUrl").Value}/feedback/{feedbackType}/{@event.Id}/{participant.Id}" }; var body = await _renderer.RenderPartialToStringAsync("_FeedbackRequestEmailPartial", emailModel); await _emailService.SendAsync(User.Identity.Name, "Admin", participant.EmployeeId, $"Feedback Requested for {@event.EventName} at {@event.EventDate}", body); } return(Ok()); }