Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm using the ContentService but am not sure where I can hook in to update a property value and have it save.. I'm doing the following:
public class RegisterCustomEvents : ApplicationEventHandler { protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { base.ApplicationStarted(umbracoApplication, applicationContext); ContentService.Saving += ContentService_Saving; } void ContentService_Saving(IContentService sender, Umbraco.Core.Events.SaveEventArgs<IContent> e) { GeolocateStockists(sender, e.SavedEntities); } void GeolocateStockists(IContentService contentService, IEnumerable<IContent> savedEntities) { if (savedEntities != null) { var stockists = savedEntities.Where(s => s.ContentType.Alias == StockistDocTypeAlias); if (stockists.Any()) { foreach (var stockist in stockists) { var addressProperty = stockist.Properties[StockistAddressPropertyName]; var address = addressProperty != null ? addressProperty.Value.ToString() : ""; if (!string.IsNullOrWhiteSpace(address)) { var geoResult = GoogleGeoCoder.GetLocationFromGoogleMaps(address); if (geoResult.Results.Any()) { stockist.SetValue(StockistLatLongPropertyName, geoResult.Results[0].Geometry.Location.Lat.ToString(Utility.NumberFormatInfo) + "," + geoResult.Results[0].Geometry.Location.Lng.ToString(Utility.NumberFormatInfo) + ",13"); } } } } } } const string StockistDocTypeAlias = "Stockist"; const string StockistAddressPropertyName = "stockistAddress"; const string StockistLatLongPropertyName = "latLong"; }
Unfortunately the new value isn't saved to the content item. Just wondering what I'm missing
I tried caling contentService.Save(stockist) without success after the call to SetValue
Thanks,
Tom
Hello,
Maybe this topic can help: http://our.umbraco.org/forum/developers/api-questions/42394-AbstractDataEditor-OnSave-in-Umbraco-61
Jeroen
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Save/Publish Events Not Updating Values
I'm using the ContentService but am not sure where I can hook in to update a property value and have it save.. I'm doing the following:
Unfortunately the new value isn't saved to the content item. Just wondering what I'm missing
I tried caling contentService.Save(stockist) without success after the call to SetValue
Thanks,
Tom
Hello,
Maybe this topic can help: http://our.umbraco.org/forum/developers/api-questions/42394-AbstractDataEditor-OnSave-in-Umbraco-61
Jeroen
is working on a reply...