public async Task <ActionResult> Editor(string name, MosaicoTemplate template, int id = 0) { MosaicoEmail model; if (id > 0) { using (var context = new ApplicationDbContext()) { model = await context.MosaicoEmails.FirstOrDefaultAsync(x => x.Id == id); } } else { model = new MosaicoEmail { Name = name, Template = template }; } ViewBag.Title = "Mosaico Editor"; // TODO: Add your own tokens here ViewBag.FieldTokens = new Dictionary <string, string> { { "Title", "Title" }, { "FirstName", "First Name" }, { "LastName", "Last Name" }, }; return(View(model)); }
public async Task <ActionResult> Save( int id, string name, MosaicoTemplate template, string metadata, string content, string html) { try { using (var context = new ApplicationDbContext()) { var record = await context.MosaicoEmails.FindAsync(id); bool isNew = (record == null); if (isNew) { record = new MosaicoEmail(); } record.Name = name; record.Template = template; record.Metadata = metadata; record.Content = content; // Save the HTML so we can use it for mass emailing. Example: User will input tokens like {FirstName}, {LastName}, etc into the template, // then we can do a search and replace with regex when sending emails (Your own logic, somewhere in your app). record.Html = html; if (isNew) { context.MosaicoEmails.Add(record); } else { context.MosaicoEmails.Attach(record); } await context.SaveChangesAsync(); } return(Json(new { success = true, message = "Sucessfully saved email." })); } catch (Exception x) { return(Json(new { success = false, message = x.GetBaseException().Message })); } }