public async Task <IActionResult> DeleteNode([FromBody] DeleteNodeDTO nodeDTO) { try { await _treeViewService.DeleteNode(nodeDTO); return(NoContent()); } catch (NotFoundException) { return(NotFound()); } catch (System.Exception ex) { return(BadRequest(ErrorDTO.Create(ex.Message))); } }
public async Task DeleteNode(DeleteNodeDTO deleteNode) { Category category = _dbContext.Categories.Include(c => c.ParentCategory).FirstOrDefault(c => c.Id == deleteNode.Id); Page page = _dbContext.Pages.Include(p => p.Category).FirstOrDefault(p => p.Id == deleteNode.Id); if (category != null) { _dbContext.Categories.Remove(deleteNode.ToCategory(category)); } else if (page != null) { _dbContext.Pages.Remove(deleteNode.ToPage(page)); } else { throw new NotFoundException(); } await _dbContext.SaveChangesAsync(); }