// Example URI for DELETE: todos/1 public async Task <IActionResult> Index(int pId) { var lIndexCardBox = _context.IndexCardBoxes.Single(x => x.Id == pId); if (lIndexCardBox == null) { return(NotFound()); // returns an 404 page not found } IUser lUser = base.GetCurrentUser(_context); // check if box belongs to authenticated user if (IndexCardBox.UserIsOwnerOfIndexCardBox(pId, lUser, _context) == false) { return(Forbid()); } // delete all index cards and uploads // loop all indexcards var lIndexCards = _context.IndexCards.Select(x => x).Where(x => x.IndexCardBoxId == pId); var lIndexCardsAsList = lIndexCards.ToList <IIndexCard>(); foreach (IIndexCard lIndexCard in lIndexCardsAsList) { // removed dependen uploaded files IndexCard.RemoveAllUploadedFiles(lIndexCard, _env.WebRootPath); } // remove all indexcards _context.IndexCards.RemoveRange(lIndexCards); _context.SaveChanges(); // remove box _context.IndexCardBoxes.Remove(lIndexCardBox); _context.SaveChanges(); return(Json(lIndexCardBox)); }
// Example URI for DELETE: todos/1 public IActionResult Index(int pId) { var lIndexCard = _context.IndexCards.Single(x => x.Id == pId); if (lIndexCard == null) { return(NotFound()); // returns an 404 page not found } // checkk if index card belongs to user if (UserIsOwnerOfIndexCard(lIndexCard) == false) { return(Forbid()); } // remove uploaded files IndexCard.RemoveAllUploadedFiles(lIndexCard, _env.WebRootPath); _context.Remove(lIndexCard); _context.SaveChanges(); return(Json(lIndexCard)); }