public async Task <IActionResult> GenerateEmail(GenerateEmailViewModel model) { try { var emailGenerator = (Types.Email.EmailGenerator)HttpContext.RequestServices.GetService(typeof(Types.Email.EmailGenerator)); var report = await _mediator.Request <GetReportById, ReportViewModel>(new GetReportById(model.Id)); var profile = await _mediator.Request <GetProfileById, ProfileViewModel>(new GetProfileById(report.ProfileId)); var vstsConfig = await _mediator.Request <GetVstsDataSourceConfiguration, VstsDataSourceViewModel>(new GetVstsDataSourceConfiguration()); if (report.ReportType == "WorkitemsReporter") { var email = await emailGenerator.Generate(profile, report as WorkItemsReportViewModel, model, vstsConfig); return(Ok(email)); } throw new NotSupportedException($"Report of type '{report.ReportType}' is not supported."); } catch (Exception ex) { _logger.LogError(ex, "Error generating email for report."); throw; } }
public async Task <byte[]> GenerateEmail(GenerateEmailViewModel model) { var url = $"{GetApiUrl()}report/generateemail"; return(await HttpPost <byte[]>(url, model)); }
public Task <byte[]> Generate(ProfileViewModel profile, WorkItemsReportViewModel report, GenerateEmailViewModel model, VstsDataSourceViewModel vstsConfig) { _logger.LogInformation("Requesting email for {ProfileId} - {ProfileName}"); var reportExt = new Report(); reportExt.Active.AddRange(report.ActiveWorkItems.Select(w => new WorkItem() { Id = w.WorkItemId, Url = GetWorkItemUrl(vstsConfig, w.WorkItemProject, w.WorkItemId), Title = w.WorkItemTitle, Type = w.WorkItemType, Estimated = (int)w.EstimatedToComplete, Spent = (int)w.TimeSpent })); reportExt.Completed.AddRange(report.ResolvedWorkItems.Select(w => new WorkItem() { Id = w.WorkItemId, Url = GetWorkItemUrl(vstsConfig, w.WorkItemProject, w.WorkItemId), Title = w.WorkItemTitle, Type = w.WorkItemType, Estimated = (int)w.EstimatedToComplete, Spent = (int)w.TimeSpent })); reportExt.Inreview.AddRange(report.WorkItemsInReview.Select(w => new WorkItem() { Id = w.WorkItemId, Url = GetWorkItemUrl(vstsConfig, w.WorkItemProject, w.WorkItemId), Title = w.WorkItemTitle, Type = w.WorkItemType, Estimated = (int)w.EstimatedToComplete, Spent = (int)w.TimeSpent })); var request = new EmailRequest { Id = report.Id.ToString(), Name = report.ProfileName, Report = reportExt, Template = new EmailTemplate { Subject = profile.EmailSubject, Body = profile.EmailBody }, Points = model.Points, }; request.Attendance.AddRange(model.Attendance.Select(a => { var attendance = new TeamAttendance { Name = a.MemberName }; attendance.Attendance.AddRange(a.Attendance.Select(ma => ma)); return(attendance); })); var reply = _client.Generate(request); return(Task.FromResult(reply.File.ToByteArray())); }