Ejemplo n.º 1
0
        public async Task <IActionResult> DeleteWorkspace(int id)
        {
            if (User.FindFirst(Constants.SuperAdminClaim) is not null)
            {
                var workspace = await _workspaceRepository.GetByIdAsync(id);

                var sectionsToDelete = await _dbContext.Sections.Where(x => x.Workspace.Id == id).ToListAsync();

                var updatesToDelete = await _dbContext.Updates.Where(x => x.Workspace.Id == id).ToListAsync();

                var userClaimsToDelete = await _dbContext.UserClaims.Where(x => x.ClaimValue == workspace.Guid.ToString()).ToListAsync();

                _dbContext.Sections.RemoveRange(sectionsToDelete);
                _dbContext.Updates.RemoveRange(updatesToDelete);
                _dbContext.UserClaims.RemoveRange(userClaimsToDelete);
                await _dbContext.SaveChangesAsync();

                await _workspaceRepository.DeleteAsync(workspace);

                return(RedirectToAction("Index"));
            }
            return(Unauthorized());
        }