public override void Execute()
        {
            if (AppSettings.Instance.UseRemoteSearchDatabase)
            {
                return;
            }

            try {
                var migrationsExists = _mediator.Query(new ObjectExistsQuery {
                    Type = ObjectType.Table,
                    Name = Common.DatabaseSchema.Migrations.TableName
                });

                if (!migrationsExists)
                {
                    _mediator.Command(new CreateMigrationTableSchemaCommand());
                }

                var migrations = _mediator.Query(new ListPossibleMigrationsQuery());
                foreach (var migration in migrations)
                {
                    _mediator.Command(new ApplyMigrationCommand {
                        Version = migration
                    });
                }
            } catch (Exception ex) { Logger.Error("ERROR ON UPDATE DATABASE: {0}", ex.Message); throw; }
        }
        public IActionResult Add(AddCourseCommand command)
        {
            var result = _mediator.Command(command);

            if (result.IsFailure)
            {
                ModelState.PopulateValidation(result.Errors);
                return(View(command));
            }

            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public async Task <IActionResult> Register([FromBody] UserRegisterRequest req)
        {
            // Yuck
            UserLogin?login = null;

            bus.Listen <UserRegisterEvent>(e => login = ((UserRegisterEvent)e).Login);

            var result = await mediator.Command(new RegisterUserCommand()
            {
                Registration = new UserRegistration(req.Username, req.Password, req.Email)
            });


            result.Match <IActionResult>(
                result => login != null ? Ok(new { Id = result.InsertId, AuthToken = tokenHandler.IssueToken(login) }) : BadRequest() as IActionResult,
                error => BadRequest(error.Message)
                );

            if (login != null)
            {
                return(Ok(login));
            }
            else
            {
                return(BadRequest(result.Right().Message));
            }
        }
Beispiel #4
0
        public async Task <IActionResult> CreateIngredient([FromBody] CreateIngredientCommand command)
        {
            var validationResult = _validators.ValidateCreate(command);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult));
            }

            var result = await _mediator.Command(command);

            if (result.IsSuccess)
            {
                return(Created($"api/ingredient{command.Id.ToString()}", result));
            }

            return(BadRequest(result));
        }
Beispiel #5
0
        /// <summary>
        /// 发送命令指令
        /// </summary>
        /// <param name="command">发送的命令</param>
        public void SendCommand(ICommand command)
        {
            if (IsDead)
            {
                return;
            }

            BattleController.Command(command);
        }
