DDS deleting post

Vote:
 

Hi!

I've been testing Dynamic Data Store for the first time following this guide:

http://roland.kierkels.net/episerver/storing-data-using-episerver-7-5-dynamic-data-store/

I have run into problems when trying to delete a post. I have this method in my class (Comments):

/// 
/// Delete the comment permanently
/// 
/// 
public static void Delete(Comment comment)
{

     // Create a data store (but only if one doesn't exist, we won't overwrite an existing one)
     var store = DynamicDataStoreFactory.Instance.CreateStore(typeof(Comment));
 
     // Delete the specified comment
     store.Delete(comment.Id);

}

I have also created a UserControl (Comment) which contains a simple form for adding posts and displaying them. It works... I would also like to add a "Delete" button to each post which should of course delete the post. So I would like to call the method Delete from the UserControl. I just can't figure out how to send the whole object to the method. At the moment I'm using asp:LinkButton which triggers DeleteClick:

protected void DeleteClick(object sender, EventArgs e)
{

//?? Here I've been trying to call the method Delete in different ways (trying to send the object Comments) with no success

}



Thankful for help!

#120434
Apr 16, 2015 17:09
Vote:
 

Hi,

try using the following extension method when you need to get the store.

var store = DynamicDataStoreFactory.Instance.GetOrCreateStore(typeof(Comment));

A link to the SDK

/Marcus

#120442
Apr 17, 2015 7:59
Vote:
 

I'm triggering DeleteClick in my UserControl and how do I pass the object (comment) to the Delete method?

In UserControl:

protected void DeleteClick(object sender, EventArgs e)

{
Comments.Delete(?);
}



Delete in Comments class:

public static void Delete(Comments comment)
{

// Create a data store (but only if one doesn't exist, we won't overwrite an existing one)
var store = DynamicDataStoreFactory.Instance.CreateStore(typeof(Comments));

// Delete the specified comment
store.Delete(comment.Id);

}



#120443
Apr 17, 2015 8:55
Vote:
 

You should bind the comment Id to the comment control, and when user clicks "delete", you can get back the Id and delete it. You don't have to submit the comment object to the function.

#120447
Apr 17, 2015 10:36
Vote:
 

Thank you! Yes, I managed to solve it like this:

In UserControl:

protected void DeleteClick(object sender, CommandEventArgs args)
{
Comments.Delete(args.CommandArgument.ToString());
ListaKommentarer();
}


In Comments class:

public static void Delete(String id)
{
// Create a data store (but only if one doesn't exist, we won't overwrite an existing one)
var store = DynamicDataStoreFactory.Instance.CreateStore(typeof(Comments));
store.Delete(Identity.Parse(id));

}



#120448
Apr 17, 2015 10:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.