Esempio n. 1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            Dictionary<string, string> routeTable = new Dictionary<string, string>();
            routeTable.Add("www.myshop.com", "jason");
            routeTable.Add("www.mystore.com", "www");
            routeTable.Add("jason.mystore.com", "jason");
            routeTable.Add("apple.mystore.com", "apple");

            string clientName;

            if (routeTable.TryGetValue(filterContext.HttpContext.Request.Headers["host"].ToString(), out clientName))
            {
                filterContext.RouteData.Values["subdomain"] = clientName;

                Store yourStore = new Store();
                yourStore.StoreName = "jason";
                yourStore.Theme = "simple";

                HttpContext.Current.Items.Add("store", yourStore);

                string lang = "en-US";

                if (filterContext.RouteData.Values["culture"] != null)
                {
                    lang = filterContext.RouteData.Values["culture"].ToString();
                }

                CultureInfo culture = CultureInfo.GetCultureInfo(lang);
                Thread.CurrentThread.CurrentUICulture = culture;
                Thread.CurrentThread.CurrentCulture = culture;

                if (filterContext.HttpContext.Session["theme"] == null)
                {
                    filterContext.HttpContext.Session["theme"] = yourStore.Theme;
                }

                if (filterContext.HttpContext.Request.QueryString["theme"] != null)
                {
                    filterContext.HttpContext.Session["theme"] = filterContext.HttpContext.Request.QueryString["theme"];
                }

            }
            else
            {
                filterContext.Result = new HttpStatusCodeResult(404);
            }
        }
Esempio n. 2
0
        public void RegisterComponents()
        {
            var container = new UnityContainer();

            var store = new Store { DisplayName = "myStore", DomainName = "www.mystore.com", Id = 1 };
            container.RegisterInstance(store);

            var token = new ShopTimeToken
            {
                Store = store,
                UserProfile = new ShopTimeUserProfile() { UserId = 1, DisplayName = "Jason Lee" }
            };

            container.RegisterInstance<IShopTimeToken>(token);

            //string connectionstring = string.Format(@"Data Source=(localdb)\v11.0;Initial Catalog={0};Integrated Security=True", Guid.NewGuid());
            string connectionstring = "ShopTimeDb";
            var shopTimeDb = new ShopTimeDbContext(token, connectionstring);
            shopTimeDb.Database.Log = Console.WriteLine;
            container.RegisterInstance(shopTimeDb);

            #region Repositories

            container.RegisterType<IRepository<Collection>, EfRepository<Collection>>();
            container.RegisterType<IRepository<CustomField>, EfRepository<CustomField>>();

            #endregion

            #region Services

            container.RegisterType<ICollectionService, CollectionService>();
            container.RegisterType<IProductService, ProductService>();

            #endregion

            Container = container;
        }