public IActionResult Delete(string id) { var user = _context.Users.FirstOrDefault(x => x.Id == id); _context.Remove(user); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); }
public async Task DeleteSurveyAsync(int surveyId) { var surveyModel = await _context.Surveys .Include("Reports") .Include("Reports.Responses") .FirstOrDefaultAsync(r => r.Id == surveyId); if (surveyModel != null) { var responses = surveyModel.Reports.SelectMany(x => x.Responses); if (responses != null) { _context.Responses.RemoveRange(responses); } _context.Remove(surveyModel); await _context.SaveChangesAsync(); } }
public void Delete(T entity) { _context.Remove(entity); Save(); }