public virtual async Task <IActionResult> UserEdit(EditUserViewModel model)
        {
            var selectedSite = await SiteManager.GetSiteForDataOperations(model.SiteId);

            // only server admin site can edit other sites settings
            if (selectedSite.Id != SiteManager.CurrentSite.Id)
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, StringLocalizer["{0} - Manage User"], selectedSite.SiteName);
            }
            else
            {
                ViewData["Title"] = StringLocalizer["Manage User"];
            }



            bool isValid           = ModelState.IsValid && (model.UserId != Guid.Empty);
            bool userNameAvailable = await UserManager.LoginIsAvailable(model.UserId, model.Username);

            if (!userNameAvailable)
            {
                ModelState.AddModelError("usernameerror", StringLocalizer["Username is already in use"]);
                isValid = false;
            }

            bool customDataIsValid = await CustomUserInfo.HandleUserEditValidation(
                UserManager.Site,
                model,
                HttpContext,
                ViewData,
                ModelState);

            var viewName = await CustomUserInfo.GetUserEditViewName(UserManager.Site, HttpContext);

            var user = await UserManager.Fetch(selectedSite.Id, model.UserId);

            if (!isValid || !customDataIsValid)
            {
                model.AccountApproved = user.AccountApproved;
                model.UserClaims      = await UserManager.GetClaimsAsync((SiteUser)user);

                model.UserRoles = await UserManager.GetRolesAsync((SiteUser)user);

                return(View(viewName, model));
            }

            //editing an existing user

            if (user != null)
            {
                user.Email       = model.Email;
                user.FirstName   = model.FirstName;
                user.LastName    = model.LastName;
                user.UserName    = model.Username;
                user.DisplayName = model.DisplayName;
                //user.AccountApproved = model.AccountApproved;
                user.Comment        = model.Comment;
                user.EmailConfirmed = model.EmailConfirmed;

                if ((user.IsLockedOut) && (!model.IsLockedOut))
                {
                    // TODO: notify user
                    // think we need to change this so the admin controls whether
                    // email is sent when approving an account
                }
                user.IsLockedOut = model.IsLockedOut;

                user.TimeZoneId = model.TimeZoneId;

                if (model.DateOfBirth.HasValue)
                {
                    user.DateOfBirth = model.DateOfBirth.Value;
                }
                else
                {
                    user.DateOfBirth = null;
                }
                user.WebSiteUrl = model.WebSiteUrl;

                await CustomUserInfo.HandleUserEditPostSuccess(
                    UserManager.Site,
                    user,
                    model,
                    HttpContext
                    );

                await UserManager.UpdateAsync((SiteUser)user);



                this.AlertSuccess(string.Format(StringLocalizer["user account for {0} was successfully updated."],
                                                user.DisplayName), true);
            }
            else
            {
                //to do log it?
            }


            return(RedirectToAction("UserEdit", "UserAdmin", new { siteId = selectedSite.Id, userId = user.Id }));
        }
        public virtual async Task <ActionResult> UserEdit(
            Guid userId,
            Guid?siteId
            )
        {
            if (userId == Guid.Empty)
            {
                return(RedirectToAction("Index"));
            }

            ViewData["ReturnUrl"] = Request.Path + Request.QueryString;
            var selectedSite = await SiteManager.GetSiteForDataOperations(siteId);

            // only server admin site can edit other sites settings
            if (selectedSite.Id != SiteManager.CurrentSite.Id)
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, StringLocalizer["{0} - Manage User"], selectedSite.SiteName);
            }
            else
            {
                ViewData["Title"] = StringLocalizer["Manage User"];
            }



            var model = new EditUserViewModel
            {
                SiteId = selectedSite.Id
            };

            var user = await UserManager.Fetch(selectedSite.Id, userId);

            if (user != null)
            {
                model.UserId          = user.Id;
                model.Email           = user.Email;
                model.FirstName       = user.FirstName;
                model.LastName        = user.LastName;
                model.Username        = user.UserName;
                model.DisplayName     = user.DisplayName;
                model.AccountApproved = user.AccountApproved;
                model.Comment         = user.Comment;
                model.EmailConfirmed  = user.EmailConfirmed;
                model.IsLockedOut     = user.IsLockedOut;
                model.LastLoginDate   = user.LastLoginUtc;
                model.TimeZoneId      = user.TimeZoneId;
                model.WebSiteUrl      = user.WebSiteUrl;
                model.AvatarUrl       = user.AvatarUrl;

                if (string.IsNullOrEmpty(model.TimeZoneId))
                {
                    model.TimeZoneId = await TimeZoneIdResolver.GetSiteTimeZoneId();
                }
                model.AllTimeZones = TimeZoneHelper.GetTimeZoneList().Select(x =>
                                                                             new SelectListItem
                {
                    Text     = x,
                    Value    = x,
                    Selected = model.TimeZoneId == x
                });

                if (user.DateOfBirth > DateTime.MinValue)
                {
                    model.DateOfBirth = user.DateOfBirth;
                }

                model.UserClaims = await UserManager.GetClaimsAsync((SiteUser)user);

                model.UserRoles = await UserManager.GetRolesAsync((SiteUser)user);


                var currentCrumbAdjuster = new NavigationNodeAdjuster(Request.HttpContext)
                {
                    KeyToAdjust    = "UserEdit",
                    AdjustedText   = user.DisplayName,
                    ViewFilterName = NamedNavigationFilters.Breadcrumbs // this is default but showing here for readers of code
                };
                currentCrumbAdjuster.AddToContext();
            }

            var viewName = await CustomUserInfo.GetUserEditViewName(UserManager.Site, HttpContext);

            await CustomUserInfo.HandleUserEditGet(
                UserManager.Site,
                model,
                HttpContext,
                ViewData);

            return(View(viewName, model));
        }