tags:

views:

112

answers:

3

Here is what I am trying to do. Pay close attention to the InsertConlogEntry and how I am trying to assign it to my DelegateCommand, but, how do I handle the return int?

Thank you,

   #region Members        
    public static readonly string AddConlogEntry = "AddConlogEntry";
    public static readonly string GetConlogList = "GetConlogList";
    public static readonly string GetConlogEntry = "GetConlogEntry";            
    public static readonly string Scope = "ConLog";
    #endregion

    #region Ctor
    public ConLogCommands() :base()
    {
        scope = Scope;

        DelegateCommand<ConlogEntryData> AddEntryCmd = new DelegateCommand<ConlogEntryData>("Add New Conlog Entry",
            "AddConLogEntry", InsertConlogEntry);            
        this.Add(AddEntryCmd);
    }
    #endregion

    #region Methods
    private int InsertConlogEntry(ConlogEntryData data)
    {
        ConlogService service = new ConlogService();
        return service.InsertConlogEntry(data.LoanNumber, data.UserId, data.Subject, data.Comment, data.EntryDate);
    }
A: 

You can't. It only takes an Action<T>.

Matthew Flaschen
Thank you all, I resolved it by passing by ref a data structure that has a field that then I populate with the returned value from the database insert (record unique id). I appreciate the answers. El Matador
ElMatador
A: 

Not without defining your own version of DelegateCommand<T> that accepts a Func<T, int> as a constructor parameter rather than a simple Action<T>.

Since the command itself doesn't care about the return value, you can initialize it like this:

AddEntryCmd = new DelegateCommand<ConlogEntryData>("Add New Conlog Entry",
    "AddConLogEntry", e => InsertConlogEntry(e));
Matt Hamilton
Thank you all, I resolved it by passing by ref a data structure that has a field that then I populate with the returned value from the database insert (record unique id).I appreciate the answers. El Matador.
ElMatador
+1  A: 

Commands are meant to be actions - not functions. As such, they shouldn't return any values.

A command is meant to be an action that fires in response to some input. The logic should, technically, be self-contained.

That being said, if you need to just call this method and ignore the results, you can wrap it in an Action<ConlogEntryData> and build your delegate command with that:

 Action<ConlogEntryData> action = c => this.InsertConlogEntry(c);
 DelegateCommand<ConlogEntryData> AddEntryCmd = new DelegateCommand<ConlogEntryData>(
         "Add New Conlog Entry","AddConLogEntry", action); 
Reed Copsey
Thank you all, I resolved it by passing by ref a data structure that has a field that then I populate with the returned value from the database insert (record unique id). I appreciate the answers.
ElMatador