示例#1
0
        public async Task <IActionResult> CancelProfile()
        {
            var currentUserId = _userManager.GetUserId(User);
            var user          = await _userManager.FindByIdAsync(currentUserId);

            if (user == null)
            {
                // Would be funny if this happens. Someone is hacking us I guess.
                return(View("Error"));
            }
            var model = new RemoveProfileViewModel();

            model.UserName    = user.UserName;
            model.DisplayName = user.DisplayName;

            return(View(model));
        }
示例#2
0
        public async Task <IActionResult> CancelProfile(RemoveProfileViewModel model)
        {
            // Check the model first
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            // Find id
            var currentUserId = _userManager.GetUserId(User);
            // Find user
            var user = await _userManager.FindByIdAsync(currentUserId);

            if (user == null)
            {
                // Would be funny if this happens. Someone is hacking us I guess.
                return(View("Error"));
            }

            user.IsCancelled        = true;
            user.DateUpdated        = DateTime.Now;
            user.DateCancelled      = DateTime.Now;
            user.CancellationReason = model.Reason;

            var updateResult = await _userManager.UpdateAsync(user);

            // Log out.
            await _signInManager.SignOutAsync();

            // If all good we redirect to home.
            if (updateResult.Succeeded)
            {
                // Read the reason
                var reason = _resourcesService.GetString(this.Culture, Lines.YOUR_PROFILE_WAS_REMOVED);
                return(RedirectToAction("Index", "Home", new { reason = reason }));
            }

            AddErrors(updateResult);

            return(View(model));
        }