Esempio n. 1
0
        public ActionResult Edit(string id)
        {
            var menu = _repository.Get(p => p.Id == id);

            var model = new WxMenuModel();

            model.Id             = menu.Id;
            model.Bind           = menu.Bind;
            model.BindTopic      = menu.Content;
            model.BindValue      = menu.ReplyId;
            model.Name           = menu.Name;
            model.CreateDateTime = menu.CreateDateTime;
            model.Url            = menu.Content;
            model.Sequence       = menu.Sequence;

            model.ParentMenu = _repository.Get(x => x.Id == menu.ParentId);

            model.BindTypes = SelectListItems.FromEnum(menu.Bind).ToArray();

            model.Keywords = _wxReplyRepository.Query()
                             .Select(x => new { x.Sequence, x.Id, x.Content })
                             .OrderByDescending(x => x.Sequence)
                             .ToList()
                             .Select(x => new SelectListItem
            {
                Value    = x.Id,
                Text     = x.Content,
                Selected = x.Id == menu.Content
            }).ToArray();

            model.Topics = new SelectListItem[] { };

            return(View(model));
        }
Esempio n. 2
0
        public IEnumerable <System.Web.Mvc.SelectListItem> GetSelectListItems(System.Web.Routing.RequestContext requestContext, string filter = null)
        {
            var items = SelectListItems.FromEnum <OrderStatus>();

            items.Insert(0, new System.Web.Mvc.SelectListItem {
                Text = "", Value = ""
            });
            return(items);
        }
Esempio n. 3
0
        // protected int CustomerTypeId { get; set; }

        #endregion

        #region Initialisation

        protected override async Task OnInitAsync()
        {
            this.Title         = "Clients";
            this.CustomerTypes = SelectListItems.Convert(await AdministrationService.GetCustomerTypes(), (src, dest) =>
            {
                dest.Id   = src.Id;
                dest.Text = src.Text;
            });
            await LoadCustomers();

            await JavascriptFunctions.InitTable("customerTable");
        }
Esempio n. 4
0
        public ActionResult Add(BindType?bind, string parentId)
        {
            var model = new WxMenuModel()
            {
                Bind     = bind.GetValueOrDefault(),
                ParentId = parentId
            };

            model.BindTypes = SelectListItems.FromEnum(bind.GetValueOrDefault()).ToArray();

            model.Keywords = _wxReplyRepository.Query()
                             .Select(x => new { x.Sequence, x.Id, x.Content })
                             .OrderByDescending(x => x.Sequence)
                             .ToList()
                             .Select(x => new SelectListItem {
                Value = x.Id, Text = x.Content
            }).ToArray();

            model.Topics = new SelectListItem[] { };

            return(View(model));
        }
Esempio n. 5
0
        public List <SelectListItem> List(List <string> SelectedItems = null)
        {
            var Items = _db.Facility.ToList();

            if (SelectListItems == null)
            {
                SelectListItems = new List <SelectListItem>();
            }
            //var SelectList = new List<SelectListItem>();
            //var SelectedItems = SelectedItems;
            foreach (var item in Items)
            {
                SelectListItems.Add(new SelectListItem
                {
                    Text     = item.Text,
                    Value    = item.ID.ToString(),
                    Selected = SelectedItems == null ? false :
                               (SelectedItems.Contains(item.ID.ToString())?true:false)
                });
            }

            return(SelectListItems);
        }
Esempio n. 6
0
        public void Scenic()
        {
            var Items = _db.Scenic.ToList();

            if (SelectListItems == null)
            {
                SelectListItems = new List <SelectListItem>();
            }
            //var SelectList = new List<SelectListItem>();
            //var SelectedItems = SelectedItems;
            foreach (var item in Items)
            {
                SelectListItems.Add(new SelectListItem
                {
                    Text     = item.Name,
                    Value    = item.ID.ToString(),
                    Selected = SelectedItems == null ? false :
                               (SelectedItems.Contains(item.ID.ToString())?true:false)
                });
            }

            //return SelectList;
        }
        protected override async Task OnParametersSetAsync()
        {
            this.CustomerTypes = SelectListItems.Convert(await AdministrationService.GetCustomerTypes(), (src, dest) =>
            {
                dest.Id   = src.Id;
                dest.Text = src.Text;
            });


            if (IsNew())
            {
                this.Title = "Ajouter un client";
            }
            else
            {
                this.Title = "Modifier un client";

                Customer customer = await CustomerService.GetCustomer(Id.Value);

                this.Name           = customer.Name;
                this.FirstName      = customer.FirstName;
                this.CustomerTypeId = customer.CustomerTypeId;
            }
        }
 public PaymentMethodEditorModel()
 {
     AvailablePaymentProcessors = new List <PaymentProcessorModel>();
     AllFeeChargeModes          = SelectListItems.FromEnum(typeof(PaymentMethodFeeChargeMode));
 }
