本文整理汇总了C#中IUserRepository.Submit方法的典型用法代码示例。如果您正苦于以下问题:C# IUserRepository.Submit方法的具体用法?C# IUserRepository.Submit怎么用?C# IUserRepository.Submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IUserRepository
的用法示例。
在下文中一共展示了IUserRepository.Submit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UserViewModel
public UserViewModel(IScreen screen, User user, IUserRepository userRepository)
{
_userRepository = userRepository;
HostScreen = screen;
// Commands
var canSubmit = this.WhenAny(e => e.Code, code => code.Value.IsValid());
Submit = ReactiveCommand.CreateAsyncTask(canSubmit, _ => userRepository.Submit(Model));
Submit.Subscribe(result => MessageBox.Show(result ? "Success" : "Failure"));
// Observe on UI thread
Submit.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler)
.Select(ex => new UserError("It will fail again, try anyway?", ex.Message))
.SelectMany(UserError.Throw)
.Subscribe(resolution =>
{
if (resolution == RecoveryOptionResult.RetryOperation)
Submit.Execute(null);
});
// Model subscription
this.WhenAnyValue(e => e.Model).Where(e => e != null).Subscribe(model =>
{
Code = model.Code;
Group = model.Group;
});
Model = user;
// Properties subscriptions
this.WhenAnyValue(e => e.Group).Subscribe(group => Model.Group = group);
this.WhenAnyValue(e => e.Code).Subscribe(code => Model.Code = code);
// Subscribe to error handle
UserError.RegisterHandler(async error =>
{
// This shouldn't be a messagebox because is blocking the application, you must provide context and offer a resolution to the user not just showing "error"
await Task.Delay(1);
var message = new StringBuilder();
bool hasRecoveryOptions = error.ErrorCauseOrResolution.IsValid();
if (hasRecoveryOptions)
message.AppendLine(error.ErrorCauseOrResolution);
message.AppendLine(error.ErrorMessage);
var result = MessageBox.Show(message.ToString(), "Alert!",
hasRecoveryOptions ? MessageBoxButton.YesNo : MessageBoxButton.OK);
return hasRecoveryOptions && result == MessageBoxResult.Yes ? RecoveryOptionResult.RetryOperation : RecoveryOptionResult.CancelOperation;
});
}