public async Task <BulkActionResult> UpdatePropertiesAsync(CatalogProduct[] products, Property[] properties) { var result = new BulkActionResult { Succeeded = true }; var hasChanges = false; if (products.IsNullOrEmpty()) { // idle } else { hasChanges = TryChangeProductPropertyValues(properties, products, result); } if (hasChanges) { await _itemService.SaveChangesAsync(products); } return(result); }
public BulkActionResult UpdateProperties(CatalogProduct[] products, CatalogModule.Property[] properties) { var result = new BulkActionResult { Succeeded = true }; var hasChanges = false; if (products.IsNullOrEmpty()) { // idle } else { hasChanges = TryChangeProductPropertyValues(properties, products, result); } if (hasChanges) { _itemService.Update(products); } return(result); }
private bool TryChangeProductPropertyValues( Property[] properties, IEnumerable <CatalogProduct> products, BulkActionResult result) { var hasChanges = false; foreach (var product in products) { try { foreach (var property in properties) { if (string.IsNullOrEmpty(property.Id)) { if (string.IsNullOrEmpty(property.Name)) { continue; } hasChanges = TrySetOwnProperty(product, property) || hasChanges; } else { hasChanges = TrySetCustomProperty(product, property) || hasChanges; } } } catch (Exception e) { result.Succeeded = false; result.Errors.Add(e.Message); } } return(hasChanges); }