/// <summary> /// DELETE whole album /// </summary> /// <param name="albumid"></param> /// <param name="pagename"></param> /// <returns>My Album view</returns> public IActionResult DeleteAlbum(string albumid, string pagename) { Album album = new Album(); int AlbumId = 0; if (!String.IsNullOrEmpty(albumid)) { AlbumId = Convert.ToInt32(Protector.Unprotect(albumid)); album = albumRepository.GetById(AlbumId); } albumRepository.Delete(AlbumId); foreach (var item in album.PhotoList) { LMCommon.DeletePhoto(item.PhotoPath, hostingEnvironment.WebRootPath, configuration["PhotoPath"]); } toastNotification.AddSuccessToastMessage("Album Delete Successfully."); string page = pagename.ToLower(); if (page == "allalbums") { return(RedirectToAction("AllAlbums", "User")); } else if (page == "newalbums") { return(RedirectToAction("NewAlbum", "User")); } return(RedirectToAction("MyAlbums", "User")); // return RedirectToAction("AlbumDetail", new RouteValueDictionary( //new { controller = "User", action = "AlbumDetail", albumId = model.ProtectorId })); }
/// <summary> /// DELETE current user /// </summary> /// <param name="UserId"></param> /// <returns>all users view</returns> public async Task <IActionResult> DeleteUser(string UserId) { AccountUser user = await userManager.Users.Include(i => i.AlbumList).ThenInclude(r => r.PhotoList).Where(user => user.Id == UserId).FirstOrDefaultAsync(); //user.AlbumList = user.AlbumList.ToList(); // List<Album> albums= albumRepository.GetUserAlbums(user.Id); if (user != null && user.AlbumList.Count > 0) { foreach (var item in user.AlbumList.ToList()) { foreach (var item2 in item.PhotoList.ToList()) { LMCommon.DeletePhoto(item2.PhotoPath, hostingEnvironment.WebRootPath, configuration["PhotoPath"]); photoRepository.DeletePhoto(item2.Id); } albumRepository.Delete(item.Id); } } await userManager.DeleteAsync(user); return(RedirectToAction("AllUsers")); }