public static string PageTitle <TModel>(this HtmlHelper <TModel> htmlHelper, params string[] items) where TModel : OxiteModel { OxiteModel model = htmlHelper.ViewData.Model; if (items == null || items.Length == 0) { return(model.Site.DisplayName); } StringBuilder sb = new StringBuilder(50); List <string> itemList = new List <string>(items); itemList.RemoveAll(s => s == null); itemList.Insert(0, model.Site.DisplayName); for (int i = itemList.Count - 1; i >= 0; i--) { sb.Append(itemList[i]); if (i > 0) { sb.Append(model.Site.PageTitleSeparator); } } return(htmlHelper.Encode(sb.ToString())); }
public void OnActionExecuted(ActionExecutedContext filterContext) { OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel; if (model != null) { string areaName = filterContext.RouteData.Values["areaName"] as string; Area area = !string.IsNullOrEmpty(areaName) ? areaService.GetArea(areaName) : null; Post post = null; List <Post> posts = new List <Post>(); if (area != null && string.Compare(area.Name, "IE8", true) == 0) { posts.AddRange(postService.GetPosts(0, 50, area, (DateTime?)null)); } if (area != null && string.Compare(area.Name, "MIX09", true) == 0) { post = postService.GetPosts(0, 1, area, (DateTime?)null).FirstOrDefault(); } else { post = postService.GetRandomPost(); } model.AddModelItem(new SidebarViewModel(post, posts)); } }
private void setLocalization(OxiteModel model) { if (model != null) { model.AddModelItem(locService.GetTranslations()); } }
public void OnActionExecuted(ActionExecutedContext filterContext) { OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel; if (model == null) { return; } IList <KeyValuePair <ArchiveData, int> > archives; string areaName = filterContext.RouteData.Values["areaName"] as string; INamedEntity container; if (!string.IsNullOrEmpty(areaName)) { archives = postService.GetArchives(new Area { Name = areaName }); container = areaService.GetArea(areaName); } else { archives = postService.GetArchives(); container = new HomePageContainer(); } model.AddModelItem(new ArchiveViewModel(archives, container)); }
private void setModel(OxiteModel model) { if (model != null) { model.Site = new SiteViewModel(site, appSettings.GetString("SiteName", "Oxite")); } }
public void OnActionExecuted(ActionExecutedContext filterContext) { OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel; if (model != null) { model.AntiForgeryToken = new AntiForgeryToken(site.ID.ToString()); } }
public void OnActionExecuted(ActionExecutedContext filterContext) { OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel; if (model != null) { model.AddModelItem(new AreaListViewModel(areaService.GetAreas())); } }
public static string Gravatar(this HtmlHelper htmlHelper, OxiteModel model, UserBase user, string size) { return(htmlHelper.Gravatar( user != null ? user.HashedEmail.CleanAttribute() : null, user != null ? (user.DisplayName ?? user.Name).CleanAttribute() : null, size, model.Site.GravatarDefault )); }
public void OnActionExecuted(ActionExecutedContext filterContext) { OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel; if (model != null) { model.Site = new SiteViewModel(site, appSettings.GetString("SiteName", "Oxite")); } }
public void SignInSetsContainerToSignIn() { UserController controller = new UserController(null, null); OxiteModel result = controller.SignIn(); Assert.NotNull(result); Assert.IsType <SignInPageContainer>(result.Container); }
public void OnActionExecuted(ActionExecutedContext filterContext) { OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel; if (model == null) { return; } model.AddModelItem(new PageListViewModel(pageService.GetPages())); }
public static void RenderOpenSearch <TModel>(this HtmlHelper <TModel> htmlHelper) where TModel : OxiteModel { OxiteModel model = htmlHelper.ViewData.Model; if (model.Site.IncludeOpenSearch) { UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext); htmlHelper.ViewContext.HttpContext.Response.Write(htmlHelper.HeadLink("search", urlHelper.AbsolutePath(urlHelper.OpenSearch()), "application/opensearchdescription+xml", string.Format(model.Localize("SearchFormat", "{0} Search"), model.Site.DisplayName))); } }
public static string OxiteAntiForgeryToken <TModel>(this HtmlHelper <TModel> htmlHelper, Func <TModel, OxiteModel> getRootModel) where TModel : class { OxiteModel rootModel = getRootModel(htmlHelper.ViewData.Model); if (rootModel != null) { return(htmlHelper.AntiForgeryToken(rootModel.Site.ID.ToString())); } return(""); }
public static void RenderFavIcon <TModel>(this HtmlHelper <TModel> htmlHelper) where TModel : OxiteModel { OxiteModel model = htmlHelper.ViewData.Model; if (!string.IsNullOrEmpty(model.Site.FavIconUrl)) { UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext); htmlHelper.ViewContext.HttpContext.Response.Write(htmlHelper.HeadLink("shortcut icon", urlHelper.AppPath(model.Site.FavIconUrl), null, null)); } }
public static string Gravatar <TModel>(this HtmlHelper <TModel> htmlHelper, UserBase user, string size) where TModel : OxiteModel { OxiteModel model = htmlHelper.ViewData.Model; return(htmlHelper.Gravatar( user != null ? user.HashedEmail.CleanAttribute() : null, user != null ? (user.DisplayName ?? user.Name).CleanAttribute() : null, size, model.Site.GravatarDefault )); }
public void OnActionExecuted(ActionExecutedContext filterContext) { OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel; if (model == null) { return; } model.AddModelItem(new TagCloudViewModel(tagService.GetTagsWithPostCount())); }
public void AddModelItemThenGetModelItemReturnsItem() { OxiteModel model = new OxiteModel(); OxiteModelTests modelItem = new OxiteModelTests(); model.AddModelItem(modelItem); var actualItem = model.GetModelItem <OxiteModelTests>(); Assert.Same(modelItem, actualItem); }
public static string OpenSearchOSDXLink <TModel>(this HtmlHelper <TModel> htmlHelper) where TModel : OxiteModel { OxiteModel model = htmlHelper.ViewData.Model; if (model.Site.IncludeOpenSearch && htmlHelper.ViewContext.HttpContext.Request.UserAgent.Contains("Windows NT 6.1")) { UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext); return(htmlHelper.Link(string.Format(model.Localize("Search.WindowsSearch", "Search {0} in Windows"), model.Site.DisplayName), urlHelper.AppPath(urlHelper.OpenSearchOSDX()), new { @class = "windowsSearch" })); } return(""); }
public void OnActionExecuted(ActionExecutedContext filterContext) { ViewResult result = filterContext.Result as ViewResult; if (result != null) { OxiteModel model = result.ViewData.Model as OxiteModel; if (model != null) { model.AddModelItem(locService.GetTranslations()); } } }
public void OnActionExecuted(ActionExecutedContext filterContext) { OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel; if (model != null) { UserBase user = filterContext.HttpContext.User.Identity.IsAuthenticated ? userService.GetUser(filterContext.HttpContext.User.Identity.Name) : filterContext.HttpContext.Request.Cookies.GetAnonymousUser(); if (user != null) { model.User = new UserViewModel(user); } } }
public static string Published <TModel>(this HtmlHelper <TModel> htmlHelper, Post post) where TModel : OxiteModel { OxiteModel model = htmlHelper.ViewData.Model; if (post.State == EntityState.Removed) { return(model.Localize("Removed")); } if (post.Published.HasValue) { return(ConvertToLocalTime(htmlHelper, post.Published.Value, htmlHelper.ViewData.Model).ToLongDateString()); } return(model.Localize("Draft")); }
public void OnActionExecuted(ActionExecutedContext filterContext) { OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel; if (model != null) { //recent posts - all up IList <Post> posts = postService.GetPostsWithDrafts(0, 5); //recent comments - all up IList <ParentAndChild <PostBase, Comment> > comments = postService.GetComments(0, 10, true, true); IList <Area> areas = areaService.GetAreas(); model.AddModelItem(new AdminDataViewModel(posts, comments, areas)); } }
public void OnActionExecutedAddsAllPhrasesToModel() { FakeLocalizationService locService = new FakeLocalizationService(); OxiteModel model = new OxiteModel(); ActionExecutedContext context = new ActionExecutedContext() { Result = new ViewResult() { ViewData = new ViewDataDictionary(model) } }; LocalizationActionFilter filter = new LocalizationActionFilter(locService); filter.OnActionExecuted(context); Assert.NotNull(model.GetModelItem<ICollection<Phrase>>()); Assert.Same(locService.Phrases, model.GetModelItem<ICollection<Phrase>>()); }
public void OnActionExecuted(ActionExecutedContext filterContext) { OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel; if (model != null) { string areaName = filterContext.RouteData.Values["areaName"] as string; if (areaName != null) { Area area = areaService.GetArea(areaName); model.AddModelItem(new TagCloudViewModel(tagService.GetTagsUsedIn(area))); } else { model.AddModelItem(new TagCloudViewModel(tagService.GetTagsWithPostCount())); } } }
public static DateTime ConvertToLocalTime(this HtmlHelper htmlHelper, DateTime dateTime, OxiteModel model) { if (model.User == null) { if (model.Site.TimeZoneOffset != 0) { return(dateTime.Add(TimeSpan.FromHours(model.Site.TimeZoneOffset))); } return(dateTime); } return(dateTime); //TODO: (erikpo) Get the timezone offset from the current user and apply it }
public void GetModelReturnsNullIfNotFound() { OxiteModel model = new OxiteModel(); Assert.Null(model.GetModelItem <OxiteModelTests>()); }
public OxiteModelPartial(OxiteModel rootModel, T partialModel) { RootModel = rootModel; PartialModel = partialModel; }
public static string TextBoxWithValidation <TModel>(this HtmlHelper <TModel> htmlHelper, string validationKey, string name, object value, object htmlAttributes) where TModel : OxiteModel { OxiteModel model = htmlHelper.ViewData.Model; return(htmlHelper.TextBox(name, value, htmlAttributes) + htmlHelper.ValidationMessage(validationKey, model.Localize(validationKey))); }