public ModuleRequirements() { Domain = new DomainModel(); UIDefinitions = new UIDefinition[0]; RequredModules = new int[0]; Templates = new HtmlTemplate[0]; }
public object Save(HtmlTemplate template) { if (_securityService.CurrentUser.UserType != Core.Domain.UserTypes.Admin) throw new Exception("Only admins can edit UI texts."); _templateService.Save(template); return new { success = true }; }
public void Test_Template_Render() { var jordan = new Author() { FirstName = "Robert", LastName = "Jordan", IsAlive = false, Born = new DateTime(1948, 10, 17), Rating = 10.0m }; var feist = new Author() { FirstName = "Raymond", LastName = "Feist", IsAlive = true, Born = new DateTime(1963, 2, 14), Rating = 6.7m }; var svc = getSvc(); var tmpl = "<h2>{Favorite.Firstname} is my favorite author</h2><p>You can check <a href=\"google.com/search?q={Favorite.lastname}\">{Favorite.FirstNAME}'s books</a>, though I also like {SecondFavorite.FirstName} {SecondFavorite.Lastname}, born on {SecondFavorite.born}.</p>"; var subj = "About this {Favorite.lastname} author"; var exp = "<h2>Raymond is my favorite author</h2><p>You can check <a href=\"google.com/search?q=Feist\">Raymond's books</a>, though I also like Robert Jordan, born on 17/10/1948.</p>"; var expSubj = "About this Feist author"; var template = new HtmlTemplate() { Id = Guid.NewGuid(), Name = "Test 2", BodyTemplate = tmpl, SubjectTemplate = subj }; svc.Save(template); var tmplContext = new Dictionary<string, Entity>(); tmplContext.Add("Favorite", feist); tmplContext.Add("SecondFavorite", jordan); string body = null, subject = null; svc.Render(template, tmplContext, out subject, out body); Assert.AreEqual(exp, body); Assert.AreEqual(expSubj, subject); }
public void Test_Template_Save() { var svc = getSvc(); var template = new HtmlTemplate() { Id = Guid.NewGuid(), Name = "Test 1", SubjectTemplate = "About...", BodyTemplate = "Plain text template." }; svc.Save(template); var ret = svc.Get(template.Id); Assert.IsNotNull(ret); Assert.AreEqual(template.Id, ret.Id); Assert.AreEqual(template.Name, ret.Name); Assert.AreEqual(template.BodyTemplate, ret.BodyTemplate); Assert.AreEqual(template.SubjectTemplate, ret.SubjectTemplate); template.SubjectTemplate = template.SubjectTemplate + "_edit"; template.BodyTemplate = template.BodyTemplate + "_edit"; svc.Save(template); ret = svc.Get(template.Id); Assert.IsNotNull(ret); Assert.AreEqual(template.Id, ret.Id); Assert.AreEqual(template.Name, ret.Name); Assert.AreEqual(template.BodyTemplate, ret.BodyTemplate); Assert.AreEqual(template.SubjectTemplate, ret.SubjectTemplate); }