I am using the ApplicationEventHandler to bind the ContentService Saved method to some custom logic that saves a custom property editor's data into a custom database table. Everything is working fine in the custom table side. But I wonder if it is possible to ignore the normal process and not save the data into the cmsPropertyData table.
This is my code:
using Newtonsoft.Json;
using System.Linq;
using Tigerbay.Cms.Umbraco.CV.Core.Controllers;
using Tigerbay.Cms.Umbraco.CV.Core.Models;
using Umbraco.Core;
using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Umbraco.Core.Publishing;
using Umbraco.Core.Services;
namespace Tigerbay.Cms.Umbraco.CV.Core.Services
{
/// <summary>
/// Hooks up all the necessary events into the current assembly / logic
/// </summary>
public class HookupEventsService : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
//hockup events to allow saving and deleting villa information
ContentService.EmptyingRecycleBin += ContentService_EmptyingRecycleBin;
ContentService.Deleted += ContentService_Deleted;
ContentService.Saved += ContentService_Saved;
}
private void ContentService_Deleted(IContentService sender, DeleteEventArgs<IContent> e)
{
foreach (var deleted in e.DeletedEntities)
SaveOrDeleteNode(deleted, Process.Delete);
}
private void ContentService_EmptyingRecycleBin(IContentService sender, RecycleBinEventArgs e)
{
foreach (var id in e.Ids)
{
var deleted = sender.GetById(id);
SaveOrDeleteNode(deleted, Process.Delete);
}
}
private void ContentService_Saved(IContentService sender, SaveEventArgs<IContent> e)
{
foreach (var node in e.SavedEntities)
SaveOrDeleteNode(node, Process.Save);
// can I ignore the normal saving process,
// maybe with the ContentService_Saving method
//(but I need the NodeID, that is why the logic is currently in the Saved method)
}
private void SaveOrDeleteNode(IContent node, Process process)
{
if (node.ContentType.Alias == "tigerbayVilla")
{
var villaNode = node.Properties.SingleOrDefault(x => x.Alias == "tigerbayVillaDetails");
if (villaNode.Value != null)
{
using (var srv = new VillasSurfaceController())
{
var json = villaNode.Value.ToString();
Villas villa = JsonConvert.DeserializeObject<Villas>(json);
if (villa.NodeId == 0) villa.NodeId = node.Id;
switch (process)
{
case Process.Save:
srv.SaveVilla(villa);
break;
case Process.Delete:
srv.DeleteVilla(villa.NodeId);
break;
}
}
}
}
}
protected internal enum Process
{
Save,
Delete
}
}
}
I want to avoid cluttering the Umbraco cmsPropertyData table with stuff that will never be used.
Do not save into cmsPropertyData
I am using the ApplicationEventHandler to bind the ContentService Saved method to some custom logic that saves a custom property editor's data into a custom database table. Everything is working fine in the custom table side. But I wonder if it is possible to ignore the normal process and not save the data into the cmsPropertyData table.
This is my code:
I want to avoid cluttering the Umbraco cmsPropertyData table with stuff that will never be used.
Does anyone have any clues on this????
is working on a reply...