private string LoadTemplates(string layout) { var regex = new Regex(@"{\s*\""template""\s*:\s*[0-9]\s*}"); var regexId = new Regex(@"[0-9]+"); var matches = regex.Matches(layout); foreach (var match in matches) { try { var ids = regexId.Matches(match.ToString()).FirstOrDefault(); if (int.TryParse(ids.Value.FirstOrDefault().ToString(), out int templateId)) { TemplateViewModel temp = _TemplateAppService.GetById(templateId); if (temp != null) { layout = layout.Replace(match.ToString(), JsonConvert.SerializeObject(temp.Json)); } } } catch (Exception ex) { } } return(layout); }
public async Task <IActionResult> GetById(int id) { try { var result = _TemplateAppService.GetById(id); return(await Response(result, null)); } catch (Exception ex) { return(await Response(null, new List <Notification> { new Notification("Template", ex.Message) })); } }