I am trying to develop a notification feature and would like to use messages templates for the notifications.
I do have a table which stores those events and who are the subjects and objects of the message.
However, I am lacking a means to show the message templates to the users.
I know I can store the final messages as TEXT in the database but I was wondering if there is a way to store the template some how and merge that template with the data to make it easier for future updates as and when there are new templates or template changes.
What I have tried:
I am currently using the ASP.NET MVC model for the notifications page so only the properties are seen for now.
Index.cshtml
...
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateTime)
</td>
<td>
@Html.DisplayFor(modelItem => item.Types)
</td>
<td>
@Html.DisplayFor(modelItem => item.Subject)
</td>
<td>
@Html.DisplayFor(modelItem => item.Object)
</td>
<td>
@Html.DisplayFor(modelItem => item.Status)
</td>
<td>
@Html.ActionLink("Details", "Details", new { id = item.Id })
</td>
</tr>
}
...
NotificationController.cs
public async Task<ActionResult> Index()
{
String UserId = HttpContext.User.Identity.GetUserId();
var notifications = db.notifications.Where(n => n.UserId == UserId);
return View(await notifications.ToListAsync());
}