public virtual IActionResult Edit(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) return AccessDeniedView(); //try to get a vendor attribute with the specified id var vendorAttribute = _vendorAttributeService.GetVendorAttributeById(id); if (vendorAttribute == null) return RedirectToAction("List"); //prepare model var model = _vendorAttributeModelFactory.PrepareVendorAttributeModel(null, vendorAttribute); return View(model); }
//edit public virtual IActionResult Edit(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) { return(AccessDeniedView()); } var vendorAttribute = _vendorAttributeService.GetVendorAttributeById(id); if (vendorAttribute == null) { //No vendor attribute found with the specified id return(RedirectToAction("List")); } var model = vendorAttribute.ToModel(); //locales AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Name = vendorAttribute.GetLocalized(x => x.Name, languageId, false, false); }); return(View(model)); }
/// <summary> /// Gets vendor attributes from XML /// </summary> /// <param name="attributesXml">Attributes in XML format</param> /// <returns>List of vendor attributes</returns> public virtual IList <VendorAttribute> ParseVendorAttributes(string attributesXml) { var result = new List <VendorAttribute>(); if (string.IsNullOrEmpty(attributesXml)) { return(result); } var ids = ParseVendorAttributeIds(attributesXml); foreach (var id in ids) { var attribute = _vendorAttributeService.GetVendorAttributeById(id); if (attribute != null) { result.Add(attribute); } } return(result); }
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); }