public ProjectViewModel(string name, string path, [NotNull] ICommandDispatcher commandDispatcher) { Guard.NotNull(commandDispatcher, nameof(commandDispatcher)); Guard.NotNullOrWhiteSpace(name, nameof(name)); Guard.NotNullOrWhiteSpace(path, nameof(path)); Name = name; Path = path; Progress = new ProgressViewModel(); FixCsProjectFiles = new CapturingExceptionAsyncCommand( async _ => await commandDispatcher.ExecuteAsync( new UpdateProjectFilesCommand(Path), new Progress <ProgressData>(data => (Progress as ProgressViewModel)?.Update(data))), _ => TaskRunning == false); RemoveNewAppConfig = new CapturingExceptionAsyncCommand( async _ => await commandDispatcher.ExecuteAsync( new CleanAppConfigCommand(Path), new Progress <ProgressData>(data => (Progress as ProgressViewModel)?.Update(data))), _ => TaskRunning == false); commandWatch = new ExecutingAsyncCommandsComposition(); commandWatch.WatchCommand(FixCsProjectFiles); commandWatch.WatchCommand(RemoveNewAppConfig); commandWatch.RegisterAction(value => TaskRunning = value); }
public async Task <IActionResult> Create([FromBody] SurveyCreateViewModel model) { var user = User.Identity.Name; string userIdStr = User.FindFirstValue(CustomClaimType.UserId); int userId; if (String.IsNullOrEmpty(userIdStr) || !int.TryParse(userIdStr, out userId)) { return(Ok(new ErrorServiceRespose("User id in token is invalid"))); } var createSurveyCommand = new CreateSurveyCommand { Title = model.Title, Description = model.Description, UserEmail = user }; var result = await _commandDispatcher.ExecuteAsync(createSurveyCommand); if (result.IsSuccess) { return(Ok(new OkServiceResponse <string>(""))); } return(Ok(new ErrorServiceRespose(result.Error))); }
public async Task <ActionResult> GetProductsAsync() { var command = new GetProductsCommand(); CommandResult <List <Models.Product> > result = await _commandDispatcher.ExecuteAsync(command); return(Ok(result)); }
public async Task <ActionResult <IdField> > Update(string id, [FromBody] OrderInputModel data) { var command = _commandBuilder.BuildUpdateOrderCommand(id, data); var orderId = await _commandDispatcher.ExecuteAsync(command).ConfigureAwait(false); return(new IdField { Id = orderId }); }
public async Task <ActionResult> Post([FromBody] UserLocationRequestModel userLocation) { var command = new AddUserLocation(userLocation.UserId, userLocation.Latitude, userLocation.Longitude, userLocation.Height); await commandDispatcher.ExecuteAsync(command); return(new OkResult()); }
public async Task <IActionResult> CreateTransaction( [FromRoute] Guid accountId, [FromBody] TransactionDto transactionDto) { if (!ModelState.IsValid) { return(BadRequest()); } var resultado = await _commandDispatcher.ExecuteAsync(new CreateTransaction(accountId, Guid.Parse(transactionDto.CategoryId), transactionDto.Amount, transactionDto.Type)); if (resultado.Failure && resultado.ReturnDto == null) { return(NotFound($"Account not found.")); } return(Ok()); }
public async Task <object> DispatchAsync(string commandText) { var args = commandText.ParseCommandText(); if (args.Any(a => a == "--help")) { return(_helpInfoFactory.Create(args)); } var executable = _executableFactory.Create( _executableInfoFactory.Create(args)); var result = executable is ICommand ? await _commandDispatcher.ExecuteAsync((ICommand)executable) : await _queryDispatcher.ExecuteAsync((IQuery)executable); return(result); }
public async Task <IActionResult> Authenticate([FromBody] LoginDto loginDto) { if (!ModelState.IsValid) { return(BadRequest()); } var resultado = await _commandDispatcher.ExecuteAsync(new AuthenticateCommand( loginDto.Username, loginDto.Password)); if (resultado.Failure) { return(NotFound(resultado.ErrorMessage)); } _logger.LogInformation("Response: {@response}", resultado); return(Ok(resultado.ReturnDto)); }
public async Task <IActionResult> Create([FromBody] UserDto userDto) { if (!ModelState.IsValid) { return(BadRequest()); } var result = await _commandDispatcher.ExecuteAsync( new RegisterUser( userDto.FirstName, userDto.LastName, userDto.CPF, userDto.Username, userDto.Password)); if (result.Failure) { return(BadRequest(result.ErrorMessage)); } userDto.Password = null; return(Created($"account/{0}", userDto)); }
public async Task <object> DispatchCommandAsync(ICommand command, ClaimsPrincipal user = null) { return(await _commandDispatcher.ExecuteAsync(command, user)); }
public static async Task SendNotification(this ICommandDispatcher dispatcher, NotificationInfo notification) { await dispatcher.ExecuteAsync(new SendNotification { Notification = notification }); }
public static async Task MarkNotificationAsRead(this ICommandDispatcher dispatcher, NotificationInfo notification) { await dispatcher.ExecuteAsync(new MarkAsRead { Notification = notification }); }