Ejemplo n.º 1
0
        public static MvcHtmlString DropDownListMultipleChoiceFor <TModel, TValue>(this HtmlHelper <TModel> helper,
                                                                                   Expression <Func <TModel, TValue> > expression,
                                                                                   IEnumerable <SelectListItem> list, string label = "", object htmlAttributes = null)
        {
            var attributes = new Dictionary <string, object>();

            if (htmlAttributes != null)
            {
                foreach (var property in htmlAttributes.GetType().GetProperties())
                {
                    attributes[property.Name] = property.GetValue(htmlAttributes);
                }
            }

            var numMaxEl = HelperExtensions.NumMaxEl;

            attributes["data-live-search"] = (list.Count() > numMaxEl) ? "true" : "false";
            attributes["data-actions-box"] = "true";
            attributes["data-size"]        = "10";
            attributes["multiple"]         = "multiple";

            attributes["data-select-all-Text"]    = "Select All";
            attributes["data-deselect-all-Text"]  = "Deselect All";
            attributes["data-none-selected-Text"] = "Select...";

            attributes["class"] = (
                attributes.ContainsKey("class") ?
                attributes["class"] as string :
                ""
                ) + " selectpicker";

            return(SelectExtensions.ListBoxFor(helper, expression, list, attributes));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Return the Html's select element
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <typeparam name="TProperty"></typeparam>
        /// <param name="htmlHelper"></param>
        /// <param name="expression"></param>
        /// <param name="selectList"></param>
        /// <param name="htmlAttributes"></param>
        /// <param name="addEmptyRow"></param>
        /// <returns></returns>
        public static MvcHtmlString DropDownListFor <TModel, TProperty>(
            this HtmlHelper <TModel> htmlHelper,
            Expression <Func <TModel, TProperty> > expression,
            IEnumerable <SelectListItem> selectList,
            object htmlAttributes,
            bool addEmptyRow)
        {
            var list = new List <SelectListItem>();

            if (addEmptyRow)
            {
                list.Add(new SelectListItem()
                {
                    Value = string.Empty,
                    Text  = "選択してください"
                });
            }

            if (selectList != null)
            {
                list.AddRange(selectList);
            }

            return(SelectExtensions.DropDownListFor(
                       htmlHelper,
                       expression,
                       list,
                       htmlAttributes
                       ));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Drop down list
        /// </summary>
        /// <typeparam name="TModel">TModel entity</typeparam>
        /// <typeparam name="TValue">TValue entity</typeparam>
        /// <param name="htmlHelper">html helper</param>
        /// <param name="expression">Expression field</param>
        /// <param name="selectList">Select list</param>
        /// <param name="htmlAttributes">html attributes</param>
        /// <param name="disabled">Disabled field</param>
        /// <returns>returns mvc html string</returns>
        public static MvcHtmlString DropDownListFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TValue> > expression, IEnumerable <SelectListItem> selectList, object htmlAttributes, string disabled)
        {
            Func <TModel, TValue> deleg = expression.Compile();
            var result = deleg(htmlHelper.ViewData.Model);

            if (string.IsNullOrEmpty(disabled))
            {
                return(SelectExtensions.DropDownListFor(htmlHelper, expression, selectList, htmlAttributes));
            }
            else
            {
                string name = ExpressionHelper.GetExpressionText(expression);

                string selectedText = SelectInternal(htmlHelper, name, selectList);

                RouteValueDictionary routeValues = new RouteValueDictionary(htmlAttributes);

                if (disabled == "disabled")
                {
                    routeValues.Add("disabled", "disabled");
                }
                else if (disabled == "readonly")
                {
                    routeValues.Add("readonly", "read-only");
                }

                return(InputExtensions.TextBox(htmlHelper, name, selectedText, routeValues));
            }
        }
        //https://jeremylindsayni.wordpress.com/2015/01/17/mvc-enhanced-dropdownlistfor-part-2/

        /// <summary>
        /// Returns a single-selection HTML &lt;select&gt; element for the expression <paramref name="name" />,
        /// using the specified list items.
        /// </summary>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <typeparam name="TListItemType">The type of the items in the list.</typeparam>
        /// <typeparam name="TItemId">The type of the item identifier.</typeparam>
        /// <typeparam name="TItemName">The type of the item name.</typeparam>
        /// <typeparam name="TSelectedValue">The type of the selected value expression result.</typeparam>
        /// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
        /// <param name="formFieldName">Name of the form field.</param>
        /// <param name="items">The items to put in the  HTML &lt;select&gt; element.</param>
        /// <param name="optionValueProperty">The item identifier property.</param>
        /// <param name="optionInnerHTMLProperty">The item name property.</param>
        /// <param name="optionLabel">The text for a default empty item. Does not include such an item if argument is <c>null</c>.</param>
        /// <param name="htmlAttributes">An <see cref="object" /> that contains the HTML attributes for the &lt;select&gt; element. Alternatively, an
        /// <see cref="IDictionary{string, object}" /> instance containing the HTML attributes.</param>
        /// <returns>A new MvcHtmlString containing the &lt;select&gt; element.</returns>
        public static MvcHtmlString AutoDropDownListFor <TModel, TListItemType, TItemId, TItemName, TSelectedValue>(
            this HtmlHelper <TModel> htmlHelper,
            Expression <Func <TModel, TSelectedValue> > formFieldName,
            Expression <Func <TModel, List <TListItemType> > > items,
            Expression <Func <TListItemType, TItemId> > optionValueProperty,
            Expression <Func <TListItemType, TItemName> > optionInnerHTMLProperty,
            string optionLabel    = null,
            object htmlAttributes = null)
        {
            var formField            = ExpressionHelper.GetExpressionText(formFieldName);
            var itemIdPropertyName   = ExpressionHelper.GetExpressionText(optionValueProperty);
            var itemNamePropertyName = ExpressionHelper.GetExpressionText(optionInnerHTMLProperty);

            var listItemsModel = GetModelFromExpressionAndViewData(items, htmlHelper.ViewData) as List <TListItemType>;

            // if the list is null, initialize to an empty list so we display something
            if (listItemsModel == null)
            {
                listItemsModel = new List <TListItemType>();
            }

            var selectedValueObject = GetModelFromExpressionAndViewData(formFieldName, htmlHelper.ViewData);

            var selectList = new SelectList(listItemsModel, itemIdPropertyName, itemNamePropertyName, selectedValueObject);

            return(SelectExtensions.DropDownList(htmlHelper: htmlHelper, name: formField, selectList: selectList, optionLabel: optionLabel, htmlAttributes: htmlAttributes));
        }
        public static MvcHtmlString DropDownListFor <TModel, TListItemType, TItemId, TItemName, TSelectedValue>(
            this HtmlHelper <TModel> htmlHelper,
            Expression <Func <TModel, TSelectedValue> > formFieldName,
            Expression <Func <TModel, ICollection <TListItemType> > > items,
            Expression <Func <TListItemType, TItemId> > optionValueProperty,
            Expression <Func <TListItemType, TItemName> > optionInnerHtmlProperty,
            [Optional] string optionLabel,
            [Optional] object htmlAttributes)
        {
            if (htmlHelper == null)
            {
                throw new ArgumentNullException(paramName: "htmlHelper", message: "The static Html Helper is null.");
            }

            var formField            = ExpressionHelper.GetExpressionText(formFieldName);
            var itemIdPropertyName   = ExpressionHelper.GetExpressionText(optionValueProperty);
            var itemNamePropertyName = ExpressionHelper.GetExpressionText(optionInnerHtmlProperty);

            var listItemsModel = GetModelFromExpressionAndViewData(items, htmlHelper.ViewData) as List <TListItemType>;

            // if the list is null, initialize to an empty list so we display something
            if (listItemsModel == null)
            {
                listItemsModel = new List <TListItemType>();
            }

            var selectedValueObject = GetModelFromExpressionAndViewData(formFieldName, htmlHelper.ViewData);

            var selectList = new SelectList(listItemsModel, itemIdPropertyName, itemNamePropertyName, selectedValueObject);

            return(SelectExtensions.DropDownList(htmlHelper: htmlHelper, name: formField, selectList: selectList, optionLabel: optionLabel, htmlAttributes: htmlAttributes));
        }
        public static MvcHtmlString DropDownListBind(this HtmlHelper htmlHelper, string name, IEnumerable <SelectListItem> selectList, string optionLabel, object htmlAttributes)
        {
            var bind = new KnockoutBind(null, htmlAttributes);

            bind.AddBind("value", name);
            return(SelectExtensions.DropDownList(htmlHelper, name, selectList, optionLabel, bind));
        }
Ejemplo n.º 7
0
        public static MvcHtmlString DropDownListFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, object htmlAttributes)
        {
            if (expression.NodeType != ExpressionType.Lambda || expression.Body.NodeType != ExpressionType.MemberAccess)
            {
                throw new ArgumentException("Cannot determine dropdown list items - unparsable expression");
            }

            var memberExpression = expression.Body as MemberExpression;
            var attributes       = (ListChoiceAttribute[])memberExpression.Member.GetCustomAttributes(typeof(ListChoiceAttribute), true);

            if (attributes == null || attributes.Length == 0)
            {
                throw new ArgumentException("Cannot determine dropdown list items - no ListChoiceAttribute");
            }

            // get the object whose member is being accessed by executing the expressions' "base"
            var lambda           = Expression.Lambda(memberExpression.Expression, expression.Parameters);
            var containingObject = lambda.Compile().DynamicInvoke(htmlHelper.ViewData.Model);

            // finally, get the value of the property
            string propertyName  = attributes.First().ListPropertyName;
            Type   declaringType = (expression.Body as MemberExpression).Member.DeclaringType;
            object value         = declaringType.GetProperty(propertyName).GetValue(containingObject, null);

            if (!value.GetType().GetInterfaces().Any(x => x == typeof(IEnumerable <SelectListItem>)))
            {
                throw new ArgumentException("Cannot determine dropdown list items - invalid list property specified");
            }

            // do not call on htmlHelper to avoid a stack overflow: apparantly (IEnumerable<SelectListItem>value) is seen as object and we're called again
            return(SelectExtensions.DropDownListFor(htmlHelper, expression, (IEnumerable <SelectListItem>)value, htmlAttributes));
        }
