private static IHtmlContentBuilder ListItemToOptionForExtendedListItem(ExtendedSelectListItem item, bool selectedValue) { TagBuilder builder = new TagBuilder("option"); builder.Attributes["value"] = item.Value; if (selectedValue) { builder.Attributes["selected"] = "selected"; } if (item.AdditionalDataAttribute != null) { builder.Attributes["data-additional"] = item.AdditionalDataAttribute; } builder.InnerHtml.Append(item.Text); return(new HtmlContentBuilder().AppendHtml(builder)); }
public static String ListItemToOption(ExtendedSelectListItem item) { var builder = new TagBuilder("option") { InnerHtml = HttpUtility.HtmlEncode(item.Text) }; if (item.Value != null) { builder.Attributes["value"] = item.Value; builder.Attributes["id"] = item.Value; } if (item.Selected) { builder.Attributes["selected"] = "selected"; } builder.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(item.htmlAttributes)); return builder.ToString(TagRenderMode.Normal); }
protected void prepareModelLists(OrcamentoViewModel model) { Dictionary <String, object> dictHtmlAtt = new Dictionary <string, object>(); dictHtmlAtt.Add("data-value", 0.0); dictHtmlAtt.Add("data-min-value", 0.0); dictHtmlAtt.Add("data-max-value", 0.0); ExtendedSelectListItem firstItem = new ExtendedSelectListItem() { Value = "", Text = "", htmlAttributes = dictHtmlAtt }; model.Equipamentos = EquipamentoService.getEquipamentos(1).Select(c => { double precoMedio = Math.Round((c.PrecoMaximo + c.PrecoMinimo) / 2, 2); dictHtmlAtt = new Dictionary <string, object>(); dictHtmlAtt.Add("data-value", precoMedio); dictHtmlAtt.Add("data-min-value", c.PrecoMinimo); dictHtmlAtt.Add("data-max-value", c.PrecoMaximo); return(new ExtendedSelectListItem() { Value = c.IDEquipamento.ToString(), Text = c.Descricao, htmlAttributes = dictHtmlAtt }); }).ToList(); model.Equipamentos.Insert(0, firstItem); Dictionary <int, String> dictValores = EnumHelper.getDictionaryValueDescription(TiposTransporte.Correios); model.TiposTransporte = dictValores.Select(c => new SelectListItem() { Value = c.Key.ToString(), Text = c.Value }).ToList(); model.TiposTransporte.Insert(0, firstItem); model.FormasPagamento.Add(firstItem); for (int i = 1; i <= 10; i++) { model.FormasPagamento.Add(new SelectListItem() { Text = i + "x", Value = i.ToString() }); } }
protected List <ExtendedSelectListItem> GetServicosByEquipamento(int idEquipamento) { var servicos = ServicoService.getServicosByEquipamento(idEquipamento); var opcoesServicos = new List <ExtendedSelectListItem>(); foreach (var servico in servicos) { var opcaoServico = new ExtendedSelectListItem() { Text = servico.Descricao.ToUpper(), Value = servico.IDServico.ToString(), }; var equipamentoServico = EquipamentoService.getEquipamentoServico(idEquipamento, servico.IDServico); var dictHtmlAtt = new Dictionary <string, object>(); dictHtmlAtt.Add("data-value", Math.Round((equipamentoServico.PrecoMaximo + equipamentoServico.PrecoMinimo) / 2, 2)); dictHtmlAtt.Add("data-min-value", equipamentoServico.PrecoMinimo); dictHtmlAtt.Add("data-max-value", equipamentoServico.PrecoMaximo); opcaoServico.htmlAttributes = dictHtmlAtt; opcoesServicos.Add(opcaoServico); } return(opcoesServicos); }
private void PrepareModel(RuleSetModel model, RuleSetEntity entity, RuleScope?scope = null) { var scopes = (entity?.Scope ?? scope ?? RuleScope.Cart).ToSelectList(); model.Scopes = scopes .Select(x => { var item = new ExtendedSelectListItem { Value = x.Value, Text = x.Text, Selected = x.Selected }; var ruleScope = (RuleScope)x.Value.ToInt(); item.CustomProperties["Description"] = ruleScope.GetLocalizedEnum(Services.Localization, Services.WorkContext, true); return(item); }) .ToList(); if ((entity?.Id ?? 0) != 0) { var provider = _ruleProvider(entity.Scope); model.ScopeName = entity.Scope.GetLocalizedEnum(Services.Localization, Services.WorkContext); model.ExpressionGroup = _ruleFactory.CreateExpressionGroup(entity, provider, true); model.AssignedToDiscounts = entity.Discounts .Select(x => new RuleSetModel.AssignedToEntityModel { Id = x.Id, Name = x.Name.NullEmpty() ?? x.Id.ToString() }) .ToList(); model.AssignedToShippingMethods = entity.ShippingMethods .Select(x => new RuleSetModel.AssignedToEntityModel { Id = x.Id, Name = x.GetLocalized(y => y.Name) }) .ToList(); var paymentMethods = entity.PaymentMethods; if (paymentMethods.Any()) { var paymentProviders = _paymentService.Value.LoadAllPaymentMethods().ToDictionarySafe(x => x.Metadata.SystemName); model.AssignedToPaymentMethods = paymentMethods .Select(x => { string friendlyName = null; if (paymentProviders.TryGetValue(x.PaymentMethodSystemName, out var paymentProvider)) { friendlyName = _pluginMediator.Value.GetLocalizedFriendlyName(paymentProvider.Metadata); } return(new RuleSetModel.AssignedToEntityModel { Id = x.Id, Name = friendlyName.NullEmpty() ?? x.PaymentMethodSystemName, SystemName = x.PaymentMethodSystemName }); }) .ToList(); } model.AssignedToCustomerRoles = entity.CustomerRoles .Select(x => new RuleSetModel.AssignedToEntityModel { Id = x.Id, Name = x.Name }) .ToList(); model.AssignedToCategories = entity.Categories .Select(x => new RuleSetModel.AssignedToEntityModel { Id = x.Id, Name = x.GetLocalized(y => y.Name) }) .ToList(); } }
protected void prepareModelLists(OrcamentoViewModel model) { Dictionary<String, object> dictHtmlAtt = new Dictionary<string, object>(); dictHtmlAtt.Add("data-value", 0.0); dictHtmlAtt.Add("data-min-value", 0.0); dictHtmlAtt.Add("data-max-value", 0.0); ExtendedSelectListItem firstItem = new ExtendedSelectListItem() { Value = "", Text = "", htmlAttributes = dictHtmlAtt }; model.Equipamentos = EquipamentoService.getEquipamentos(1).Select(c => { double precoMedio = Math.Round((c.PrecoMaximo + c.PrecoMinimo) / 2, 2); dictHtmlAtt = new Dictionary<string, object>(); dictHtmlAtt.Add("data-value", precoMedio); dictHtmlAtt.Add("data-min-value", c.PrecoMinimo); dictHtmlAtt.Add("data-max-value", c.PrecoMaximo); return new ExtendedSelectListItem() { Value = c.IDEquipamento.ToString(), Text = c.Descricao, htmlAttributes = dictHtmlAtt }; }).ToList(); model.Equipamentos.Insert(0, firstItem); Dictionary<int, String> dictValores = EnumHelper.getDictionaryValueDescription(TiposTransporte.Correios); model.TiposTransporte = dictValores.Select(c => new SelectListItem() { Value = c.Key.ToString(), Text = c.Value }).ToList(); model.TiposTransporte.Insert(0, firstItem); model.FormasPagamento.Add(firstItem); for (int i = 1; i <= 10; i++) { model.FormasPagamento.Add(new SelectListItem() { Text = i + "x", Value = i.ToString() }); } }
protected List<ExtendedSelectListItem> GetServicosByEquipamento(int idEquipamento) { var servicos = ServicoService.getServicosByEquipamento(idEquipamento); var opcoesServicos = new List<ExtendedSelectListItem>(); foreach (var servico in servicos) { var opcaoServico = new ExtendedSelectListItem() { Text = servico.Descricao.ToUpper(), Value = servico.IDServico.ToString(), }; var equipamentoServico = EquipamentoService.getEquipamentoServico(idEquipamento, servico.IDServico); var dictHtmlAtt = new Dictionary<string, object>(); dictHtmlAtt.Add("data-value", Math.Round((equipamentoServico.PrecoMaximo + equipamentoServico.PrecoMinimo) / 2, 2)); dictHtmlAtt.Add("data-min-value", equipamentoServico.PrecoMinimo); dictHtmlAtt.Add("data-max-value", equipamentoServico.PrecoMaximo); opcaoServico.htmlAttributes = dictHtmlAtt; opcoesServicos.Add(opcaoServico); } return opcoesServicos; }