public static MvcHtmlString SiteMenu(this HtmlHelper helper, Tenant currentTenant) { ILinkService linkService = DependencyResolver.Current.GetService<ILinkService>(); if (currentTenant == null || linkService == null) { return null; } TagBuilder itemTag; IList<Link> menuItems = linkService.GetMenuLinks(currentTenant.Id.ToString()); TagBuilder menu = new TagBuilder("ul"); menu.MergeAttribute("id", "menu"); foreach (Link item in menuItems) { itemTag = new TagBuilder("li"); if (String.IsNullOrWhiteSpace(item.Area)) { itemTag.InnerHtml = helper.ActionLink(item.Name, item.Action, new { area = "", controller = item.Controller }).ToString(); } else { itemTag.InnerHtml = helper.ActionLink(item.Name, item.Action, new { area = item.Area, controller = item.Controller }).ToString(); } menu.InnerHtml += itemTag; } return MvcHtmlString.Create(menu.ToString()); }
private TenantRepository() { _tenants = new Collection<Tenant>(); #region Initialize _tenants _tenants.Add(new Tenant { Host = "apple", Name = "Apple", Id = TenantIds.AppleId }); _tenants.Add(new Tenant { Host = "microsoft", Name = "Microsoft", Id = TenantIds.MicrosoftId }); _tenants.Add(new Tenant { Host = "bestbuy", Name = "BestBuy", Id = TenantIds.BestBuyId }); #endregion _currentTenant = null; }
public static bool HasAccess(Tenant currentTenant, string[] accessTypes) { IAccessService accessService = DependencyResolver.Current.GetService<IAccessService>(); if (currentTenant == null) { return false; } return accessService.HasAccess(currentTenant.Id, accessTypes); }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { string[] host = filterContext.RequestContext.HttpContext.Request.Headers["Host"].Split(':'); if (host.Length > 0) { CurrentTenant = _tenantService.GetCurrentTenant(host[0]); } base.OnActionExecuting(filterContext); }
protected override void Initialize(System.Web.Http.Controllers.HttpControllerContext controllerContext) { string[] host = controllerContext.Request.Headers.Host.Split(':'); if (host.Length > 0) { CurrentTenant = _tenantService.GetCurrentTenant(host[0]); } base.Initialize(controllerContext); }
public static MvcHtmlString PartialHelper(this HtmlHelper helper, Tenant currentTenant, string type, object model, string defaultLocation) { IPathService pathService = DependencyResolver.Current.GetService<IPathService>(); string location = null; if (currentTenant != null && pathService != null) { location = pathService.GetContentLocation(currentTenant.Id.ToString(), type); } if (location == null) { location = defaultLocation; } return helper.Partial(location, model); }
public static string StyleBundle(this UrlHelper helper, Tenant currentTenant, string type, string defaultLocation) { IPathService pathService = DependencyResolver.Current.GetService<IPathService>(); string location; if (currentTenant == null || pathService == null) { return defaultLocation; } location = pathService.GetContentLocation(currentTenant.Id.ToString(), type); if (location == null) { return defaultLocation; } return helper.Content(location); }
public Tenant SetCurrentTenant(int id) { var tenant = (from t in _tenants where t.Id == id select t).FirstOrDefault(); _currentTenant = tenant; return _currentTenant; }