private TCommandResult InternalExecute <TCommand, TCommandResult>(TCommand command) where TCommand : ICommand <TCommandResult> where TCommandResult : CommandResult, new() { var result = CreateDefaultCommandResult <TCommand, TCommandResult>(command); var handler = _commandHandlerProvider.GetCommandHandler <TCommand, TCommandResult>(); if (handler != null) { var hasTransactionAttribute = handler.HasTransactionAttribute(); if (hasTransactionAttribute) { _dbSessionManager.OpenTransaction(); } try { var checkResult = _prerequisitesChecker.Check(command); if (!checkResult.ContainsError) { result = handler.Handle(command); } else { result.Message = checkResult.Message; } if (hasTransactionAttribute) { _dbSessionManager.CommitTransaction(); } } catch (Exception) { if (hasTransactionAttribute) { _dbSessionManager.RollbackTransaction(); } throw; } } return(result); }
public TViewModel GetViewModel() { var args = _argumentsProvider.GetArguments<TArg>(); var checkResult = _prerequisitesChecker.Check( args ); if ( checkResult.ContainsError ) throw new ArgumentException( checkResult.Message ); return _viewModelProvider.GetViewModel( args ); }
public CommandResult Execute <TCommand>(TCommand command) { var result = new CommandResult { ContainsError = true, Message = String.Format("Handler not found for command {0}", command.GetType().Name) }; var handler = _commandHandlerProvider.GetCommandHandler <TCommand>(); if (handler != null) { var hasTransactionAttribute = handler.HasTransactionAttribute(); if (hasTransactionAttribute) { _dbSessionManager.OpenTransaction(); } try { var checkResult = _prerequisitesChecker.Check(command); if (!checkResult.ContainsError) { result = handler.Handle(command); } else { result.Message = checkResult.Message; } if (hasTransactionAttribute) { _dbSessionManager.CommitTransaction(); } } catch (Exception) { if (hasTransactionAttribute) { _dbSessionManager.RollbackTransaction(); } throw; } } return(result); }