public async Task <IActionResult> EditRegistration(int id, EditTeamContestRegistrationViewModel viewModel)
        {
            try
            {
                EditTeamContestRegistrationCommand command;
                if (User.IsInRole(Roles.Admin))
                {
                    command = new EditAdminTeamContestRegistrationCommand();
                }
                else
                {
                    command = new EditUserTeamContestRegistrationCommand();
                }
                command.RegistrationId = id;
                command.ViewModel      = viewModel;
                await HandlerDispatcher.ExecuteCommandAsync(command);
            }
            catch (ValidationException e)
            {
                e.ValidationResult.ForEach(res => ModelState.AddModelError(res.Key, res.Value));

                await FillViewDataForContestRegistrationAsync(viewModel);

                return(View(viewModel));
            }

            return(RedirectToAction(nameof(Details), new { id = viewModel.ContestId }));
        }
        public async Task <IActionResult> MakeNotAdmin(string id)
        {
            await HandlerDispatcher.ExecuteCommandAsync(new UserRemoveRoleCommand
            {
                Id   = id,
                Role = Roles.Admin
            });

            return(RedirectToAction(nameof(Admins)));
        }
        public async Task <IActionResult> ChangePassword(string id, PasswordViewModel viewModel)
        {
            if (id == null)
            {
                throw new EntityNotFoundException();
            }

            await HandlerDispatcher.ExecuteCommandAsync(new UserChangePasswordCommand
            {
                Id       = id,
                Password = viewModel.Password
            });

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Register(int id, CreateTeamContestRegistrationViewModel viewModel)
        {
            try
            {
                ICommand command;
                if (User.IsInRole(Roles.Admin))
                {
                    command = new CreateAdminTeamContestRegistrationCommand {
                        ViewModel = viewModel
                    }
                }
                ;
                else
                {
                    command = new CreateUserTeamContestRegistrationCommand {
                        ViewModel = viewModel
                    }
                };
                await HandlerDispatcher.ExecuteCommandAsync(command);
            }
            catch (ValidationException e)
            {
                e.ValidationResult.ForEach(res => ModelState.AddModelError(res.Key, res.Value));

                await FillViewDataForContestRegistrationAsync(viewModel);

                return(View(viewModel));
            }

            if (viewModel.ShowRegistrationInfo)
            {
                //TODO стоит ли показывать эту страницу для тренера?
                return(RedirectToAction(nameof(Registration) /*, new { id = result.RegistrationId }*/));
            }

            return(RedirectToAction(nameof(Details), new { id = viewModel.ContestId }));
        }
        public async Task <IActionResult> ImportBaylorRegistration(int id, ImportParticipantsViewModel viewModel)
        {
            await HandlerDispatcher.ExecuteCommandAsync(new ImportBaylorRegistrationsCommand { ViewModel = viewModel });

            return(RedirectToAction(nameof(Details), new { id }));
        }