示例#1
0
        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);
        }
示例#2
0
        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)));
        }
示例#3
0
        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
            });
        }
示例#5
0
        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());
        }
示例#6
0
        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());
        }
示例#7
0
        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);
        }
示例#8
0
        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));
        }
示例#9
0
        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));
        }
示例#10
0
 public async Task <object> DispatchCommandAsync(ICommand command, ClaimsPrincipal user = null)
 {
     return(await _commandDispatcher.ExecuteAsync(command, user));
 }
示例#11
0
 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 });
 }