Ejemplo n.º 8
0
        public static MvcHtmlString DropDownListFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, object htmlAttributes)
        {
            if (expression.NodeType != ExpressionType.Lambda || expression.Body.NodeType != ExpressionType.MemberAccess)
            {
                throw new ArgumentException("Cannot determine dropdown list items - unparsable expression");
            }

            MemberInfo member     = (expression.Body as MemberExpression).Member;
            var        attributes = (ListChoiceAttribute[])member.GetCustomAttributes(typeof(ListChoiceAttribute), true);

            if (attributes == null || attributes.Length == 0)
            {
                throw new ArgumentException("Cannot determine dropdown list items - no ListChoiceAttribute");
            }

            string       propertyName = attributes.First().ListPropertyName;
            PropertyInfo property     = htmlHelper.ViewData.Model.GetType().GetProperty(propertyName);
            object       value        = property.GetValue(htmlHelper.ViewData.Model, null);

            if (!value.GetType().GetInterfaces().Any(x => x == typeof(IEnumerable <SelectListItem>)))
            {
                throw new ArgumentException("Cannot determine dropdown list items - invalid list property specified");
            }

            // do not call on htmlHelper to avoid a stack overflow: apparantly (IEnumerable<SelectListItem>value) is seen as object and we're called again
            return(SelectExtensions.DropDownListFor(htmlHelper, expression, (IEnumerable <SelectListItem>)value, htmlAttributes));
        }
