public ActionResult AddAccessCode(AccountAccessCodesViewModel viewModel)
        {
            // Convert the currently logged-in account id to an integer.
            int accountId = Conversion.StringToInt32(User.Identity.Name);

            if (ModelState.IsValid)
            {
                // Ensure that the description input is safe before being passed to the service layer.
                string description = Conversion.StringToSafeString(Server.HtmlEncode(viewModel.Description));

                // Generate a new access code.
                string newKey = this.doctrineShipsServices.AddAccessCode(accountId, description, (Role)viewModel.SelectedRole);

                // If the new key string is empty, something did not validate in the service layer.
                if (newKey != string.Empty)
                {
                    // Assign the new key to TempData to be passed to the AccessCodes view.
                    string authUrl = this.websiteDomain + "/Auth/" + accountId + "/" + newKey;
                    TempData["Status"] = "Success, the auth url is: <a href=\"" + authUrl + "\">" + authUrl + "</a>";
                }
                else
                {
                    TempData["Status"] = "Error: The access code was not added, a validation error occured.";
                }

                return RedirectToAction("AccessCodes");
            }
            else
            {
                // Re-populate the view model and return with any validation errors.
                viewModel.AccessCodes = this.doctrineShipsServices.GetAccessCodes(accountId);
                return View("~/Views/Account/AccessCodes.cshtml", viewModel);
            }
        }
        public ActionResult AccessCodes()
        {
            AccountAccessCodesViewModel viewModel = new AccountAccessCodesViewModel();

            // Convert the currently logged-in account id to an integer.
            int accountId = Conversion.StringToInt32(User.Identity.Name);

            // Set the ViewBag to the TempData status value passed from the Add & Delete methods.
            ViewBag.Status = TempData["Status"];

            // Retrieve a current list of access codes for the current account.
            viewModel.AccessCodes = this.doctrineShipsServices.GetAccessCodes(accountId);

            return View(viewModel);
        }
        public ActionResult DeleteAccessCode(AccountAccessCodesViewModel viewModel)
        {
            if (viewModel.RemoveList != null)
            {
                // Convert the currently logged-in account id to an integer.
                int accountId = Conversion.StringToInt32(User.Identity.Name);

                // Create a collection for the results of the delete operations.
                ICollection<bool> resultList = new List<bool>();

                foreach (var accessCodeId in viewModel.RemoveList)
                {
                    resultList.Add(this.doctrineShipsServices.DeleteAccessCode(accountId, accessCodeId));
                }

                // If any of the deletions failed, output an error message.
                if (resultList.Contains(false))
                {
                    TempData["Status"] = "Error: One or more access codes were not removed.";
                }
                else
                {
                    TempData["Status"] = "All selected access codes were successfully removed.";
                }
            }

            return RedirectToAction("AccessCodes");
        }