Esempio n. 9
0
 public ConfigModel()
 {
     AvailableDiscountModes      = SelectListItems.FromEnum <DiscountMode>();
     AvailableDiscountAppliedTos = SelectListItems.FromEnum <DiscountAppliedTo>();
 }
Esempio n. 10
0
        private string GenerateSingleChoice <TModel>(ControlFormResult <TModel> controlForm, HtmlHelper htmlHelper) where TModel : class
        {
            var attributes = new RouteValueDictionary();
            var valMsg     = new MvcHtmlString(string.Format("<span data-valmsg-for=\"{0}\" data-valmsg-replace=\"true\"></span>", Name));

            var selectedValue = Convert.ToString(Value);

            IList <SelectListItem> selectItems;

            if (PropertyType.IsEnum)
            {
                var values = Enum.GetValues(PropertyType);

                selectItems = (from object value in values
                               select new SelectListItem
                {
                    Text = GetEnumValueDescription(PropertyType, value),
                    Value = Convert.ToString(value),
                }).ToList();
            }
            else
            {
                if (SelectListItems == null)
                {
                    var tmpSelectItems = controlForm.GetExternalDataSource(Name);

                    if (tmpSelectItems == null && Name.Contains('['))
                    {
                        tmpSelectItems = controlForm.GetExternalDataSource(Name.RemoveBetween('[', ']'));
                    }

                    if (tmpSelectItems == null && Name.Contains('.'))
                    {
                        tmpSelectItems = controlForm.GetExternalDataSource((Name + ".").RemoveBetween('.', '.'));
                    }

                    if (tmpSelectItems == null)
                    {
                        throw new NotSupportedException("You need to register an external data source for " + Name);
                    }
                    selectItems = tmpSelectItems.ToList();
                }
                else
                {
                    selectItems = SelectListItems.ToList();
                }
            }

            var cssClass = (controlForm.FormProvider.ControlCssClass + " " + CssClass).Trim();

            if (EnableChosen)
            {
                cssClass = CssClass;
            }
            if (!string.IsNullOrEmpty(cssClass))
            {
                attributes.Add("class", cssClass);
            }

            if (ReadOnly || controlForm.ReadOnly)
            {
                string selectedText = null;

                var item = selectItems.FirstOrDefault(x => x.Value == selectedValue);
                if (item != null)
                {
                    selectedText = item.Text;
                }

                return(string.Format(
                           @"<input type=""hidden"" id=""{3}"" name=""{0}"" value=""{1}"" /><input type=""text"" class=""{4}"" readonly=""readonly"" value=""{2}"" />",
                           Name,
                           selectedValue,
                           selectedText,
                           htmlHelper.ViewData.TemplateInfo.GetFullHtmlFieldId(Name),
                           cssClass));
            }

            if (Required || !string.IsNullOrEmpty(RequiredIf))
            {
                attributes.Add("data-val", "true");
                if (!string.IsNullOrEmpty(RequiredIf))
                {
                    if (Name.Contains("."))
                    {
                        var dependency = RequiredIf.TrimStart('#').Split(':').First();
                        var requiredIf = RequiredIf.Replace(dependency, Name.Replace(Name.Split('.').Last(), dependency));
                        attributes.Add("data-val-requiredif", "#" + htmlHelper.ViewData.TemplateInfo.GetFullHtmlFieldId(requiredIf.TrimStart('#')));
                    }
                    else
                    {
                        attributes.Add("data-val-requiredif", "#" + RequiredIf.TrimStart('#'));
                    }
                }
                else
                {
                    if (RequiredIfHaveItemsOnly == false || selectItems.Any())
                    {
                        attributes.Add("data-val-required", Constants.Messages.Validation.Required);
                    }
                }
            }

            if (!string.IsNullOrEmpty(DataBind))
            {
                attributes["data-bind"] = DataBind;
            }

            if (type == ControlChoice.DropDownList)
            {
                var builder = new StringBuilder();

                if (!string.IsNullOrEmpty(OnSelectedIndexChanged))
                {
                    attributes["onchange"] = OnSelectedIndexChanged;
                }

                var selectedValues = new List <string>();

                if (AllowMultiple)
                {
                    attributes["multiple"] = "multiple";

                    var value = Value as IEnumerable;
                    if (value != null)
                    {
                        selectedValues.AddRange(from object item in value select Convert.ToString(item));
                    }
                }

                var selectTag = htmlHelper.DropDownList(Name, new SelectListItem[] { }, attributes);

                if (!Required)
                {
                    builder.AppendLine("<option>" + OptionLabel + "</option>");
                }

                if (GroupedByCategory && EnableChosen)
                {
                    var items  = selectItems.Cast <ExtendedSelectListItem>().ToList();
                    var groups = items.GroupBy(x => x.Category);

                    foreach (var @group in groups)
                    {
                        builder.AppendFormat("<optgroup label=\"{0}\">", group.Key);

                        foreach (var item in group)
                        {
                            var optionTag = new TagBuilder("option")
                            {
                                InnerHtml = HttpUtility.HtmlEncode(item.Text)
                            };
                            if (item.Value != null)
                            {
                                optionTag.Attributes["value"] = item.Value;
                            }

                            if (AllowMultiple)
                            {
                                if (selectedValues.Contains(item.Value))
                                {
                                    optionTag.Attributes["selected"] = "selected";
                                }
                            }
                            else
                            {
                                if (item.Value == selectedValue)
                                {
                                    optionTag.Attributes["selected"] = "selected";
                                }
                            }

                            if (item != null && item.HtmlAttributes != null)
                            {
                                var htmlAttributes = item.HtmlAttributes as IDictionary <string, object>;
                                optionTag.MergeAttributes(htmlAttributes ?? HtmlHelper.AnonymousObjectToHtmlAttributes(item.HtmlAttributes));
                            }

                            builder.AppendLine(optionTag.ToString(TagRenderMode.Normal));
                        }

                        builder.Append("</optgroup>");
                    }
                }
                else
                {
                    foreach (var selectItem in selectItems)
                    {
                        var optionTag = new TagBuilder("option")
                        {
                            InnerHtml = HttpUtility.HtmlEncode(selectItem.Text)
                        };
                        if (selectItem.Value != null)
                        {
                            optionTag.Attributes["value"] = selectItem.Value;
                        }

                        if (AllowMultiple)
                        {
                            if (selectedValues.Contains(selectItem.Value))
                            {
                                optionTag.Attributes["selected"] = "selected";
                            }
                        }
                        else
                        {
                            if (selectItem.Value == selectedValue)
                            {
                                optionTag.Attributes["selected"] = "selected";
                            }
                        }

                        var extendedSelectListItem = selectItem as ExtendedSelectListItem;
                        if (extendedSelectListItem != null && extendedSelectListItem.HtmlAttributes != null)
                        {
                            var htmlAttributes = extendedSelectListItem.HtmlAttributes as IDictionary <string, object>;
                            optionTag.MergeAttributes(htmlAttributes ?? HtmlHelper.AnonymousObjectToHtmlAttributes(extendedSelectListItem.HtmlAttributes));
                        }

                        builder.AppendLine(optionTag.ToString(TagRenderMode.Normal));
                    }
                }

                var html = selectTag.ToHtmlString();

                builder.Insert(0, html.Replace("</select>", ""));
                builder.Append("</select>");

                if (!string.IsNullOrEmpty(PrependText) && !string.IsNullOrEmpty(AppendText))
                {
                    builder.Insert(0, string.Format("<div class=\"input-prepend input-append\"><span class=\"add-on\">{0}</span>", PrependText));
                    builder.AppendFormat("<span class=\"add-on\">{0}</span>", AppendText);
                    builder.Append("</div>");
                }

                else if (!string.IsNullOrEmpty(PrependText))
                {
                    builder.Insert(0, string.Format("<div class=\"input-prepend\"><span class=\"add-on\">{0}</span>", PrependText));
                    builder.Append("</div>");
                }

                else if (!string.IsNullOrEmpty(AppendText))
                {
                    builder.Insert(0, "<div class=\"input-append\">");
                    builder.AppendFormat("<span class=\"add-on\">{0}</span>", AppendText);
                    builder.Append("</div>");
                }

                builder.Append(valMsg);

                if (!string.IsNullOrEmpty(HelpText))
                {
                    builder.AppendFormat("<span class=\"help-block\">{0}</span>", HelpText);
                }

                #region Scripts

                if (EnableChosen)
                {
                    builder.Append("<script type=\"text/javascript\">");
                    builder.Append("$(document).ready(function(){");
                    builder.AppendFormat("$('#{0}').chosen({{ no_results_text: \"No results matched\", allow_single_deselect:true, inherit_select_classes: true, display_selected_options: true }});", htmlHelper.ViewData.TemplateInfo.GetFullHtmlFieldId(Name));
                    builder.Append("});");
                    builder.Append("</script>");
                }

                #endregion Scripts

                return(builder.ToString());
            }

            #region Radio Buttons

            cssClass = CssClass ?? "radio";
            attributes.Remove("class");

            var sb    = new StringBuilder();
            var index = 0;
            foreach (var selectItem in selectItems)
            {
                string dataBind = null;
                var    extendedSelectListItem = selectItem as ExtendedSelectListItem;
                if (extendedSelectListItem != null && extendedSelectListItem.HtmlAttributes != null)
                {
                    attributes = attributes.Merge(extendedSelectListItem.HtmlAttributes);
                    if (attributes.ContainsKey("container-data-bind"))
                    {
                        dataBind = Convert.ToString(attributes["container-data-bind"]);
                        attributes.Remove("container-data-bind");
                    }
                }

                attributes["id"] = htmlHelper.ViewData.TemplateInfo.GetFullHtmlFieldId(Name + "_" + index);

                var radioButton = htmlHelper.RadioButton(Name, selectItem.Value, selectItem.Value == selectedValue, attributes);
                sb.AppendFormat("<div class=\"{2}\" data-bind=\"{3}\"><label>{1}{0}</label></div>", selectItem.Text, radioButton, cssClass, dataBind);
                index++;
            }

            return(sb.ToString());

            #endregion Radio Buttons
        }
