Skip to content

Commit 7306b96

Browse files
authored
Merge pull request #1255 from bcgov/dev
Dev
2 parents c2696c9 + 077d681 commit 7306b96

29 files changed

Lines changed: 4161 additions & 71 deletions

File tree

applications/Unity.GrantManager/modules/Unity.Notifications/src/Unity.Notifications.Application/Templates/ITemplatesService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ public interface ITemplateService : IApplicationService
1212
Task<List<EmailTemplate>> GetTemplatesByTenent();
1313
Task<EmailTemplate?> GetTemplateById(Guid id);
1414
Task DeleteTemplate(Guid id);
15+
Task<EmailTemplate?> GetTemplateByName(string name);
16+
17+
Task<List<TemplateVariable>> GetTemplateVariables();
1518
}
1619
}

applications/Unity.GrantManager/modules/Unity.Notifications/src/Unity.Notifications.Application/Templates/TemplatesService.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ public class TemplateService : ApplicationService, ITemplateService
1515

1616
private readonly ITemplatesRepository _templatesRepository;
1717
private readonly ICurrentTenant _currentTenant;
18+
private readonly ITemplateVariablesRepository _templateVariablesRepository;
1819

1920

2021
public TemplateService(
2122
ITemplatesRepository templatesRepository,
22-
ICurrentTenant currentTenant
23+
ICurrentTenant currentTenant,
24+
ITemplateVariablesRepository templateVariablesRepository
2325

2426
)
2527
{
2628
_templatesRepository = templatesRepository;
2729
_currentTenant = currentTenant;
30+
_templateVariablesRepository = templateVariablesRepository;
2831
}
2932

3033
public async Task<EmailTemplate?> CreateAsync(EmailTempateDto templateDto)
@@ -70,4 +73,15 @@ public async Task DeleteTemplate(Guid id)
7073
{
7174
await _templatesRepository.DeleteAsync(id);
7275
}
76+
public async Task<EmailTemplate?> GetTemplateByName(string name)
77+
{
78+
var data = await _templatesRepository.GetByNameAsync(name);
79+
return data;
80+
}
81+
82+
public async Task<List<TemplateVariable>> GetTemplateVariables()
83+
{
84+
var data = await _templateVariablesRepository.GetListAsync();
85+
return data;
86+
}
7387
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
using Unity.Notifications.Templates;
4+
using Volo.Abp.Data;
5+
using Volo.Abp.DependencyInjection;
6+
7+
namespace Unity.Notifications;
8+
9+
public class NotificationsDataSeedContributor : IDataSeedContributor, ITransientDependency
10+
{
11+
private readonly ITemplateVariablesRepository _templateVariablesRepository;
12+
13+
public NotificationsDataSeedContributor(ITemplateVariablesRepository templateVariablesRepository)
14+
{
15+
16+
_templateVariablesRepository = templateVariablesRepository;
17+
}
18+
19+
public async Task SeedAsync(DataSeedContext context)
20+
{
21+
var EmailTempateVariableDtos = new List<EmailTempateVariableDto>
22+
{
23+
new EmailTempateVariableDto { Name = "Applicant name", Token = "applicant_name", MapTo = "applicant.applicantName" },
24+
new EmailTempateVariableDto { Name = "Submission #", Token = "submission_number", MapTo = "referenceNo" },
25+
new EmailTempateVariableDto { Name = "Submission Date", Token = "submission_date", MapTo = "submissionDate" },
26+
new EmailTempateVariableDto { Name = "Category", Token = "category", MapTo = "category" },
27+
new EmailTempateVariableDto { Name = "Status", Token = "status", MapTo = "status" },
28+
new EmailTempateVariableDto { Name = "Approved Amount", Token = "approved_amount", MapTo = "approvedAmount" },
29+
new EmailTempateVariableDto { Name = "Approval date", Token = "approval_date", MapTo = "finalDecisionDate" },
30+
new EmailTempateVariableDto { Name = "Community", Token = "community", MapTo = "community" },
31+
new EmailTempateVariableDto { Name = "Contact Full Name", Token = "contact_full_name", MapTo = "contactFullName" },
32+
new EmailTempateVariableDto { Name = "Contact Title", Token = "contact_title", MapTo = "contactTitle" },
33+
new EmailTempateVariableDto { Name = "Decline Rationale", Token = "decline_rationale", MapTo = "declineRational" },
34+
new EmailTempateVariableDto { Name = "Registered Organization Name", Token = "organization_name", MapTo = "organizationName" },
35+
new EmailTempateVariableDto { Name = "Project Start Date", Token = "project_start_date", MapTo = "projectStartDate" },
36+
new EmailTempateVariableDto { Name = "Project End Date", Token = "project_end_date", MapTo = "projectEndDate" },
37+
new EmailTempateVariableDto { Name = "Project Name", Token = "project_name", MapTo = "projectName" },
38+
new EmailTempateVariableDto { Name = "Project Summary", Token = "project_summary", MapTo = "projectSummary" },
39+
new EmailTempateVariableDto { Name = "Signing Authority Full Name", Token = "signing_authority_full_name", MapTo = "signingAuthorityFullName" },
40+
new EmailTempateVariableDto { Name = "Signing Authority Title", Token = "signing_authority_title", MapTo = "signingAuthorityTitle" }
41+
};
42+
43+
if (context.TenantId != null) // only try seed into a tenant database
44+
{
45+
foreach (var template in EmailTempateVariableDtos)
46+
{
47+
await _templateVariablesRepository.InsertAsync(new TemplateVariable { Name = template.Name, Token = template.Token, MapTo = template.MapTo }, autoSave: true);
48+
}
49+
}
50+
51+
}
52+
}
53+
54+
internal class EmailTempateVariableDto
55+
{
56+
public string Name { get; set; } = string.Empty;
57+
public string Token { get; set; } = string.Empty;
58+
public string MapTo { get; set; } = string.Empty;
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using Volo.Abp.Domain.Repositories;
3+
4+
namespace Unity.Notifications.Templates
5+
{
6+
public interface ITemplateVariablesRepository : IRepository<TemplateVariable, Guid>
7+
{
8+
9+
}
10+
}

applications/Unity.GrantManager/modules/Unity.Notifications/src/Unity.Notifications.Domain/Templates/ITemplatesRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ public interface ITemplatesRepository : IBasicRepository<EmailTemplate, Guid>
99
{
1010
Task<EmailTemplate?> GetByIdAsync(Guid id, bool includeDetails = false);
1111
Task<List<EmailTemplate>> GetByTenentIdAsync(Guid? tenentId);
12+
Task<EmailTemplate?> GetByNameAsync(string name);
1213
}
1314
}

