Example #1
0
        private string GenerateUrl(HccRoute route, string actionName, string controllerName, string protocol,
                                   string hostName, string fragment, RouteValueDictionary routeValues, RouteCollection routeCollection,
                                   RequestContext requestContext, bool includeImplicitMvcValues)
        {
            // Code that search DNN module corresponding to concrete route have to be here
            // Route params have to be added to the url too.

            var urlInfo = new DnnUrlInfo();

            if (route == HccRoute.Login)
            {
                return(Globals.LoginURL((string)routeValues["returnUrl"], false));
            }
            if (route == HccRoute.Terms)
            {
                return(Globals.NavigateURL("Terms"));
            }
            if (route == HccRoute.Logoff)
            {
                return(Globals.NavigateURL("LogOff"));
            }
            if (route == HccRoute.SendPassword)
            {
                return(Globals.NavigateURL("SendPassword"));
            }
            if (route == HccRoute.UserProfile)
            {
                var userId = 0;
                if (int.TryParse((string)routeValues["userId"], out userId))
                {
                    return(Globals.UserProfileURL(userId));
                }
                throw new ApplicationException("UserId is not a number");
            }
            urlInfo = GetTabId(route);

            var paramsList = new List <string>();

            if (!string.IsNullOrEmpty(urlInfo.ControlKey))
            {
                var moduleCtl = new ModuleController();
                var mInfo     = moduleCtl.GetTabModules(urlInfo.TabId)
                                .Where(m => m.Value.DesktopModule.ModuleName == urlInfo.ModuleName)
                                .Select(m => m.Value)
                                .FirstOrDefault();

                if (mInfo != null)
                {
                    paramsList.Add("mid=" + mInfo.ModuleID);
                }
            }

            if (routeValues != null)
            {
                foreach (var newQueryItem in routeValues)
                {
                    var isParamValid = newQueryItem.Value != null;
                    if (newQueryItem.Value is string)
                    {
                        isParamValid = !string.IsNullOrWhiteSpace(newQueryItem.Value as string);
                    }

                    if (isParamValid)
                    {
                        var parameter = string.Format("{0}={1}", newQueryItem.Key, newQueryItem.Value);
                        paramsList.Add(parameter);
                    }
                }
            }

            var portalSettings = CurrentPortalSettings;
            var isSuperTab     = Globals.IsHostTab(urlInfo.TabId);
            var parameters     = paramsList.ToArray();

            var navigateUrl = string.Empty;

            if (PortalSettings.Current != null)
            {
                navigateUrl = Globals.NavigateURL(urlInfo.TabId, isSuperTab, portalSettings, urlInfo.ControlKey, null,
                                                  parameters);
            }
            else
            {
                navigateUrl = NavigateUrl(urlInfo.TabId, isSuperTab, portalSettings, urlInfo.ControlKey, parameters);
            }
            return(navigateUrl);
        }
Example #2
0
        private DnnUrlInfo GetTabId(HccRoute route)
        {
            StoreSettingsUrls urlStoreSettings = null;

            if (HccRequestContext.Current.CurrentStore != null)
            {
                urlStoreSettings = HccRequestContext.Current.CurrentStore.Settings.Urls;
            }

            var urlInfo = new DnnUrlInfo();

            switch (route)
            {
            case HccRoute.Cart:
                urlInfo.TabId = urlStoreSettings.CartTabId;
                break;

            case HccRoute.Product:
                urlInfo.TabId = urlStoreSettings.ProductTabId;
                break;

            case HccRoute.ProductReview:
                urlInfo.TabId = urlStoreSettings.ProductReviewTabId;
                break;

            case HccRoute.Category:
                urlInfo.TabId = urlStoreSettings.CategoryTabId;
                break;

            case HccRoute.Checkout:
                urlInfo.TabId = urlStoreSettings.CheckoutTabId;
                break;

            case HccRoute.CheckoutPayPal:
                urlInfo.TabId      = urlStoreSettings.CheckoutTabId;
                urlInfo.ControlKey = "PayPalCheckout";
                urlInfo.ModuleName = "Hotcakes.Checkout";
                break;

            case HccRoute.ThirdPartyPayment:
                urlInfo.TabId      = urlStoreSettings.CheckoutTabId;
                urlInfo.ControlKey = "ThirdPartyPayment";
                urlInfo.ModuleName = "Hotcakes.Checkout";
                break;

            case HccRoute.WishList:
                urlInfo.TabId = urlStoreSettings.WishListTabId;
                break;

            case HccRoute.Search:
                urlInfo.TabId = urlStoreSettings.SearchTabId;
                break;

            case HccRoute.OrderHistory:
                urlInfo.TabId = urlStoreSettings.OrderHistoryTabId;
                break;

            case HccRoute.AddressBook:
                urlInfo.TabId = urlStoreSettings.AddressBookTabId;
                break;

            case HccRoute.EditUserProfile:
                urlInfo.TabId      = CurrentPortalSettings.UserTabId;
                urlInfo.ControlKey = "Profile";
                break;

            case HccRoute.AffiliateRegistration:
                urlInfo.TabId = GetTabIdByModuleName("Hotcakes.AffiliateRegistration");
                break;

            case HccRoute.AffiliateDashboard:
                urlInfo.TabId = GetTabIdByModuleName("Hotcakes.AffiliateDashboard");
                break;

            case HccRoute.Home:
                urlInfo.TabId = CurrentPortalSettings.HomeTabId;
                break;

            default:
                throw new NotImplementedException();
            }
            return(urlInfo);
        }