public string FormatMessage(IList <NotificationEntry> items) { if (string.IsNullOrEmpty(Template)) { return(string.Empty); } var tableBuilder = new HTMLTableBuilder <NotificationEntry>(); var table = tableBuilder.Build(TableTitle, new string[] { "URL", "Action", "Code", "Description", "Due date", "Start date", "End date" }, items, (item, tb) => { tb.AddCell("", item.URL, item.ID.ToString()); tb.AddCell(item.ExpectedAction); tb.AddCell(item.Code); tb.AddCell(item.Description); tb.AddCell(item.Duedate); tb.AddCell(item.Startdate); tb.AddCell(item.Enddate); } ); var message = Template; message = message .Replace("{TableTitle}", TableTitle) .Replace("{Items}", table) .Replace("{Salutation}", Salutation); return(message); }
/// <summary> /// Utility method to create a HTML table in one function call /// </summary> /// <param name="title">Title of the table</param> /// <param name="columntitles">string array with the names of the column headers</param> /// <param name="list">IEnumerable list of items to put in the table</param> /// <param name="filler">Delegate of lambda that fills each line of the table. Do this by calling AddCell on the ht parameter, using the item that is passed in the delegate/lambda</param> /// <returns>The HTML table as a string</returns> public string Build(string title, string[] columntitles, IEnumerable <TListItem> list, Action <TListItem, HTMLTableBuilder <TListItem> > filler) { HTMLTableBuilder <TListItem> ht = this; ht.TableTitle(title); ht.StartTable(); ht.OpenHeader(); foreach (var item in columntitles) { ht.AddHeader(item); } ht.CloseHeader(); foreach (var item in list) { ht.OpenLine(); filler(item, ht); ht.CloseLine(); } ht.CloseTable(); return(ht.GetHTML()); }