Ejemplo n.º 9
0
        public static MvcHtmlString DropDownListFor <TModel, TProperty, TEnum>(
            this HtmlHelper <TModel> htmlHelper,
            Expression <Func <TModel, TProperty> > expression,
            TEnum?selectedValue,
            Func <TEnum, string> getValue,
            List <SelectListItem> headerItems = null) where TEnum : struct
        {
            IEnumerable <TEnum> values = Enum.GetValues(typeof(TEnum))
                                         .Cast <TEnum>();
            IEnumerable <SelectListItem> items = from value in values
                                                 select new SelectListItem()
            {
                Text     = value.ToString(),
                Value    = getValue(value),
                Selected = (value.Equals(selectedValue))
            };

            if (headerItems != null && headerItems.Count > 0)
            {
                foreach (var item in headerItems)
                {
                    item.Selected = item.Value.Equals(selectedValue);
                }
                //headerItems.Union(items);
                headerItems.AddRange(items);
            }
            return(SelectExtensions.DropDownListFor(htmlHelper, expression, headerItems));
        }
Ejemplo n.º 10
0
        public void RightJoin_adds_join()
        {
            Select <TestClass> select = new Select <TestClass>();

            SelectExtensions.RightJoin(select, "foo", "1=1");
            select.Join().Sql().MustBe("right join foo on 1=1");
        }
