/// <summary> /// Prepare paged vendor attribute value list model /// </summary> /// <param name="searchModel">Vendor attribute value search model</param> /// <param name="vendorAttribute">Vendor attribute</param> /// <returns>Vendor attribute value list model</returns> public virtual VendorAttributeValueListModel PrepareVendorAttributeValueListModel(VendorAttributeValueSearchModel searchModel, VendorAttribute vendorAttribute) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (vendorAttribute == null) { throw new ArgumentNullException(nameof(vendorAttribute)); } //get vendor attribute values var vendorAttributeValues = _vendorAttributeService.GetVendorAttributeValues(vendorAttribute.Id); //prepare list model var model = new VendorAttributeValueListModel { //fill in model values from the entity Data = vendorAttributeValues.PaginationByRequestModel(searchModel).Select(value => value.ToModel <VendorAttributeValueModel>()), Total = vendorAttributeValues.Count }; return(model); }
/// <summary> /// Prepare paged vendor attribute value list model /// </summary> /// <param name="searchModel">Vendor attribute value search model</param> /// <param name="vendorAttribute">Vendor attribute</param> /// <returns>Vendor attribute value list model</returns> public virtual VendorAttributeValueListModel PrepareVendorAttributeValueListModel(VendorAttributeValueSearchModel searchModel, VendorAttribute vendorAttribute) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (vendorAttribute == null) { throw new ArgumentNullException(nameof(vendorAttribute)); } //get vendor attribute values var vendorAttributeValues = _vendorAttributeService.GetVendorAttributeValues(vendorAttribute.Id).ToPagedList(searchModel); //prepare list model var model = new VendorAttributeValueListModel().PrepareToGrid(searchModel, vendorAttributeValues, () => { //fill in model values from the entity return(vendorAttributeValues.Select(value => value.ToModel <VendorAttributeValueModel>())); }); return(model); }
public virtual IActionResult ValueList(int vendorAttributeId, DataSourceRequest command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) { return(AccessDeniedKendoGridJson()); } var values = _vendorAttributeService.GetVendorAttributeValues(vendorAttributeId); var gridModel = new DataSourceResult { Data = values.Select(x => new VendorAttributeValueModel { Id = x.Id, VendorAttributeId = x.VendorAttributeId, Name = x.Name, IsPreSelected = x.IsPreSelected, DisplayOrder = x.DisplayOrder, }), Total = values.Count() }; return(Json(gridModel)); }
/// <summary> /// Prepare vendor attribute models /// </summary> /// <param name="vendorAttributesXml">Vendor attributes in XML format</param> /// <returns>List of the vendor attribute model</returns> protected virtual IList <VendorAttributeModel> PrepareVendorAttributes(string vendorAttributesXml) { var result = new List <VendorAttributeModel>(); var vendorAttributes = _vendorAttributeService.GetAllVendorAttributes(); foreach (var attribute in vendorAttributes) { var attributeModel = new VendorAttributeModel { Id = attribute.Id, Name = _localizationService.GetLocalized(attribute, x => x.Name), IsRequired = attribute.IsRequired, AttributeControlType = attribute.AttributeControlType, }; if (attribute.ShouldHaveValues()) { //values var attributeValues = _vendorAttributeService.GetVendorAttributeValues(attribute.Id); foreach (var attributeValue in attributeValues) { var valueModel = new VendorAttributeValueModel { Id = attributeValue.Id, Name = _localizationService.GetLocalized(attributeValue, x => x.Name), IsPreSelected = attributeValue.IsPreSelected }; attributeModel.Values.Add(valueModel); } } switch (attribute.AttributeControlType) { case AttributeControlType.DropdownList: case AttributeControlType.RadioList: case AttributeControlType.Checkboxes: { if (!string.IsNullOrEmpty(vendorAttributesXml)) { //clear default selection foreach (var item in attributeModel.Values) { item.IsPreSelected = false; } //select new values var selectedValues = _vendorAttributeParser.ParseVendorAttributeValues(vendorAttributesXml); foreach (var attributeValue in selectedValues) { foreach (var item in attributeModel.Values) { if (attributeValue.Id == item.Id) { item.IsPreSelected = true; } } } } } break; case AttributeControlType.ReadonlyCheckboxes: { //do nothing //values are already pre-set } break; case AttributeControlType.TextBox: case AttributeControlType.MultilineTextbox: { if (!string.IsNullOrEmpty(vendorAttributesXml)) { var enteredText = _vendorAttributeParser.ParseValues(vendorAttributesXml, attribute.Id); if (enteredText.Any()) { attributeModel.DefaultValue = enteredText[0]; } } } break; case AttributeControlType.ColorSquares: case AttributeControlType.ImageSquares: case AttributeControlType.Datepicker: case AttributeControlType.FileUpload: default: //not supported attribute control types break; } result.Add(attributeModel); } return(result); }
protected virtual string ParseVendorAttributes(IFormCollection form) { if (form == null) { throw new ArgumentNullException(nameof(form)); } var attributesXml = string.Empty; var vendorAttributes = _vendorAttributeService.GetAllVendorAttributes(); foreach (var attribute in vendorAttributes) { var controlId = $"{NopAttributePrefixDefaults.Vendor}{attribute.Id}"; StringValues ctrlAttributes; switch (attribute.AttributeControlType) { case AttributeControlType.DropdownList: case AttributeControlType.RadioList: ctrlAttributes = form[controlId]; if (!StringValues.IsNullOrEmpty(ctrlAttributes)) { var selectedAttributeId = int.Parse(ctrlAttributes); if (selectedAttributeId > 0) { attributesXml = _vendorAttributeParser.AddVendorAttribute(attributesXml, attribute, selectedAttributeId.ToString()); } } break; case AttributeControlType.Checkboxes: var cblAttributes = form[controlId]; if (!StringValues.IsNullOrEmpty(cblAttributes)) { foreach (var item in cblAttributes.ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { var selectedAttributeId = int.Parse(item); if (selectedAttributeId > 0) { attributesXml = _vendorAttributeParser.AddVendorAttribute(attributesXml, attribute, selectedAttributeId.ToString()); } } } break; case AttributeControlType.ReadonlyCheckboxes: //load read-only (already server-side selected) values var attributeValues = _vendorAttributeService.GetVendorAttributeValues(attribute.Id); foreach (var selectedAttributeId in attributeValues .Where(v => v.IsPreSelected) .Select(v => v.Id) .ToList()) { attributesXml = _vendorAttributeParser.AddVendorAttribute(attributesXml, attribute, selectedAttributeId.ToString()); } break; case AttributeControlType.TextBox: case AttributeControlType.MultilineTextbox: ctrlAttributes = form[controlId]; if (!StringValues.IsNullOrEmpty(ctrlAttributes)) { var enteredText = ctrlAttributes.ToString().Trim(); attributesXml = _vendorAttributeParser.AddVendorAttribute(attributesXml, attribute, enteredText); } break; case AttributeControlType.Datepicker: case AttributeControlType.ColorSquares: case AttributeControlType.ImageSquares: case AttributeControlType.FileUpload: //not supported vendor attributes default: break; } } return(attributesXml); }
/// <summary> /// Prepare vendor attribute models /// </summary> /// <param name="models">List of vendor attribute models</param> /// <param name="vendor">Vendor</param> protected virtual void PrepareVendorAttributeModels(IList <VendorModel.VendorAttributeModel> models, Vendor vendor) { if (models == null) { throw new ArgumentNullException(nameof(models)); } //get available vendor attributes var vendorAttributes = _vendorAttributeService.GetAllVendorAttributes(); foreach (var attribute in vendorAttributes) { var attributeModel = new VendorModel.VendorAttributeModel { Id = attribute.Id, Name = attribute.Name, IsRequired = attribute.IsRequired, AttributeControlType = attribute.AttributeControlType }; if (attribute.ShouldHaveValues()) { //values var attributeValues = _vendorAttributeService.GetVendorAttributeValues(attribute.Id); foreach (var attributeValue in attributeValues) { var attributeValueModel = new VendorModel.VendorAttributeValueModel { Id = attributeValue.Id, Name = attributeValue.Name, IsPreSelected = attributeValue.IsPreSelected }; attributeModel.Values.Add(attributeValueModel); } } //set already selected attributes if (vendor != null) { var selectedVendorAttributes = _genericAttributeService.GetAttribute <string>(vendor, NopVendorDefaults.VendorAttributes); switch (attribute.AttributeControlType) { case AttributeControlType.DropdownList: case AttributeControlType.RadioList: case AttributeControlType.Checkboxes: { if (!string.IsNullOrEmpty(selectedVendorAttributes)) { //clear default selection foreach (var item in attributeModel.Values) { item.IsPreSelected = false; } //select new values var selectedValues = _vendorAttributeParser.ParseVendorAttributeValues(selectedVendorAttributes); foreach (var attributeValue in selectedValues) { foreach (var item in attributeModel.Values) { if (attributeValue.Id == item.Id) { item.IsPreSelected = true; } } } } } break; case AttributeControlType.ReadonlyCheckboxes: { //do nothing //values are already pre-set } break; case AttributeControlType.TextBox: case AttributeControlType.MultilineTextbox: { if (!string.IsNullOrEmpty(selectedVendorAttributes)) { var enteredText = _vendorAttributeParser.ParseValues(selectedVendorAttributes, attribute.Id); if (enteredText.Any()) { attributeModel.DefaultValue = enteredText[0]; } } } break; case AttributeControlType.Datepicker: case AttributeControlType.ColorSquares: case AttributeControlType.ImageSquares: case AttributeControlType.FileUpload: default: //not supported attribute control types break; } } models.Add(attributeModel); } }
public string ConvertToXml(List <VendorItemAttributeDto> attributeDtos, int vendorId) { var attributesXml = ""; if (attributeDtos == null) { return(attributesXml); } var vendorAttributes = _vendorAttributeService.GetVendorAttributeById(vendorId); var list = new List <VendorAttribute>(); list.Add(vendorAttributes); foreach (var attribute in list) { switch (attribute.AttributeControlType) { case AttributeControlType.DropdownList: case AttributeControlType.RadioList: case AttributeControlType.ColorSquares: case AttributeControlType.ImageSquares: { // there should be only one selected value for this attribute var selectedAttribute = attributeDtos.Where(x => x.Id == attribute.Id).FirstOrDefault(); if (selectedAttribute != null) { int selectedAttributeValue; var isInt = int.TryParse(selectedAttribute.Value, out selectedAttributeValue); if (isInt && selectedAttributeValue > 0) { attributesXml = _vendorAttributeParser.AddVendorAttribute(attributesXml, attribute, selectedAttributeValue.ToString()); } } } break; case AttributeControlType.Checkboxes: { // there could be more than one selected value for this attribute var selectedAttributes = attributeDtos.Where(x => x.Id == attribute.Id); foreach (var selectedAttribute in selectedAttributes) { int selectedAttributeValue; var isInt = int.TryParse(selectedAttribute.Value, out selectedAttributeValue); if (isInt && selectedAttributeValue > 0) { // currently there is no support for attribute quantity var quantity = 1; //attributesXml = _vendorAttributeParser.AddVendorAttribute(attributesXml, // attribute, selectedAttributeValue.ToString(), quantity); } } } break; case AttributeControlType.ReadonlyCheckboxes: { //load read-only(already server - side selected) values var attributeValues = _vendorAttributeService.GetVendorAttributeValues(attribute.Id); foreach (var selectedAttributeId in attributeValues .Where(v => v.IsPreSelected) .Select(v => v.Id) .ToList()) { attributesXml = _vendorAttributeParser.AddVendorAttribute(attributesXml, attribute, selectedAttributeId.ToString()); } } break; case AttributeControlType.TextBox: case AttributeControlType.MultilineTextbox: { var selectedAttribute = attributeDtos.Where(x => x.Id == attribute.Id).FirstOrDefault(); if (selectedAttribute != null) { attributesXml = _vendorAttributeParser.AddVendorAttribute(attributesXml, attribute, selectedAttribute.Value); } } break; case AttributeControlType.Datepicker: { var selectedAttribute = attributeDtos.Where(x => x.Id == attribute.Id).FirstOrDefault(); if (selectedAttribute != null) { DateTime selectedDate; // Since nopCommerce uses this format to keep the date in the database to keep it consisten we will expect the same format to be passed var validDate = DateTime.TryParseExact(selectedAttribute.Value, "D", CultureInfo.CurrentCulture, DateTimeStyles.None, out selectedDate); if (validDate) { attributesXml = _vendorAttributeParser.AddVendorAttribute(attributesXml, attribute, selectedDate.ToString("D")); } } } break; case AttributeControlType.FileUpload: { var selectedAttribute = attributeDtos.Where(x => x.Id == attribute.Id).FirstOrDefault(); if (selectedAttribute != null) { Guid downloadGuid; Guid.TryParse(selectedAttribute.Value, out downloadGuid); var download = _downloadService.GetDownloadByGuid(downloadGuid); if (download != null) { attributesXml = _vendorAttributeParser.AddVendorAttribute(attributesXml, attribute, download.DownloadGuid.ToString()); } } } break; default: break; } } // No Gift Card attributes support yet return(attributesXml); }