コード例 #1
0
        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());
        }
コード例 #2
0
        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;
        }
コード例 #3
0
ファイル: AccessHelper.cs プロジェクト: jcadruvi/MultiTenant
 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);
 }
コード例 #4
0
 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);
 }
コード例 #5
0
 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);
 }
コード例 #6
0
 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);
 }
コード例 #7
0
ファイル: ContentHelper.cs プロジェクト: jcadruvi/MultiTenant
 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);
 }
コード例 #8
0
 public Tenant SetCurrentTenant(int id)
 {
     var tenant = (from t in _tenants
                   where t.Id == id
                   select t).FirstOrDefault();
     _currentTenant = tenant;
     return _currentTenant;
 }