Ejemplo n.º 11
0
        public void Join_adds_join()
        {
            Select <TestClass> select = new Select <TestClass>();

            SelectExtensions.Join(select, JoinType.Left, "foo", "1=1");
            select.Join().Sql().MustBe("left join foo on 1=1");
        }
Ejemplo n.º 12
0
        public static MvcHtmlString DropDownList(this HtmlHelper helper, string name, Type type, object selectedValue, object htmlAttributes)
        {
            if (!type.IsEnum)
            {
                throw new ArgumentException("Invalid type. It should be an enum.");
            }
            if (selectedValue == null || selectedValue.GetType() != type)
            {
                throw new ArgumentException("Invalid selected value type. It should be '" + type.ToString() + "'");
            }

            var items = new List <SelectListItem>();

            foreach (int value in Enum.GetValues(type))
            {
                string valueText = Enum.GetName(type, value);
                if (!IsObsoleteValue(value, valueText, type))
                {
                    var item = new SelectListItem();
                    item.Value    = value.ToString();
                    item.Text     = valueText;
                    item.Selected = object.Equals(value, (int)selectedValue);
                    items.Add(item);
                }
            }
            return(SelectExtensions.DropDownList(helper, name, items, htmlAttributes));
        }
Ejemplo n.º 13
0
        public static MvcHtmlString TimeDropDownList(this HtmlHelper html, string name, object htmlAttributes, int selectedHr = 0)
        {
            var list = new SelectList(new[]
            {
                new { Key = "0", Value = "00:00" },
                new { Key = "1", Value = "01:00" },
                new { Key = "2", Value = "02:00" },
                new { Key = "3", Value = "03:00" },
                new { Key = "4", Value = "04:00" },
                new { Key = "5", Value = "05:00" },
                new { Key = "6", Value = "06:00" },
                new { Key = "7", Value = "07:00" },
                new { Key = "8", Value = "08:00" },
                new { Key = "9", Value = "09:00" },
                new { Key = "10", Value = "10:00" },
                new { Key = "11", Value = "11:00" },
                new { Key = "12", Value = "12:00" },
                new { Key = "13", Value = "13:00" },
                new { Key = "14", Value = "14:00" },
                new { Key = "15", Value = "15:00" },
                new { Key = "16", Value = "16:00" },
                new { Key = "17", Value = "17:00" },
                new { Key = "18", Value = "18:00" },
                new { Key = "19", Value = "19:00" },
                new { Key = "20", Value = "20:00" },
                new { Key = "21", Value = "21:00" },
                new { Key = "22", Value = "22:00" },
                new { Key = "23", Value = "23:00" },
                new { Key = "24", Value = "24:00" },
            }, "Key", "Value", selectedHr);

            return(SelectExtensions.DropDownList(html, name, list, htmlAttributes));
        }
        public static MvcHtmlString DropDownListBindFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, IEnumerable <SelectListItem> selectList, string optionLabel, object htmlAttributes)
        {
            var bind = new KnockoutBind(null, htmlAttributes);

            bind.AddBind("value", ExpressionHelper.GetExpressionText(expression));
            return(SelectExtensions.DropDownListFor(htmlHelper, expression, selectList, optionLabel, bind));
        }
