public ActionResult Edit(HeaderInfoController headerInfoController, SidebarController sidebarController, EditPuzzleViewModel viewModel, bool captchaValid)
        {
            if (_authenticationService.CurrentUser.Reputation < Settings.MinimumReputationToEditPuzzle)
                return View("NotPrivaledged");

            var themes = Theme.GetThemesFromString(viewModel.Themes);

            ValidatePuzzleEdit(viewModel, themes, captchaValid);

            if (!ModelState.IsValid)
                return View(viewModel);

            _puzzleService.AddThemesToPuzzle(viewModel.Id, _authenticationService.CurrentUserId, themes);

            return RedirectToAction("Display", new { id = viewModel.Id });
        }
        private void ValidatePuzzleEdit(EditPuzzleViewModel vm, IEnumerable<string> themes, bool captchaValid)
        {
            if (!captchaValid)
                ModelState.AddModelError("Captcha", "Captcha is invalid");

            if (themes.Count() == 0)
                ModelState.AddModelError("Themes", "At least 1 theme is required");

            if (themes.Count() > 5)
                ModelState.AddModelError("Themes", "Can only select up to 5 themes.");
        }
        public ActionResult Edit(HeaderInfoController headerInfoController, SidebarController sidebarController, int id)
        {
            //Only allow logged in users with high enough reputation to edit the puzzle
            if (!_authenticationService.IsAuthenticated)
                return View("Unauthorized");

            if (_authenticationService.CurrentUser.Reputation < Settings.MinimumReputationToEditPuzzle)
                return View("NotPrivaledged");

            var puzzle = _puzzleService.GetPuzzleById(id);

            if (puzzle == null)
                return View("NotFound");

            //Only show puzzles that have not been verified to the user who created them.
            if (!puzzle.IsVerified)
            {
                if (puzzle.User.Id != _authenticationService.CurrentUserId)
                    return View("NotFound");
            }

            var vm = new EditPuzzleViewModel(puzzle);
            return View(vm);
        }