/// <summary>
        ///     Displays a view allowing the member to manage their account, including 
        ///     addresses, passwords and favorite tags and platforms
        /// </summary>
        /// <param name="message">
        ///     Enum value for a message to display with the page
        /// </param>
        /// <returns>
        ///     The view allowing the member to manage their account
        /// </returns>
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            switch (message)
            {
                case ManageMessageId.AddPhoneSuccess:
                    this.AddAlert(AlertType.Success, "Your phone number was added.");
                    break;
                case ManageMessageId.ChangePasswordSuccess:
                    this.AddAlert(AlertType.Success, "Your password has been changed.");
                    break;
                case ManageMessageId.SetTwoFactorSuccess:
                    this.AddAlert(
                        AlertType.Success, "Your two-factor authentication provider has been set.");
                    break;
                case ManageMessageId.SetPasswordSuccess:
                    this.AddAlert(AlertType.Success, "Your password has been set.");
                    break;
                case ManageMessageId.RemoveLoginSuccess:
                    this.AddAlert(AlertType.Success, "A login has been removed.");
                    break;
                case ManageMessageId.RemovePhoneSuccess:
                    this.AddAlert(AlertType.Success, "Your phone number was removed.");
                    break;
                case ManageMessageId.Error:
                    this.AddAlert(AlertType.Error, "An error has occurred.");
                    break;
            }

            var userId = GetUserId();
            var user = await userManager.FindByIdAsync(userId);

            if (user == null)
            {
                // If this happens, the user has been deleted in the database but still has a valid login cookie
                signInManager.AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                return RedirectToAction("Index", "Home");
            }

            if (user.Member == null)
            {
                this.AddAlert(AlertType.Error, "Employees do not have profiles to view.");
                return RedirectToAction("Index", "Home");
            }

            var model = new IndexViewModel
            {
                PhoneNumber = user.PhoneNumber,
                MemberFirstName = user.FirstName,
                MemberLastName = user.LastName,
                MemberEmail = user.Email,
                MemberVisibility = user.Member.WishListVisibility,
                ReceivePromotionalEmails = user.Member.ReceivePromotionalEmails,
                FavoritePlatformCount = user.Member.FavoritePlatforms.Count,
                FavoriteTagCount = user.Member.FavoriteTags.Count
            };

            return View(model);
        }
        public async Task<ActionResult> UpdateProfile(IndexViewModel viewModel)
        {
            Guid userId = GetUserId();
            var user = await userManager.FindByIdAsync(userId);
            bool isNewEmail = false;

            if (user == null)
            {
                // If this happens, the user has been deleted in the database but still has a valid login cookie
                signInManager.AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                return RedirectToAction("Index", "Home");
            }

            if (user.Member == null)
            {
                this.AddAlert(AlertType.Error, "Employees do not have public profiles.");
                return RedirectToAction("Index", "Home");
            }

            if (ModelState.IsValid)
            {
                user.FirstName = viewModel.MemberFirstName;
                user.LastName = viewModel.MemberLastName;
                user.PhoneNumber = viewModel.PhoneNumber;
                user.Member.ReceivePromotionalEmails = viewModel.ReceivePromotionalEmails;
                user.Member.WishListVisibility = viewModel.MemberVisibility;

                if (user.Email != viewModel.MemberEmail)
                {
                    // Runs if newEmail was not null or empty and and the new email property is 
                    // different than the one being set
                    if (!string.IsNullOrWhiteSpace(user.NewEmail) &&
                        user.NewEmail != viewModel.MemberEmail)
                    {
                        // Invalidates confirmation email stamp
                        await userManager.UpdateSecurityStampAsync(userId);
                    }
                    user.NewEmail = viewModel.MemberEmail;
                    isNewEmail = true;
                }

                try
                {
                    db.MarkAsModified(user);
                    await db.SaveChangesAsync();
                    if (isNewEmail)
                    {
                        await SendConfirmationEmail(user);
                        this.AddAlert(
                            AlertType.Info, "A confirmation email has been sent to " + user.NewEmail +
                                ". You must continue logging into your Veil account using " +
                                user.Email + " until you confirm the new email address");
                    }
                    this.AddAlert(AlertType.Success, "Your Profile has been updated");
                }
                catch (DataException)
                {
                    this.AddAlert(AlertType.Error, "An error occurred while trying to save your changes");
                }
            }
            else
            {
                this.AddAlert(AlertType.Error, "Some profile information was invalid");

                viewModel.FavoritePlatformCount = user.Member.FavoritePlatforms.Count;
                viewModel.FavoriteTagCount = user.Member.FavoriteTags.Count;

                return View(viewModel);
            }

            return RedirectToAction("Index");
        }