Exemplo n.º 1
0
        //ToDo:  This logic needs to be moved behind the view so it can be unit tested.
        public static HtmlString DynamicSortNameActionLink(this AjaxHelper helper, string expression, string actionName, string partialActionName, string controllerName, RouteValueDictionaryWrapper routeValueDictionaryWrapper, AjaxOptions options, string sortExpression = null)
        {
            var htmlHelper   = new HtmlHelper(helper.ViewContext, helper.ViewDataContainer);
            var urlHelper    = new UrlHelper(helper.ViewContext.RequestContext);
            var columnHeader = htmlHelper.DisplayName(expression).ToString();

            if (helper.ViewDataContainer.ViewData.Model is DynamicTableHeaderViewModel)
            {
                columnHeader = ((DynamicTableHeaderViewModel)helper.ViewDataContainer.ViewData.Model).DisplayName;
            }

            routeValueDictionaryWrapper = routeValueDictionaryWrapper.Clone();
            if (sortExpression == null)
            {
                sortExpression = expression;
            }
            if (routeValueDictionaryWrapper.ContainsKey("OrderBy") && routeValueDictionaryWrapper.GetValue("OrderBy").ToString() == sortExpression)
            {
                routeValueDictionaryWrapper.SetValue("OrderBy", sortExpression + " descending");
            }
            else
            {
                routeValueDictionaryWrapper.SetValue("OrderBy", sortExpression);
            }

            routeValueDictionaryWrapper.SetValue("Page", 1);
            options.Url = urlHelper.Action(partialActionName, controllerName, routeValueDictionaryWrapper.GetRouteValueDictionary());
            return(helper.ActionLink(columnHeader, actionName, controllerName, routeValueDictionaryWrapper.GetRouteValueDictionary(), options));
        }
        public static RouteValueDictionaryWrapper Clone(this RouteValueDictionaryWrapper routeValueDictionaryWrapper)
        {
            var result = new RouteValueDictionaryWrapper();

            foreach (var kvp in routeValueDictionaryWrapper.GetRouteValueDictionary())
            {
                result.Add(kvp.Key, kvp.Value);
            }
            return(result);
        }