Ejemplo n.º 15
0
        public static void DropDownListForTestWithListAndNoSelectedItem()
        {
            // Arrange
            var userViewModel = new UserViewModel(new List <User>()
            {
                new User {
                    Name = "Dave", Id = 1
                },
                new User {
                    Name = "Nate", Id = 2
                },
                new User {
                    Name = "Pat", Id = 3
                },
                new User {
                    Name = "Taylor", Id = 4
                },
                new User {
                    Name = "Chris", Id = 5
                }
            });

            var htmlHelper            = HtmlHelperMock.GetMock(userViewModel);
            var expectedMvcHtmlString = SelectExtensions.DropDownListFor(htmlHelper, m => m.UserId, new SelectList(userViewModel.UserNames, "Id", "Name", userViewModel.UserId));

            // Act
            var actualMvcHtmlString = HtmlHelperSelectExtensions.DropDownListFor(htmlHelper, m => m.UserId, m => m.UserNames, m => m.Id, m => m.Name);

            // Assert
            Assert.AreEqual(expectedMvcHtmlString.ToHtmlString(), actualMvcHtmlString.ToHtmlString());
        }
Ejemplo n.º 16
0
        public static MvcHtmlString UomEnumDropdownList <TModel, TEnum>(
            this HtmlHelper <TModel> htmlHelper, string name, TEnum selectedValue, object htmlAttributes) where TEnum : struct
        {
            var values = Enum.GetValues(typeof(TEnum)).Cast <TEnum>();
            IEnumerable <SelectListItem> items = ValueToListItems(selectedValue, values);

            return(SelectExtensions.DropDownList(htmlHelper, name, items, htmlAttributes));
        }
Ejemplo n.º 17
0
        public static MvcHtmlString KODropDownListFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, IEnumerable <SelectListItem> selectList, string optionLabel)
        {
            var htmlAttributes = new Dictionary <string, object>();
            var name           = GetMemberName(expression);

            htmlAttributes.Add("data-bind", string.Format("value:{0}", name));
            return(SelectExtensions.DropDownListFor(htmlHelper, expression, selectList, optionLabel, htmlAttributes));
        }
Ejemplo n.º 18
0
 public static MvcHtmlString ListBoxFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, IEnumerable <SelectListItem> selectList = null, string cssClass = null, string dir = null, bool disabled = false, string id = null, string lang = null, int?size = null, string style = null, int?tabIndex = null, string title = null)
 {
     return(SelectExtensions.ListBoxFor(
                htmlHelper,
                expression,
                selectList,
                SelectAttributes(cssClass, dir, disabled, id, lang, size, style, tabIndex, title)
                ));
 }
Ejemplo n.º 19
0
 public static MvcHtmlString ListBox(this HtmlHelper htmlHelper, string name, IEnumerable <SelectListItem> selectList = null, string cssClass = null, string dir = null, bool disabled = false, string id = null, string lang = null, int?size = null, string style = null, int?tabIndex = null, string title = null)
 {
     return(SelectExtensions.ListBox(
                htmlHelper,
                name,
                selectList,
                SelectAttributes(cssClass, dir, disabled, id, lang, size, style, tabIndex, title)
                ));
 }
