Delete Comments Rendered via ajax call

Topics: Customizing Orchard
Oct 17, 2012 at 2:49 PM

I have comments part attached to a blog..when a comment is submitted i display it in the page via a ajax call after storing it in the database..

I also have a delete button attached to each comment..this delete works fine for all the comments except the ones which are just submitted via an ajax call..It worksonly when  the page is refreshed..

Your help is appreciated..

Thanks in advance

 

 

 

Coordinator
Oct 17, 2012 at 5:47 PM

You might need to call contentManager.Flush() to have those changes into the db before executing a select query.

Aug 6, 2013 at 1:45 PM
What would you suggest today, Sebastien, with ContentManager.Flush() having been removed?

I'm having a problem in a situation where I used to use ContentManager.Flush() but now my code broke without that call.

Any advice?
Developer
Aug 6, 2013 at 2:20 PM
Flush has been removed as the SessonLocator and Transaction Manager have been rewritten. You no longer need flush and can remove it.
Aug 6, 2013 at 2:32 PM
Edited Aug 6, 2013 at 6:38 PM
Thanks, Nick, for clarifying. Unfortunately, in my code block the expected UPDATE statement never reaches the DB. I'm calling this (EDIT: this is a call across AppDomains, called from a test assembly, executed in the Application Under Test's AppDomain):
Context.CodeExecutor.Execute<ILifetimeScope>(
    ls => {
        var contentManager = ls.Resolve<IContentManager>();
        var defaultEntry = contentManager.Get(entryId);
        var defaultEntryPart = defaultEntry.Parts
                                .Single(p => p.PartDefinition.Name == "EntryPart");
        var portalConfiguration = ls.Resolve<IPortalConfigurationReaderWriter>()
                                .ReadPortalConfiguration();

        foreach (var propertyNameAndValue in propertyNamesAndValues) {
            var propertyInfo = defaultEntryPart.GetType()
                                .GetProperty(propertyNameAndValue.Key);
            var propertyType = portalConfiguration.DetailPageConfiguration
                                .GetProperty(propertyNameAndValue.Key).PropertyType;

            if (string.IsNullOrEmpty(propertyNameAndValue.Value)) {
                propertyInfo.SetValue(defaultEntryPart, null, null);
            }
        }
        // used to call contentManager.Flush() here
    });
In NHProf I can see the session and the SessionLocator.Dispose() method being called but like I said, no changes are sent to the DB. Could this be a problem of using Reflection for setting property values? But how else could I do that knowing neither the property's name nor the value's type beforehand?

UPDATE: Does not seem to be related to Reflection. Setting a part's property directly also doesn't persist. Tried this:
        ((dynamic) defaultEntryPart).Town = "BERLIN";
Coordinator
Aug 6, 2013 at 7:43 PM
Having to call flush is usually a smell. That simple properties don't persist is another. Did you check for exceptions after this that would rollback the transaction?