Esempio n. 11
0
        private string GenerateCheckBoxList <TModel>(ControlFormResult <TModel> controlForm, HtmlHelper htmlHelper) where TModel : class
        {
            if (!typeof(IEnumerable).IsAssignableFrom(PropertyType))
            {
                throw new NotSupportedException("Cannot apply control choice for non enumerable property as checkbox list.");
            }

            var value  = Value as IEnumerable;
            var values = new List <string>();

            if (value != null)
            {
                values.AddRange(from object item in value select Convert.ToString(item));
            }

            IList <SelectListItem> selectItems;

            if (SelectListItems == null)
            {
                selectItems = controlForm.GetExternalDataSource(Name.RemoveBetween('[', ']'));

                if (selectItems == null)
                {
                    throw new NotSupportedException("You need to register an external data source for " + Name);
                }
            }
            else
            {
                selectItems = SelectListItems.ToList();
            }

            var cssClass = CssClass ?? "checkbox";

            var index = 0;

            var sb = new StringBuilder();

            if (GroupedByCategory)
            {
                var items  = selectItems.Cast <ExtendedSelectListItem>().ToList();
                var groups = items.GroupBy(x => x.Category);

                foreach (var @group in groups)
                {
                    sb.AppendFormat("<strong>{0}</strong>", group.Key);

                    foreach (var item in group)
                    {
                        var isChecked = values.Contains(item.Value);
                        var checkbox  = new TagBuilder("input");

                        string name = htmlHelper.ViewData.TemplateInfo.GetFullHtmlFieldName(Name);
                        checkbox.MergeAttribute("type", "checkbox");
                        checkbox.MergeAttribute("name", name);
                        checkbox.MergeAttribute("id", htmlHelper.ViewData.TemplateInfo.GetFullHtmlFieldId(Name) + "_" + index);
                        checkbox.MergeAttribute("value", item.Value);
                        if (isChecked)
                        {
                            checkbox.MergeAttribute("checked", "checked");
                        }

                        if (ReadOnly || controlForm.ReadOnly)
                        {
                            checkbox.MergeAttribute("disabled", "disabled");
                        }

                        sb.AppendFormat("<label for=\"{3}\" class=\"{2}\">{1}{0}</label>", item.Text, checkbox.ToString(TagRenderMode.SelfClosing), cssClass, name);
                        index++;
                    }
                }
            }
            else
            {
                var columns     = (Columns > 0) ? Columns : 1;
                var rows        = (int)Math.Ceiling((selectItems.Count() * 1d) / columns);
                var columnWidth = (int)Math.Ceiling(12d / columns);

                for (var i = 0; i < columns; i++)
                {
                    var items = selectItems.Skip(i * rows).Take(rows);
                    sb.AppendFormat("<div class=\"span{0}\">", columnWidth);

                    foreach (var item in items)
                    {
                        var isChecked = values.Contains(item.Value);
                        var checkbox  = new TagBuilder("input");
                        checkbox.MergeAttribute("type", "checkbox");
                        checkbox.MergeAttribute("name", htmlHelper.ViewData.TemplateInfo.GetFullHtmlFieldName(Name));
                        checkbox.MergeAttribute("id", htmlHelper.ViewData.TemplateInfo.GetFullHtmlFieldId(Name) + "_" + index);
                        checkbox.MergeAttribute("value", item.Value);
                        if (isChecked)
                        {
                            checkbox.MergeAttribute("checked", "checked");
                        }

                        if (ReadOnly || controlForm.ReadOnly)
                        {
                            checkbox.MergeAttribute("disabled", "disabled");
                        }

                        sb.AppendFormat("<label class=\"{2}\">{1}{0}</label>", item.Text, checkbox.ToString(TagRenderMode.SelfClosing), cssClass);
                        index++;
                    }

                    sb.Append("</div>");
                }
            }

            return(sb.ToString());
        }
 public PromotionEditorModel()
 {
     OtherPromotions            = new List <PromotionRowModel>();
     AvailableOverlappingUsages = SelectListItems.FromEnum(typeof(PromotionOverlappingUsage));
 }