Beispiel #6
0
        private void RunCommand <T>(T command) where T : ICommand
        {
            ActionDataProvider.ProvideValue(command);
            var result = _mediator.Command(command);

            if (result.IsFailure)
            {
                throw new Exception(result.ErrorMessage);
            }
        }
        public IActionResult Add(Guid courseId, RegisterTrainingCommand command)
        {
            var result = _mediator.Command(command);

            if (result.IsFailure)
            {
                return(View(command));
            }

            return(RedirectToAction("Index", new { id = courseId }));
        }
        public async Task <ActionResult <GetOrderQueryResponse> > CreateOrder(CreateOrderCommand command, CancellationToken token)
        {
            await mediator.Command(command, token);

            var response = await mediator.Query <GetOrderQuery, GetOrderQueryResponse>(
                new GetOrderQuery
            {
                OrderId = command.Id
            },
                token);

            return(response);
        }
        public IActionResult Index(Guid courseId, Guid trainingId, BuyBookingViewModel model)
        {
            var command = new BuyBookingCommand(new Id <Course>(courseId), model.TrainingDate, model.Email, model.Quantity);
            var result  = _mediator.Command(command);

            if (result.IsFailure)
            {
                ModelState.PopulateValidation(result.Errors);
                return(View(model));
            }

            return(RedirectToAction("Index", "Course"));
        }
        private void ChangePosition_Click(object sender, EventArgs e)
        {
            if (documentDirectoryDataGridView.SelectedRows.Count == 0)
            {
                MessageBox.Show("Selecione um diretório de documentos para mudar sua posição."
                                , "Selecionar"
                                , MessageBoxButtons.OK
                                , MessageBoxIcon.Information);
                return;
            }

            var button = sender as Button;

            if (button != null)
            {
                var documentDirectory = documentDirectoryDataGridView.SelectedRows[0].DataBoundItem as Entities.DocumentDirectory;
                switch (button.Tag.ToString().ToUpperInvariant())
                {
                case CHANGE_POSITION_TOP_TAG:
                    documentDirectory.Position = DocumentDirectoryForm.MIN_POSITION;
                    break;

                case CHANGE_POSITION_UP_TAG:
                    documentDirectory.Position = documentDirectory.Position <= DocumentDirectoryForm.MIN_POSITION
                            ? DocumentDirectoryForm.MIN_POSITION
                            : documentDirectory.Position - 1;
                    break;

                case CHANGE_POSITION_DOWN_TAG:
                    documentDirectory.Position = documentDirectory.Position >= DocumentDirectoryForm.MAX_POSITION
                            ? DocumentDirectoryForm.MAX_POSITION
                            : documentDirectory.Position + 1;
                    break;

                case CHANGE_POSITION_BOTTOM_TAG:
                    documentDirectory.Position = DocumentDirectoryForm.MAX_POSITION;
                    break;
                }

                _mediator.Command(new SaveDocumentDirectoryCommand {
                    Code = documentDirectory.Code,
                    DocumentDirectoryID = documentDirectory.DocumentDirectoryID,
                    Label    = documentDirectory.Label,
                    Path     = documentDirectory.Path,
                    Position = documentDirectory.Position
                });

                FillDocumentDirectoryDataGridView();
            }
        }
Beispiel #11
0
        public async Task <IActionResult> CreateRecipe([FromForm] IFormFile File, [FromBody] CreateRecipeCommand command)
        {
            command.Image = File;
            var validationResult = _validators.ValidateCreate(command);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult));
            }

            var result = await _mediator.Command(command);

            if (result.IsSuccess)
            {
                return(Created($"api/recipe{command.Id.ToString()}", result));
            }

            if (result.ResultCode.Equals(ResultCode.NotFound))
            {
                return(NotFound(result));
            }

            return(BadRequest(result));
        }
 public IActionResult Post([FromBody] InsertMatchResultCommand command)
 {
     try
     {
         mediator.Command(command);
         return(Accepted());
     }
     catch (NullReferenceException ex)
     {
         return(NotFound(ex.Message));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex));
     }
 }
        public async Task <IActionResult> Login([FromBody] SessionLoginRequest loginRequest)
        {
            UserLogin?login = null;

            bus.Listen <UserLoginEvent>((IDomainEvent e) => {
                UserLoginEvent loginEvent = (UserLoginEvent)e;
                login = loginEvent.Login;
            });

            var result = await mediator.Command(new LoginUserCommand()
            {
                Credentials = new UserCredentials(loginRequest.Username, loginRequest.Password)
            });

            return(login != null?Ok(login) : Unauthorized("Invalid username and/or password.") as IActionResult);
        }
Beispiel #14
0
        public void Configure(IApplicationBuilder app,
                              IWebHostEnvironment env,
                              IMediator mediator)
        {
            app.UseHttpsRedirection();
            app.UseRouting();
            app.UseCors(DefaultCorsPolicy);
            app.UseAuthorization();
            app.UseEndpoints(x => x.MapControllerRoute(
                                 "Api_Default",
                                 "api/{controller=Recipe}/{action=GetBasicInfos}/{id?}"));

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseHangfireDashboard();
            BackgroundJob.Enqueue(() => mediator.Command(new BuildAllRecipesDetailsCommand()));
        }
Beispiel #15
0
 public void CleanUpDatabase()
 {
     _mediator.Command(new DatabaseCleanUpCommand());
 }