New to CSLA, need some examples of usage CommandBase<T> with Create and CreateAsync with Execute #2073
-
Hi, I am new to CSLA, I am creating a example scenario for the Commanbase CSLA. can someone help me to get the CSLA example for the CommandBase with criteria base examples |
Beta Was this translation helpful? Give feedback.
Answered by
rockfordlhotka
Jan 28, 2021
Replies: 1 comment 1 reply
-
The public class Example
{
public async Task<string> RunMyCommand()
{
var cmd = await DataPortal.CreateAsync<MyCommand>(42, "12345");
cmd = await DataPortal.ExecuteAsync(cmd);
return cmd.Result;
}
}
[Serializable]
public class MyCommand : CommandBase<MyCommand>
{
public static readonly PropertyInfo<int> IdProperty = RegisterProperty<int>(nameof(Id));
public int Id
{
get => ReadProperty(IdProperty);
private set => LoadProperty(IdProperty, value);
}
public static readonly PropertyInfo<string> PostalCodeProperty = RegisterProperty<string>(nameof(PostalCode));
public string PostalCode
{
get => ReadProperty(PostalCodeProperty);
private set => LoadProperty(PostalCodeProperty, value);
}
public static readonly PropertyInfo<string> ResultProperty = RegisterProperty<string>(nameof(Result));
public string Result
{
get => ReadProperty(ResultProperty);
private set => LoadProperty(ResultProperty, value);
}
[Create]
[RunLocal]
private void Create(int id, string postalCode)
{
Id = id;
PostalCode = postalCode;
}
[Execute]
private void Execute()
{
// execute the command here
Result = "command complete";
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
rockfordlhotka
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
CriteriaBase
type is deprecated and should no longer be necessary now that the data portal accepts multiple parameters. So you would normally have something like this: