public async Task <IActionResult> Delete(string id, string returnUrl) { if (User.IsInRole("Administrator")) { var userToDelete = await userManager.FindByIdAsync(id); var avatarPath = userToDelete.AvatarPath; if (avatarPath != null && avatarPath != defaultAvatarPath) { try { googleDriveRepository.DeleteFile(userToDelete.AvatarPath); } catch (Google.GoogleApiException) { }; } var result = await userManager.DeleteAsync(userToDelete); if (result.Succeeded) { return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } return(RedirectToAction("index", "home")); }
public IActionResult Delete(int id) { var campaign = _campaignRepository.Campaigns.First(campaign => campaign.Id == id); if (userManager.GetUserId(User) != campaign.Creator.Id) { return(RedirectToAction("index", "home")); } var imagePath = campaign.ImageGalleryUrl; if (imagePath != null && imagePath != defaultImagePath) { try { googleDriveRepository.DeleteFile(campaign.ImageGalleryUrl); } catch (Google.GoogleApiException) { }; } _campaignRepository.Delete(id); return(RedirectToAction("List", "Campaigns")); }