public async Task <IActionResult> OnPostDeleteAsync(int id, string returnUrl) { var user = await _userManager.GetUserAsync(User); if (user == null) { return(RedirectToPage("/Account/Errors/AccessDenied", new { Area = "Identity" })); } var hasPassword = await _userManager.HasPasswordAsync(user); if (!hasPassword) { return(RedirectToPage("./SetPassword")); } var entity = await _companyService.GetByIdAsync(id); if (entity == null) { return(RedirectToPage("/Account/Errors/NoEntity", new { Area = "Identity" })); } if (user.Id != entity.PosterId && !user.Role.Equals(Roles.Admin) && !user.Role.Equals(Roles.Moderator)) { return(RedirectToPage("/Account/Errors/AccessDeniedContent", new { Area = "Identity" })); } if (!ModelState.IsValid) { return(Page()); } if (!await _userManager.CheckPasswordAsync(user, Input.Password)) { ModelState.AddModelError(string.Empty, "Грешна парола."); return(Page()); } var result = await _companyService.Delete(id); if (result.Success) { await _jobsService.DeleteAllBy(id, null); _baseService.ToastNotify(ToastMessageState.Warning, "Внимание", "Фирмата е премахната успешно.", 5000); if (!String.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } else { RedirectToPage("/Identity/Companies", new { Area = "Identity" }); } } return(Page()); }
public async Task <IActionResult> OnPostAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { return(RedirectToPage("/Account/Errors/AccessDenied", new { Area = "Identity" })); } if (!user.isExternal) { RequirePassword = await _userManager.HasPasswordAsync(user); if (!await _userManager.CheckPasswordAsync(user, Input.Password)) { ModelState.AddModelError(string.Empty, "Грешна парола."); return(Page()); } _baseService.Delete(user.PictureName); } await _jobsService.DeleteAllBy(0, user); await _companyService.DeleteAllBy(user); await _contestantService.DeleteAllBy(user); await _resumeService.DeleteAllBy(user); var result = await _userManager.DeleteAsync(user); if (!result.Succeeded) { _baseService.ToastNotifyLog(user, ToastMessageState.Error, "Грешка", "при изтриване на акаунта ви.", $"{user.UserName}, {user.Email} ,{user.Role}", 2000); } await _signInManager.SignOutAsync(); return(Redirect("~/")); }