public async Task <IActionResult> AdminDeleteProfile(int profileId, string name) { //don't allow a demo admin user to delete an account var demoAdminEmail = _configuration["Data:DemoAdminUser:Email"]; var user = await userManager.GetUserAsync(User); if (user.Email == demoAdminEmail) { ViewBag.Message = "Demo user not allowed to delete profile."; return(View("Error")); } //check that profile ID is valid, check username matches what is in user table var profileResult = _context.Profiles.Where(p => p.Id == profileId).FirstOrDefault(); if (profileResult == null) { return(NotFound()); } else { AdminDeleteProfileViewModel model = new AdminDeleteProfileViewModel { ProfileId = profileId, Name = name }; return(RedirectToAction("AdminDeleteProfileConfirm", model)); } }
public async Task <IActionResult> AdminDeleteProfileConfirm(AdminDeleteProfileViewModel model) { //don't allow a demo admin user to delete a profile var demoAdminEmail = _configuration["Data:DemoAdminUser:Email"]; var currentLoggedInUser = await userManager.GetUserAsync(User); if (currentLoggedInUser.Email == demoAdminEmail) { ViewBag.Message = "Demo user not allowed to delete profile."; return(View("Error")); } return(View(model)); }
public async Task <IActionResult> AdminDeleteProfileConfirmPost(AdminDeleteProfileViewModel model) { //don't allow a demo admin user to delete a profile var demoAdminEmail = _configuration["Data:DemoAdminUser:Email"]; var currentLoggedInUser = await userManager.GetUserAsync(User); if (currentLoggedInUser.Email == demoAdminEmail) { ViewBag.Message = "Demo user not allowed to delete profile."; return(View("Error")); } //delete the profile var profileToDelete = _context.Profiles.FirstOrDefault(p => p.Id == model.ProfileId); if (profileToDelete == null) { return(NotFound()); } _context.Profiles.Remove(profileToDelete); _context.SaveChanges(); return(RedirectToAction("Index")); }