applications/Unity.GrantManager/modules/Unity.Notifications/src/Unity.Notifications.Domain/Templates/TemplateVariable.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ namespace Unity.Notifications.Templates;
66

77
public class TemplateVariable : AuditedAggregateRoot<Guid>, IMultiTenant
88
{
9-
protected TemplateVariable()
10-
{
11-
/* This constructor is for ORMs to be used while getting the entity from the database. */
12-
}
139

1410
public Guid? TenantId { get; set; }
1511

1612
public string Name { get; set; } = string.Empty;
17-
public bool Active { get; set; } = true;
18-
public string InternalName { get; set; } = string.Empty;
13+
public string Token { get; set; } = string.Empty;
14+
public string MapTo { get; set; } = string.Empty;
15+
1916
}

applications/Unity.GrantManager/modules/Unity.Notifications/src/Unity.Notifications.EntityFrameworkCore/EntityFrameworkCore/INotificationsDbContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ public interface INotificationsDbContext : IEfCoreDbContext
1111
{
1212
// Add DbSet for each Aggregate Root here.
1313
public DbSet<EmailLog> EmailLogs { get; set; }
14-
public DbSet<EmailTemplate> EmailTemplates { get; set; }
14+
public DbSet<EmailTemplate> EmailTemplates { get; set; }
15+
public DbSet<TemplateVariable> TemplateVariables { get; set; }
1516
}

applications/Unity.GrantManager/modules/Unity.Notifications/src/Unity.Notifications.EntityFrameworkCore/EntityFrameworkCore/NotificationsDbContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class NotificationsDbContext : AbpDbContext<NotificationsDbContext>, INot
1111
{
1212
public DbSet<EmailLog> EmailLogs { get; set; }
1313
public DbSet<EmailTemplate> EmailTemplates { get; set; }
14+
public DbSet<TemplateVariable> TemplateVariables { get; set; }
1415

1516
// Add DbSet for each Aggregate Root here.
1617
public NotificationsDbContext(DbContextOptions<NotificationsDbContext> options)

applications/Unity.GrantManager/modules/Unity.Notifications/src/Unity.Notifications.EntityFrameworkCore/EntityFrameworkCore/NotificationsDbContextModelCreatingExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,12 @@ public static void ConfigureNotifications(
8989
.WithMany()
9090
.HasForeignKey(ts => ts.SubscriptionGroupId);
9191
});
92+
modelBuilder.Entity<TemplateVariable>(b =>
93+
{
94+
b.ToTable(NotificationsDbProperties.DbTablePrefix + "TemplateVariables",
95+
NotificationsDbProperties.DbSchema);
96+
97+
b.ConfigureByConvention();
98+
});
9299
}
93100
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using Unity.Notifications.EntityFrameworkCore;
3+
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
4+
using Volo.Abp.EntityFrameworkCore;
5+
using Unity.Notifications.Templates;
6+
7+
8+
9+
10+
namespace Unity.Notifications.Repositories
11+
{
12+
public class TemplateVariablesRepository : EfCoreRepository<NotificationsDbContext, TemplateVariable, Guid>, ITemplateVariablesRepository
13+
{
14+
public TemplateVariablesRepository(IDbContextProvider<NotificationsDbContext> dbContextProvider) : base(dbContextProvider)
15+
{
16+
}
17+
18+
19+
}
20+
}

0 commit comments

Comments
 (0)