Esempio n. 13
0
        public ActionResult Add(WxMenuModel model)
        {
            if (ModelState.IsValid)
            {
                var isOk = RunWithCatch((ms) =>
                {
                    var entity      = new WxMenu();
                    entity.Name     = model.Name;
                    entity.Content  = model.BindValue;
                    entity.Bind     = model.Bind;
                    entity.Type     = model.BindType;
                    entity.ParentId = model.ParentId;
                    entity.Sequence = model.Sequence;

                    BindType bindType = model.Bind;
                    switch (bindType)
                    {
                    case BindType.Key:
                        entity.ReplyId = model.BindValue;
                        break;

                    case BindType.Topic:
                        entity.Content = model.BindTopic;
                        break;

                    default:
                        if (bindType == BindType.Url)
                        {
                            entity.Content = model.Url;
                        }
                        break;
                    }
                    entity.Client = MenuClient.Weixin;
                    entity.Type   = "click";
                    if (entity.ParentId.IsBlank())
                    {
                        entity.Type = "view";
                    }
                    else if (entity.Bind == BindType.None)
                    {
                        ms.AddModelError("Bind", "二级菜单必须绑定一个对象");
                        return(false);
                    }

                    _repository.Insert(entity);
                    return(true);
                });

                if (isOk)
                {
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                model.BindTypes = SelectListItems.FromEnum(model.Bind).ToArray();

                model.Keywords = _wxReplyRepository.Query()
                                 .Select(x => new { x.Sequence, x.Id, x.Content })
                                 .OrderByDescending(x => x.Sequence)
                                 .ToList()
                                 .Select(x => new SelectListItem
                {
                    Value    = x.Id,
                    Text     = x.Content,
                    Selected = model.BindValue == x.Id
                }).ToArray();

                model.Topics = new SelectListItem[] { };
            }
            return(View(model));
        }
 public ByWeightShippingRulesModel()
 {
     Rules = new List <ByWeightShippingRuleModel>();
     AvailablePriceUnits = SelectListItems.FromEnum <ShippingPriceUnit>();
 }