private void ContentService_Saving(IContentService sender, SaveEventArgs <IContent> e) { var settingService = _settingsService.GetSettings(); if (settingService == null) { return; } foreach (var entity in e.SavedEntities) { var imageCroppers = entity.Properties.Where(x => x.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.Aliases.ImageCropper); foreach (Property crop in imageCroppers) { var key = string.Concat(entity.Name, "-", crop.Alias); var imageCropperInfo = _imageCropperInfoService.Get(key); var imagePath = crop.GetValue(); //Wrong object if (imageCropperInfo == null && imagePath == null) { continue; } //Cropped file was Deleted if (imageCropperInfo != null && imagePath == null) { _imageCropperInfoService.DeleteImageFromImageCropper(key, imageCropperInfo); continue; } var json = JObject.Parse(imagePath.ToString()); var path = json.GetValue("src").ToString(); //republish existed content if (imageCropperInfo != null && imageCropperInfo.ImageId == path) { continue; } //Cropped file was created or updated _imageCropperInfoService.GetCropImagesAndTinify(key, imageCropperInfo, imagePath, settingService.EnableOptimizationOnUpload, path); } } }