Ejemplo 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));
        }
Ejemplo n.º 2
0
        public void ValidatePagingParameters(RouteValueDictionaryWrapper routeValueDictionaryWrapper)
        {
            var page = int.Parse(routeValueDictionaryWrapper.GetValue("Page").ToString());

            if (RecordStart(routeValueDictionaryWrapper) > RecordEnd(routeValueDictionaryWrapper) & page > 1)
            {
                routeValueDictionaryWrapper.SetValue("Page", page - 1);
            }
        }
Ejemplo n.º 3
0
        public static RouteValueDictionaryWrapper ToRouteValues(this FormCollection formCollection)
        {
            var routeValueDictionaryWrapper = new RouteValueDictionaryWrapper();

            foreach (var key in formCollection.AllKeys)
            {
                if (key == "__RequestVerificationToken")
                {
                    continue;
                }
                routeValueDictionaryWrapper.SetValue(key, formCollection[key]);
            }
            return(routeValueDictionaryWrapper);
        }
Ejemplo n.º 4
0
        public static RouteValueDictionaryWrapper ToRouteValues(this NameValueCollection queryString, Object obj)
        {
            var routeValueDictionaryWrapper = new RouteValueDictionaryWrapper();

            if (queryString != null)
            {
                if (queryString.AllKeys.Distinct().Count() != queryString.AllKeys.Count())
                {
                    throw new Exception("ToRouteValues method was called with duplicate querystring key values");
                }
                foreach (string key in queryString)
                {
                    //values passed in object override those already in collection
                    if (!routeValueDictionaryWrapper.ContainsKey(key))
                    {
                        routeValueDictionaryWrapper.SetValue(key, queryString[key]);
                    }
                }
            }
            return(routeValueDictionaryWrapper);
        }