/// <summary> /// ƒобавл¤ет продукту новое несуществующее свойство /// </summary> /// <remarks></remarks> protected void AddNewPropertyWithValue(string propName, string propVal, int sortOrder) { if (Page.Request["productid"] != null) { try { PropertyService.AddProductProperyValue( PropertyService.AddPropertyValue(new PropertyValue { PropertyId = PropertyService.AddProperty(new Property { Name = propName, UseInFilter = true, UseInDetails = true, Type = 1 }), Value = propVal, SortOrder = sortOrder }), ProductId, sortOrder); } catch (Exception ex) { Debug.LogError(ex); Msg("Unable to add property with value"); } cboPropertyName.DataBind(); } }
public void SaveProperties() { try { var propValues = new List <int>(); var temp = hfpropresult.Value.Split(','); foreach (var elem in temp) { int value; if (int.TryParse(elem, out value)) { propValues.Add(value); } } var currentPropValues = PropertyService.GetPropertyValuesByProductId(ProductId).Select(p => p.PropertyValueId).ToList(); var newAddedPropValues = hfnewpropresult.Value.Trim(); if (propValues == currentPropValues && newAddedPropValues.IsNullOrEmpty()) { return; } var propValuesToAdd = propValues.Where(v => !currentPropValues.Contains(v)); var propValuesToDelete = currentPropValues.Where(v => !propValues.Contains(v)); foreach (var propValueId in propValuesToAdd) { PropertyService.AddProductProperyValue(propValueId, ProductId, 0); } foreach (var propValueId in propValuesToDelete) { PropertyService.DeleteProductPropertyValue(ProductId, propValueId); } var newPropValues = JsonConvert.DeserializeObject <List <PropertyValue> >(hfnewpropresult.Value); foreach (var newPropValue in newPropValues) { AddNewPropertyValue(newPropValue.PropertyId, newPropValue.Value, 0); } } catch (Exception ex) { Debug.LogError(ex); } }