Ejemplo n.º 20
0
        public static MvcHtmlString Ul <T>(this HtmlHelper helper, string id, string cssClass, string alternateText, object htmlAttributes, string itemCssClass, IList <T> items, Func <T, IHtmlString> itemContent)
        {
//			// Create tag builder
//			var imgTag = new TagBuilder("img");
//
//			// Create valid id
//			imgTag.GenerateId(id);
//
//			// Add attributes
//			imgTag.MergeAttribute("src", helper.Url().Content(src));
//			imgTag.MergeAttribute("alt", helper.Encode(alternateText));
//			imgTag.MergeAttributes(new RouteValueDictionary(htmlAttributes), true);
//
//			// Render tag
//			return new MvcHtmlString(imgTag.ToString(TagRenderMode.Normal));
            SelectExtensions.DropDownList()
            helper.DropDownList().
            var ulTag = new TagBuilder("ul");

            ulTag.GenerateId(id);
            ulTag.AddCssClass(cssClass);
            ulTag.MergeAttributes(new RouteValueDictionary(htmlAttributes), true);
            var itemNumber = 0;

            foreach (T item in items)
            {
                itemNumber++;
                var liTag = new TagBuilder("li");
                liTag.AddCssClass(itemCssClass);
                if (Menu.IsSelected(item))
                {
                    liTag.AddCssClass(SelectedItemCssClass);
                }
                if (itemNumber == 1)
                {
                    liTag.AddCssClass("first");
                }
                if (itemNumber == items.Count)
                {
                    liTag.AddCssClass("last");
                }
                liTag.InnerHtml = itemContent(item).ToHtmlString();

                //if (string.IsNullOrEmpty(item.ClientCallbackMethod))
                //{
                //    liTag.InnerHtml = System.Web.Mvc.Html.LinkExtensions.ActionLink(Helper, item.Text, item.Url.ActionName, item.Url.ControllerName ?? string.Empty).ToHtmlString();
                //}
                //else
                //{
                //    // see http://stackoverflow.com/questions/134845/href-tag-for-javascript-links-or-javascriptvoid0
                //    liTag.InnerHtml = string.Format("<a onclick=\"{1}\">{0}</a>", item.Text, item.ClientCallbackMethod);
                //}

                ulTag.InnerHtml += liTag.ToString();
            }
            return(MvcHtmlString.Create(ulTag.ToString(TagRenderMode.Normal)));
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Gets the DropDownList component for the Enum property.
        /// </summary>
        /// <typeparam name="T">The model</typeparam>
        /// <typeparam name="U">The property</typeparam>
        /// <param name="htmlHelper">The HtmlHelper</param>
        /// <param name="expression">The expression for the property</param>
        /// <param name="htmlAttributes">The next html attributes for the component</param>
        /// <returns>The HTML string of the DropDownList with internationalized options</returns>
        public static MvcHtmlString LocalizedDropDownListFor <T, U>(this HtmlHelper <T> htmlHelper, Expression <Func <T, U> > expression, object htmlAttributes = null)
        {
            ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
            Type          enumType = GetNonNullableModelType(metadata);

            List <SelectListItem> selectListItem = CreateListItems <U>(typeof(T), Enum.GetValues(enumType).Cast <U>(), metadata);

            return(SelectExtensions.DropDownListFor(htmlHelper, expression, selectListItem, htmlAttributes));
        }
Ejemplo n.º 22
0
        public void Where_adds_clause()
        {
            Select select = new Select();

            SelectExtensions.Where(select, "foo", SqlOperator.LessThan, 2);

            select.Parameters.Count().MustBe(1);
            select.Parameters["@p0"].MustBe(2);
            select.Where().Sql().MustBe("where foo<@p0");
        }
Ejemplo n.º 23
0
        public void Linq4_Customers_CustomersAndDateOfEntry()
        {
            var result = SelectExtensions.Linq4(DataSource.Customers).ToList();

            Assert.That(() => result.Count, Is.EqualTo(DataSource.Customers.Count - 1));
            foreach (var(customer, dateOfEntry) in result)
            {
                Assert.That(FindCustomerOrdersMinDate(customer), Is.EqualTo(dateOfEntry));
            }
        }
Ejemplo n.º 24
0
        public static MvcHtmlString UomEnumDropdownList <TModel, TEnum>(
            this HtmlHelper <TModel> htmlHelper, string name, TEnum?selectedValue, object htmlAttributes) where TEnum : struct
        {
            var stringified = selectedValue != null?selectedValue.Value.ToString() : null;

            var values = new[] { "---" }.Concat(Enum.GetValues(typeof(TEnum)).Cast <TEnum>().Select(v => v.ToString()));
            IEnumerable <SelectListItem> items = ValueToListItems(stringified, values);

            return(SelectExtensions.DropDownList(htmlHelper, name, items, htmlAttributes));
        }
Ejemplo n.º 25
0
        public void Where_adds_equals_clause()
        {
            Select select = new Select();

            SelectExtensions.Where(select, "foo", 2);

            select.Parameters.Count().MustBe(1);
            select.Parameters["@p0"].MustBe(2);
            select.Where().Sql().MustBe("where foo=@p0");
        }
Ejemplo n.º 26
0
        public static MvcHtmlString EnumDropdownListFor <TModel, TProperty, TEnum>(
            this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, TEnum?selectedValue) where TEnum : struct
        {
            var stringified = selectedValue != null?selectedValue.Value.ToString() : null;

            var values = new[] { "All" }.Concat(Enum.GetValues(typeof(TEnum)).Cast <TEnum>().Select(v => v.ToString()));
            IEnumerable <SelectListItem> items = ValueToListItems(stringified, values);

            return(SelectExtensions.DropDownListFor(htmlHelper, expression, items));
        }
Ejemplo n.º 27
0
        public void Linq7_Customers_Returns5()
        {
            var expectedResult = new[]
            {
                new Linq7CategoryGroup
                {
                    Category          = "Beverages",
                    UnitsInStockGroup = new[]
                    {
                        new Linq7UnitsInStockGroup
                        {
                            UnitsInStock = 39,
                            Prices       = new[] { 19.0000M },
                        },
                        new Linq7UnitsInStockGroup
                        {
                            UnitsInStock = 17,
                            Prices       = new[] { 18.0000M },
                        },
                    },
                },
                new Linq7CategoryGroup
                {
                    Category          = "Condiments",
                    UnitsInStockGroup = new[]
                    {
                        new Linq7UnitsInStockGroup
                        {
                            UnitsInStock = 15,
                            Prices       = new[] { 10.0000M, 40.0000M },
                        },
                        new Linq7UnitsInStockGroup
                        {
                            UnitsInStock = 13,
                            Prices       = new[] { 30.0000M },
                        },
                    },
                },
            };

            var result = SelectExtensions.Linq7(DataSource.Products);

            foreach (var categoryGroup in result)
            {
                var expectedCategoryGroup = expectedResult.Single(_ => _.Category == categoryGroup.Category);
                foreach (var unitInStockGroup in categoryGroup.UnitsInStockGroup)
                {
                    var expectedUnitInStockGroup = expectedCategoryGroup
                                                   .UnitsInStockGroup.Single(_ => _.UnitsInStock == unitInStockGroup.UnitsInStock);
                    CollectionAssert.AreEqual(expectedUnitInStockGroup.Prices, unitInStockGroup.Prices);
                }
            }
        }
Ejemplo n.º 28
0
        public void Where_adds_clause_when_clauses_already_exist()
        {
            Select <TestClass> select = new Select <TestClass>();

            select.Where(x => x.Id, 7);
            SelectExtensions.Where(select, "foo", SqlOperator.LessThan, 2);

            select.Parameters.Count().MustBe(2);
            select.Parameters["@p0"].MustBe(7);
            select.Parameters["@p1"].MustBe(2);
            select.Where().Sql().MustBe("where (Id=@p0 And foo<@p1)");
        }
        public static MvcHtmlString DropDownListControlFor <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, IEnumerable <SelectListItem> selectList, object inputHtmlAttributes)
        {
            var metaData      = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
            var htmlFieldName = ExpressionHelper.GetExpressionText(expression);

            return(ControlGroupExtension.Helper(
                       html,
                       metaData,
                       htmlFieldName,
                       SelectExtensions.DropDownListFor(html, expression, selectList, inputHtmlAttributes)
                       ));
        }
Ejemplo n.º 30
0
        public static MvcHtmlString JQM_SelectMenu(this HtmlHelper htmlHelper, string name, string label, MultiSelectList values, string optionLabel = null, SelectMenuConfig config = null)
        {
            TagBuilder tagResult = new TagBuilder("div");

            tagResult.MergeAttribute("class", "ui-field-contain");
            if (config == null)
            {
                config = new SelectMenuConfig();
            }

            tagResult.InnerHtml += LabelExtensions.Label(htmlHelper, "", label).ToHtmlString();
            tagResult.InnerHtml += SelectExtensions.DropDownList(htmlHelper, name, values, optionLabel, (config != null) ? config.GetAttributes() : null).ToHtmlString();
            return(tagResult.ToHtml());
        }